releaseSequenceRange writes a binary document with the key _sync:unusedSeqs:fromSeq:toSeq. fromSeq and toSeq are inclusive (i.e. both fromSeq and toSeq are unused). From and to seq are stored as the document contents to avoid null doc issues. Returns the number of sequences released.
(ctx context.Context, fromSequence, toSequence uint64)
| 417 | // From and to seq are stored as the document contents to avoid null doc issues. |
| 418 | // Returns the number of sequences released. |
| 419 | func (s *sequenceAllocator) releaseSequenceRange(ctx context.Context, fromSequence, toSequence uint64) (uint64, error) { |
| 420 | |
| 421 | // Exit if there's nothing to release |
| 422 | if toSequence == 0 || toSequence < fromSequence { |
| 423 | return 0, nil |
| 424 | } |
| 425 | key := s.metaKeys.UnusedSeqRangeKey(fromSequence, toSequence) |
| 426 | body := make([]byte, 16) |
| 427 | binary.LittleEndian.PutUint64(body[:8], fromSequence) |
| 428 | binary.LittleEndian.PutUint64(body[8:16], toSequence) |
| 429 | _, err := s.datastore.AddRaw(key, UnusedSequenceTTL, body) |
| 430 | if err != nil { |
| 431 | return 0, err |
| 432 | } |
| 433 | count := toSequence - fromSequence + 1 |
| 434 | s.dbStats.SequenceReleasedCount.Add(int64(count)) |
| 435 | base.DebugfCtx(ctx, base.KeyCRUD, "Released unused sequences #%d-#%d", fromSequence, toSequence) |
| 436 | return count, nil |
| 437 | } |
| 438 | |
| 439 | // waitForReleasedSequences blocks for 'releaseSequenceWait' past the provided startTime. |
| 440 | // Used to guarantee assignment of allocated sequences on other nodes. |
no test coverage detected