mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-04 12:59:23 +08:00
f3649f0419
Signed-off-by: godchen <qingxiang.chen@zilliz.com>
61 lines
1.4 KiB
Go
61 lines
1.4 KiB
Go
package dataservice
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/zilliztech/milvus-distributed/internal/types"
|
|
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/commonpb"
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/masterpb"
|
|
)
|
|
|
|
type allocatorInterface interface {
|
|
allocTimestamp() (Timestamp, error)
|
|
allocID() (UniqueID, error)
|
|
}
|
|
|
|
type allocator struct {
|
|
masterClient types.MasterService
|
|
}
|
|
|
|
func newAllocator(masterClient types.MasterService) *allocator {
|
|
return &allocator{
|
|
masterClient: masterClient,
|
|
}
|
|
}
|
|
|
|
func (allocator *allocator) allocTimestamp() (Timestamp, error) {
|
|
ctx := context.TODO()
|
|
resp, err := allocator.masterClient.AllocTimestamp(ctx, &masterpb.AllocTimestampRequest{
|
|
Base: &commonpb.MsgBase{
|
|
MsgType: commonpb.MsgType_ShowCollections,
|
|
MsgID: -1, // todo add msg id
|
|
Timestamp: 0, // todo
|
|
SourceID: Params.NodeID,
|
|
},
|
|
Count: 1,
|
|
})
|
|
if err = VerifyResponse(resp, err); err != nil {
|
|
return 0, err
|
|
}
|
|
return resp.Timestamp, nil
|
|
}
|
|
|
|
func (allocator *allocator) allocID() (UniqueID, error) {
|
|
ctx := context.TODO()
|
|
resp, err := allocator.masterClient.AllocID(ctx, &masterpb.AllocIDRequest{
|
|
Base: &commonpb.MsgBase{
|
|
MsgType: commonpb.MsgType_ShowCollections,
|
|
MsgID: -1, // todo add msg id
|
|
Timestamp: 0, // todo
|
|
SourceID: Params.NodeID,
|
|
},
|
|
Count: 1,
|
|
})
|
|
if err = VerifyResponse(resp, err); err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
return resp.ID, nil
|
|
}
|