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

Method releaseSequenceMonitor

db/sequence_allocator.go:102–122  ·  view source on GitHub ↗

Release sequence monitor runs in its own goroutine, and releases allocated sequences that aren't used within 'releaseSequenceTimeout'.

(ctx context.Context)

Source from the content-addressed store, hash-verified

100// Release sequence monitor runs in its own goroutine, and releases allocated sequences
101// that aren't used within 'releaseSequenceTimeout'.
102func (s *sequenceAllocator) releaseSequenceMonitor(ctx context.Context) {
103
104 // Terminator is only checked while in idle state - ensures sequence allocation drains and
105 // unused sequences are released before exiting.
106 timer := time.NewTimer(math.MaxInt64)
107 defer timer.Stop()
108
109 for {
110 select {
111 case <-s.reserveNotify:
112 // On reserve, start the timer to release unused sequences. A new reserve resets the timer.
113 // On timeout, release sequences and return to idle state
114 _ = timer.Reset(s.releaseSequenceWait)
115 case <-timer.C:
116 s.releaseUnusedSequences(ctx)
117 case <-s.terminator:
118 s.releaseUnusedSequences(ctx)
119 return
120 }
121 }
122}
123
124// Releases any currently reserved, non-allocated sequences.
125func (s *sequenceAllocator) releaseUnusedSequences(ctx context.Context) {

Callers 1

newSequenceAllocatorFunction · 0.95

Calls 3

StopMethod · 0.65
ResetMethod · 0.45

Tested by

no test coverage detected