milvus/internal/proxyservice/nodeid_allocator.go
dragondriver c6a6b1436c Add soft time tick in proxy service
Signed-off-by: dragondriver <jiquan.long@zilliz.com>
2021-01-26 13:41:41 +08:00

35 lines
580 B
Go

package proxyservice
import (
"sync"
"github.com/zilliztech/milvus-distributed/internal/util/typeutil"
)
type UniqueID = typeutil.UniqueID
type Timestamp = typeutil.Timestamp
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,
}
}