milvus/internal/proxyservice/nodeid_allocator.go
dragondriver decc80a525 Add unittest to proxy service
Signed-off-by: dragondriver <jiquan.long@zilliz.com>
2021-04-06 14:12:57 +08:00

37 lines
686 B
Go

package proxyservice
import (
"sync"
"github.com/zilliztech/milvus-distributed/internal/allocator"
"github.com/zilliztech/milvus-distributed/internal/util/typeutil"
)
type UniqueID = typeutil.UniqueID
type Timestamp = typeutil.Timestamp
type nodeIDAllocator interface {
AllocOne() UniqueID
}
type naiveNodeIDAllocator struct {
allocator *allocator.IDAllocator
now UniqueID
mtx sync.Mutex
}
func (allocator *naiveNodeIDAllocator) AllocOne() UniqueID {
allocator.mtx.Lock()
defer func() {
// allocator.now++
allocator.mtx.Unlock()
}()
return allocator.now
}
func newNodeIDAllocator() *naiveNodeIDAllocator {
return &naiveNodeIDAllocator{
now: 1,
}
}