Skip to content

Commit b85ce2b

Browse files
letian0805Letian Yi
authored andcommitted
Fix sequence number bug when storage fails
1 parent 9d2a3c2 commit b85ce2b

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

filestore.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -278,34 +278,34 @@ func (store *fileStore) NextTargetMsgSeqNum() int {
278278

279279
// SetNextSenderMsgSeqNum sets the next MsgSeqNum that will be sent.
280280
func (store *fileStore) SetNextSenderMsgSeqNum(next int) error {
281-
if err := store.cache.SetNextSenderMsgSeqNum(next); err != nil {
282-
return errors.Wrap(err, "cache")
281+
if err := store.setSeqNum(store.senderSeqNumsFile, next); err != nil {
282+
return errors.Wrap(err, "file")
283283
}
284-
return store.setSeqNum(store.senderSeqNumsFile, next)
284+
return store.cache.SetNextSenderMsgSeqNum(next)
285285
}
286286

287287
// SetNextTargetMsgSeqNum sets the next MsgSeqNum that should be received.
288288
func (store *fileStore) SetNextTargetMsgSeqNum(next int) error {
289-
if err := store.cache.SetNextTargetMsgSeqNum(next); err != nil {
290-
return errors.Wrap(err, "cache")
289+
if err := store.setSeqNum(store.targetSeqNumsFile, next); err != nil {
290+
return errors.Wrap(err, "file")
291291
}
292-
return store.setSeqNum(store.targetSeqNumsFile, next)
292+
return store.cache.SetNextTargetMsgSeqNum(next)
293293
}
294294

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

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

311311
// CreationTime returns the creation time of the store.

mongostore.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,18 +254,18 @@ func (store *mongoStore) SetNextTargetMsgSeqNum(next int) error {
254254

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

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

271271
// CreationTime returns the creation time of the store.

sqlstore.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,18 +261,18 @@ func (store *sqlStore) SetNextTargetMsgSeqNum(next int) error {
261261

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

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

278278
// CreationTime returns the creation time of the store.

0 commit comments

Comments
 (0)