2013-11-10 09:31:50 +00:00
|
|
|
package sequence
|
|
|
|
|
2014-04-17 06:43:27 +00:00
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
)
|
2013-11-10 09:31:50 +00:00
|
|
|
|
|
|
|
// just for testing
|
|
|
|
type MemorySequencer struct {
|
2014-04-17 06:43:27 +00:00
|
|
|
counter uint64
|
|
|
|
sequenceLock sync.Mutex
|
2013-11-10 09:31:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewMemorySequencer() (m *MemorySequencer) {
|
|
|
|
m = &MemorySequencer{counter: 1}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-10-30 07:49:58 +00:00
|
|
|
func (m *MemorySequencer) NextFileId(count uint64) uint64 {
|
2014-04-17 06:43:27 +00:00
|
|
|
m.sequenceLock.Lock()
|
|
|
|
defer m.sequenceLock.Unlock()
|
2013-11-10 09:31:50 +00:00
|
|
|
ret := m.counter
|
2019-10-30 07:49:58 +00:00
|
|
|
m.counter += count
|
|
|
|
return ret
|
2013-11-10 09:31:50 +00:00
|
|
|
}
|
2014-04-17 06:43:27 +00:00
|
|
|
|
|
|
|
func (m *MemorySequencer) SetMax(seenValue uint64) {
|
|
|
|
m.sequenceLock.Lock()
|
|
|
|
defer m.sequenceLock.Unlock()
|
|
|
|
if m.counter <= seenValue {
|
|
|
|
m.counter = seenValue + 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MemorySequencer) Peek() uint64 {
|
|
|
|
return m.counter
|
|
|
|
}
|