2021-04-19 02:09:43 +00:00
|
|
|
// Copyright (C) 2019-2020 Zilliz. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
|
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
|
|
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
|
|
|
// or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
|
|
|
2021-01-22 04:57:23 +00:00
|
|
|
package proxyservice
|
|
|
|
|
|
|
|
import (
|
2021-01-27 12:00:47 +00:00
|
|
|
"sync"
|
2021-01-26 06:55:57 +00:00
|
|
|
|
2021-04-22 06:45:57 +00:00
|
|
|
"github.com/milvus-io/milvus/internal/allocator"
|
|
|
|
"github.com/milvus-io/milvus/internal/util/typeutil"
|
2021-01-22 04:57:23 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type UniqueID = typeutil.UniqueID
|
2021-01-26 05:41:41 +00:00
|
|
|
type Timestamp = typeutil.Timestamp
|
2021-01-22 04:57:23 +00:00
|
|
|
|
2021-04-06 06:12:57 +00:00
|
|
|
type nodeIDAllocator interface {
|
2021-01-22 04:57:23 +00:00
|
|
|
AllocOne() UniqueID
|
|
|
|
}
|
|
|
|
|
2021-04-06 06:12:57 +00:00
|
|
|
type naiveNodeIDAllocator struct {
|
2021-03-05 08:52:45 +00:00
|
|
|
allocator *allocator.IDAllocator
|
|
|
|
now UniqueID
|
|
|
|
mtx sync.Mutex
|
2021-01-22 04:57:23 +00:00
|
|
|
}
|
|
|
|
|
2021-04-06 06:12:57 +00:00
|
|
|
func (allocator *naiveNodeIDAllocator) AllocOne() UniqueID {
|
2021-01-27 12:00:47 +00:00
|
|
|
allocator.mtx.Lock()
|
|
|
|
defer func() {
|
2021-02-05 05:49:51 +00:00
|
|
|
// allocator.now++
|
2021-01-27 12:00:47 +00:00
|
|
|
allocator.mtx.Unlock()
|
|
|
|
}()
|
|
|
|
return allocator.now
|
2021-01-22 04:57:23 +00:00
|
|
|
}
|
|
|
|
|
2021-04-06 06:12:57 +00:00
|
|
|
func newNodeIDAllocator() *naiveNodeIDAllocator {
|
|
|
|
return &naiveNodeIDAllocator{
|
2021-02-05 05:49:51 +00:00
|
|
|
now: 1,
|
2021-01-22 04:57:23 +00:00
|
|
|
}
|
|
|
|
}
|