mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-05 05:18:52 +08:00
3b08162059
Signed-off-by: sunby <bingyi.sun@zilliz.com>
54 lines
1.2 KiB
Go
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
|
|
}
|