MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / releaseUnusedSequences

Method releaseUnusedSequences

db/sequence_allocator.go:125–151  ·  view source on GitHub ↗

Releases any currently reserved, non-allocated sequences.

(ctx context.Context)

Source from the content-addressed store, hash-verified

123
124// Releases any currently reserved, non-allocated sequences.
125func (s *sequenceAllocator) releaseUnusedSequences(ctx context.Context) {
126 s.mutex.Lock()
127 if s.last == s.max {
128 s.mutex.Unlock()
129 return
130 }
131 if s.last < s.max {
132 _, err := s.releaseSequenceRange(ctx, s.last+1, s.max)
133 if err != nil {
134 base.WarnfCtx(ctx, "Error returned when releasing sequence range [%d-%d]. Falling back to skipped sequence handling. Error:%v", s.last+1, s.max, err)
135 }
136 }
137 // Reduce batch size for next incr by the unused amount
138 unusedAmount := s.max - s.last
139
140 // If no sequences from the last batch were used, assume system is idle
141 // and drop back to the idle batch size.
142 if unusedAmount >= s.sequenceBatchSize {
143 s.sequenceBatchSize = idleBatchSize
144 } else {
145 // Some sequences were used - reduce batch size by the unused amount.
146 s.sequenceBatchSize = s.sequenceBatchSize - unusedAmount
147 }
148
149 s.last = s.max
150 s.mutex.Unlock()
151}
152
153// Retrieves the last allocated sequence. If there hasn't been an allocation yet by this node,
154// retrieves the value of the _sync:seq counter from the bucket by doing an incr(0)

Callers 3

StopMethod · 0.95
TestSequenceAllocatorFunction · 0.95

Calls 4

releaseSequenceRangeMethod · 0.95
WarnfCtxFunction · 0.92
LockMethod · 0.45
UnlockMethod · 0.45

Tested by 1

TestSequenceAllocatorFunction · 0.76