2021-04-19 11:35:38 +08: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-06-22 10:42:07 +08:00
|
|
|
package datacoord
|
2021-01-19 12:10:49 +08:00
|
|
|
|
2021-01-22 19:43:27 +08:00
|
|
|
import (
|
2021-02-26 17:44:24 +08:00
|
|
|
"context"
|
|
|
|
|
2021-04-22 14:45:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/types"
|
2021-03-05 20:41:34 +08:00
|
|
|
|
2021-04-22 14:45:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/commonpb"
|
2021-06-22 16:14:09 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/rootcoordpb"
|
2021-01-22 19:43:27 +08:00
|
|
|
)
|
|
|
|
|
2021-05-28 09:55:21 +08:00
|
|
|
type allocator interface {
|
2021-01-19 12:10:49 +08:00
|
|
|
allocTimestamp() (Timestamp, error)
|
|
|
|
allocID() (UniqueID, error)
|
|
|
|
}
|
|
|
|
|
2021-06-21 17:28:03 +08:00
|
|
|
type rootCoordAllocator struct {
|
2021-06-22 18:24:08 +08:00
|
|
|
ctx context.Context
|
2021-06-21 17:28:03 +08:00
|
|
|
rootCoordClient types.RootCoord
|
2021-01-19 12:10:49 +08:00
|
|
|
}
|
|
|
|
|
2021-06-22 18:24:08 +08:00
|
|
|
func newRootCoordAllocator(ctx context.Context, rootCoordClient types.RootCoord) *rootCoordAllocator {
|
2021-06-21 17:28:03 +08:00
|
|
|
return &rootCoordAllocator{
|
2021-06-22 18:24:08 +08:00
|
|
|
ctx: ctx,
|
2021-06-21 17:28:03 +08:00
|
|
|
rootCoordClient: rootCoordClient,
|
2021-01-22 19:43:27 +08:00
|
|
|
}
|
2021-01-19 12:10:49 +08:00
|
|
|
}
|
|
|
|
|
2021-06-22 18:24:08 +08:00
|
|
|
func (alloc *rootCoordAllocator) allocTimestamp() (Timestamp, error) {
|
|
|
|
resp, err := alloc.rootCoordClient.AllocTimestamp(alloc.ctx, &rootcoordpb.AllocTimestampRequest{
|
2021-01-22 19:43:27 +08:00
|
|
|
Base: &commonpb.MsgBase{
|
2021-04-23 10:15:30 +08:00
|
|
|
MsgType: commonpb.MsgType_RequestTSO,
|
2021-06-23 12:10:12 +08:00
|
|
|
MsgID: 0,
|
|
|
|
Timestamp: 0,
|
2021-01-26 15:14:49 +08:00
|
|
|
SourceID: Params.NodeID,
|
2021-01-22 19:43:27 +08:00
|
|
|
},
|
|
|
|
Count: 1,
|
|
|
|
})
|
2021-02-23 09:58:06 +08:00
|
|
|
if err = VerifyResponse(resp, err); err != nil {
|
2021-01-22 19:43:27 +08:00
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
return resp.Timestamp, nil
|
2021-01-19 12:10:49 +08:00
|
|
|
}
|
|
|
|
|
2021-06-22 18:24:08 +08:00
|
|
|
func (alloc *rootCoordAllocator) allocID() (UniqueID, error) {
|
|
|
|
resp, err := alloc.rootCoordClient.AllocID(alloc.ctx, &rootcoordpb.AllocIDRequest{
|
2021-01-22 19:43:27 +08:00
|
|
|
Base: &commonpb.MsgBase{
|
2021-04-23 10:15:30 +08:00
|
|
|
MsgType: commonpb.MsgType_RequestID,
|
2021-06-23 12:10:12 +08:00
|
|
|
MsgID: 0,
|
|
|
|
Timestamp: 0,
|
2021-01-26 15:14:49 +08:00
|
|
|
SourceID: Params.NodeID,
|
2021-01-22 19:43:27 +08:00
|
|
|
},
|
|
|
|
Count: 1,
|
|
|
|
})
|
2021-02-23 09:58:06 +08:00
|
|
|
if err = VerifyResponse(resp, err); err != nil {
|
2021-01-22 19:43:27 +08:00
|
|
|
return 0, err
|
|
|
|
}
|
2021-02-23 09:58:06 +08:00
|
|
|
|
2021-01-22 19:43:27 +08:00
|
|
|
return resp.ID, nil
|
2021-01-19 12:10:49 +08:00
|
|
|
}
|