mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-09-23 04:03:35 +08:00
directory structure change to work with glide
glide has its own requirements. My previous workaround caused me some code checkin errors. Need to fix this.
This commit is contained in:
36
weed/sequence/memory_sequencer.go
Normal file
36
weed/sequence/memory_sequencer.go
Normal file
@@ -0,0 +1,36 @@
|
||||
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 uint64) (uint64, uint64) {
|
||||
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
|
||||
}
|
7
weed/sequence/sequence.go
Normal file
7
weed/sequence/sequence.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package sequence
|
||||
|
||||
type Sequencer interface {
|
||||
NextFileId(count uint64) (uint64, uint64)
|
||||
SetMax(uint64)
|
||||
Peek() uint64
|
||||
}
|
Reference in New Issue
Block a user