Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sequence number bug when storage fails #432

Merged
merged 3 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions filestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,34 +280,34 @@ func (store *fileStore) NextTargetMsgSeqNum() int {

// SetNextSenderMsgSeqNum sets the next MsgSeqNum that will be sent.
func (store *fileStore) SetNextSenderMsgSeqNum(next int) error {
if err := store.cache.SetNextSenderMsgSeqNum(next); err != nil {
return errors.Wrap(err, "cache")
if err := store.setSeqNum(store.senderSeqNumsFile, next); err != nil {
return errors.Wrap(err, "file")
}
return store.setSeqNum(store.senderSeqNumsFile, next)
return store.cache.SetNextSenderMsgSeqNum(next)
}

// SetNextTargetMsgSeqNum sets the next MsgSeqNum that should be received.
func (store *fileStore) SetNextTargetMsgSeqNum(next int) error {
if err := store.cache.SetNextTargetMsgSeqNum(next); err != nil {
return errors.Wrap(err, "cache")
if err := store.setSeqNum(store.targetSeqNumsFile, next); err != nil {
return errors.Wrap(err, "file")
}
return store.setSeqNum(store.targetSeqNumsFile, next)
return store.cache.SetNextTargetMsgSeqNum(next)
}

// IncrNextSenderMsgSeqNum increments the next MsgSeqNum that will be sent.
func (store *fileStore) IncrNextSenderMsgSeqNum() error {
if err := store.cache.IncrNextSenderMsgSeqNum(); err != nil {
return errors.Wrap(err, "cache")
if err := store.SetNextSenderMsgSeqNum(store.cache.NextSenderMsgSeqNum() + 1); err != nil {
return errors.Wrap(err, "file")
}
return store.setSeqNum(store.senderSeqNumsFile, store.cache.NextSenderMsgSeqNum())
return nil
}

// IncrNextTargetMsgSeqNum increments the next MsgSeqNum that should be received.
func (store *fileStore) IncrNextTargetMsgSeqNum() error {
if err := store.cache.IncrNextTargetMsgSeqNum(); err != nil {
return errors.Wrap(err, "cache")
if err := store.SetNextTargetMsgSeqNum(store.cache.NextTargetMsgSeqNum() + 1); err != nil {
return errors.Wrap(err, "file")
}
return store.setSeqNum(store.targetSeqNumsFile, store.cache.NextTargetMsgSeqNum())
return nil
}

// CreationTime returns the creation time of the store.
Expand Down
12 changes: 6 additions & 6 deletions mongostore.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,18 +254,18 @@ func (store *mongoStore) SetNextTargetMsgSeqNum(next int) error {

// IncrNextSenderMsgSeqNum increments the next MsgSeqNum that will be sent.
func (store *mongoStore) IncrNextSenderMsgSeqNum() error {
if err := store.cache.IncrNextSenderMsgSeqNum(); err != nil {
return errors.Wrap(err, "cache incr")
if err := store.SetNextSenderMsgSeqNum(store.cache.NextSenderMsgSeqNum() + 1); err != nil {
return errors.Wrap(err, "save sequence number")
}
return store.SetNextSenderMsgSeqNum(store.cache.NextSenderMsgSeqNum())
return nil
}

// IncrNextTargetMsgSeqNum increments the next MsgSeqNum that should be received.
func (store *mongoStore) IncrNextTargetMsgSeqNum() error {
if err := store.cache.IncrNextTargetMsgSeqNum(); err != nil {
return errors.Wrap(err, "cache incr")
if err := store.SetNextTargetMsgSeqNum(store.cache.NextTargetMsgSeqNum() + 1); err != nil {
return errors.Wrap(err, "save sequence number")
}
return store.SetNextTargetMsgSeqNum(store.cache.NextTargetMsgSeqNum())
return nil
}

// CreationTime returns the creation time of the store.
Expand Down
12 changes: 6 additions & 6 deletions sqlstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,18 +261,18 @@ func (store *sqlStore) SetNextTargetMsgSeqNum(next int) error {

// IncrNextSenderMsgSeqNum increments the next MsgSeqNum that will be sent.
func (store *sqlStore) IncrNextSenderMsgSeqNum() error {
if err := store.cache.IncrNextSenderMsgSeqNum(); err != nil {
return errors.Wrap(err, "cache incr next")
if err := store.SetNextSenderMsgSeqNum(store.cache.NextSenderMsgSeqNum() + 1); err != nil {
return errors.Wrap(err, "store next")
}
return store.SetNextSenderMsgSeqNum(store.cache.NextSenderMsgSeqNum())
return nil
}

// IncrNextTargetMsgSeqNum increments the next MsgSeqNum that should be received.
func (store *sqlStore) IncrNextTargetMsgSeqNum() error {
if err := store.cache.IncrNextTargetMsgSeqNum(); err != nil {
return errors.Wrap(err, "cache incr next")
if err := store.SetNextTargetMsgSeqNum(store.cache.NextTargetMsgSeqNum() + 1); err != nil {
return errors.Wrap(err, "store next")
}
return store.SetNextTargetMsgSeqNum(store.cache.NextTargetMsgSeqNum())
return nil
}

// CreationTime returns the creation time of the store.
Expand Down
Loading