milvus/internal/proxyservice/nodeid_allocator.go
dragondriver cd52adc18b Add proxy service to ci workflow
Signed-off-by: dragondriver <jiquan.long@zilliz.com>
2021-01-22 12:57:23 +08:00

34 lines
544 B
Go

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