milvus/internal/dataservice/allocator.go
sunby 3b08162059 Add main function
Signed-off-by: sunby <bingyi.sun@zilliz.com>
2021-01-26 15:14:49 +08:00

54 lines
1.2 KiB
Go

package dataservice
import (
"github.com/zilliztech/milvus-distributed/internal/proto/commonpb"
"github.com/zilliztech/milvus-distributed/internal/proto/masterpb"
)
type allocator interface {
allocTimestamp() (Timestamp, error)
allocID() (UniqueID, error)
}
type allocatorImpl struct {
masterClient MasterClient
}
func newAllocatorImpl(masterClient MasterClient) *allocatorImpl {
return &allocatorImpl{
masterClient: masterClient,
}
}
func (allocator *allocatorImpl) allocTimestamp() (Timestamp, error) {
resp, err := allocator.masterClient.AllocTimestamp(&masterpb.TsoRequest{
Base: &commonpb.MsgBase{
MsgType: commonpb.MsgType_kShowCollections,
MsgID: -1, // todo add msg id
Timestamp: 0, // todo
SourceID: Params.NodeID,
},
Count: 1,
})
if err != nil {
return 0, err
}
return resp.Timestamp, nil
}
func (allocator *allocatorImpl) allocID() (UniqueID, error) {
resp, err := allocator.masterClient.AllocID(&masterpb.IDRequest{
Base: &commonpb.MsgBase{
MsgType: commonpb.MsgType_kShowCollections,
MsgID: -1, // todo add msg id
Timestamp: 0, // todo
SourceID: Params.NodeID,
},
Count: 1,
})
if err != nil {
return 0, err
}
return resp.ID, nil
}