seaweedfs/go/sequence/memory_sequencer.go
Chris Lu 51939efeac 1. volume server now sends master server its max file key, so that
master server does not need to store the sequence on disk any more
2. fix raft server's failure to init cluster during bootstrapping
2014-04-16 23:43:27 -07:00

37 lines
649 B
Go

package sequence
import (
"sync"
)
// just for testing
type MemorySequencer struct {
counter uint64
sequenceLock sync.Mutex
}
func NewMemorySequencer() (m *MemorySequencer) {
m = &MemorySequencer{counter: 1}
return
}
func (m *MemorySequencer) NextFileId(count int) (uint64, int) {
m.sequenceLock.Lock()
defer m.sequenceLock.Unlock()
ret := m.counter
m.counter += uint64(count)
return ret, count
}
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
}