mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-04 04:49:08 +08:00
4acaa97039
Signed-off-by: XuanYang-cn <xuan.yang@zilliz.com>
38 lines
675 B
Go
38 lines
675 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 NaiveNodeIDAllocatorImpl struct {
|
|
impl *allocator.IDAllocator
|
|
now UniqueID
|
|
mtx sync.Mutex
|
|
}
|
|
|
|
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,
|
|
}
|
|
}
|