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-01-19 12:10:49 +08:00
|
|
|
package dataservice
|
|
|
|
|
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"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/masterpb"
|
2021-01-22 19:43:27 +08:00
|
|
|
)
|
|
|
|
|
2021-03-05 16:52:45 +08:00
|
|
|
type allocatorInterface interface {
|
2021-01-19 12:10:49 +08:00
|
|
|
allocTimestamp() (Timestamp, error)
|
|
|
|
allocID() (UniqueID, error)
|
|
|
|
}
|
|
|
|
|
2021-03-05 16:52:45 +08:00
|
|
|
type allocator struct {
|
2021-03-05 20:41:34 +08:00
|
|
|
masterClient types.MasterService
|
2021-01-19 12:10:49 +08:00
|
|
|
}
|
|
|
|
|
2021-03-05 20:41:34 +08:00
|
|
|
func newAllocator(masterClient types.MasterService) *allocator {
|
2021-03-05 16:52:45 +08:00
|
|
|
return &allocator{
|
2021-01-22 19:43:27 +08:00
|
|
|
masterClient: masterClient,
|
|
|
|
}
|
2021-01-19 12:10:49 +08:00
|
|
|
}
|
|
|
|
|
2021-03-05 16:52:45 +08:00
|
|
|
func (allocator *allocator) allocTimestamp() (Timestamp, error) {
|
2021-02-26 17:44:24 +08:00
|
|
|
ctx := context.TODO()
|
2021-03-12 14:22:09 +08:00
|
|
|
resp, err := allocator.masterClient.AllocTimestamp(ctx, &masterpb.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-01-22 19:43:27 +08:00
|
|
|
MsgID: -1, // todo add msg id
|
|
|
|
Timestamp: 0, // todo
|
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-03-05 16:52:45 +08:00
|
|
|
func (allocator *allocator) allocID() (UniqueID, error) {
|
2021-02-26 17:44:24 +08:00
|
|
|
ctx := context.TODO()
|
2021-03-12 14:22:09 +08:00
|
|
|
resp, err := allocator.masterClient.AllocID(ctx, &masterpb.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-01-22 19:43:27 +08:00
|
|
|
MsgID: -1, // todo add msg id
|
|
|
|
Timestamp: 0, // todo
|
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
|
|
|
}
|