Releases any currently reserved, non-allocated sequences.
(ctx context.Context)
| 123 | |
| 124 | // Releases any currently reserved, non-allocated sequences. |
| 125 | func (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) |