2021-01-22 12:57:23 +08:00
|
|
|
package proxyservice
|
|
|
|
|
|
|
|
import (
|
2021-01-27 20:00:47 +08:00
|
|
|
"sync"
|
2021-01-26 14:55:57 +08:00
|
|
|
|
|
|
|
"github.com/zilliztech/milvus-distributed/internal/allocator"
|
2021-01-22 12:57:23 +08:00
|
|
|
|
|
|
|
"github.com/zilliztech/milvus-distributed/internal/util/typeutil"
|
|
|
|
)
|
|
|
|
|
|
|
|
type UniqueID = typeutil.UniqueID
|
2021-01-26 13:41:41 +08:00
|
|
|
type Timestamp = typeutil.Timestamp
|
2021-01-22 12:57:23 +08:00
|
|
|
|
|
|
|
type NodeIDAllocator interface {
|
|
|
|
AllocOne() UniqueID
|
|
|
|
}
|
|
|
|
|
|
|
|
type NaiveNodeIDAllocatorImpl struct {
|
2021-01-26 14:55:57 +08:00
|
|
|
impl *allocator.IDAllocator
|
2021-01-27 20:00:47 +08:00
|
|
|
now UniqueID
|
|
|
|
mtx sync.Mutex
|
2021-01-22 12:57:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (allocator *NaiveNodeIDAllocatorImpl) AllocOne() UniqueID {
|
2021-01-27 20:00:47 +08:00
|
|
|
allocator.mtx.Lock()
|
|
|
|
defer func() {
|
2021-02-05 13:49:51 +08:00
|
|
|
// allocator.now++
|
2021-01-27 20:00:47 +08:00
|
|
|
allocator.mtx.Unlock()
|
|
|
|
}()
|
|
|
|
return allocator.now
|
2021-01-22 12:57:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewNodeIDAllocator() NodeIDAllocator {
|
|
|
|
return &NaiveNodeIDAllocatorImpl{
|
2021-02-05 13:49:51 +08:00
|
|
|
now: 1,
|
2021-01-22 12:57:23 +08:00
|
|
|
}
|
|
|
|
}
|