Retrieves the last allocated sequence. If there hasn't been an allocation yet by this node, retrieves the value of the _sync:seq counter from the bucket by doing an incr(0)
(ctx context.Context)
| 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) |
| 155 | func (s *sequenceAllocator) lastSequence(ctx context.Context) (uint64, error) { |
| 156 | s.mutex.Lock() |
| 157 | lastSeq := s.last |
| 158 | s.mutex.Unlock() |
| 159 | |
| 160 | if lastSeq > 0 { |
| 161 | return lastSeq, nil |
| 162 | } |
| 163 | s.dbStats.SequenceGetCount.Add(1) |
| 164 | last, err := s.getSequence() |
| 165 | if err != nil { |
| 166 | return 0, fmt.Errorf("Couldn't get sequence from bucket: %w", err) |
| 167 | } |
| 168 | return last, err |
| 169 | } |
| 170 | |
| 171 | // Returns the next available sequence. |
| 172 | // If previously reserved sequences are available (s.last < s.max), returns one |