2021-01-19 04:10:49 +00:00
|
|
|
package dataservice
|
|
|
|
|
2021-01-22 11:43:27 +00:00
|
|
|
import (
|
|
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/commonpb"
|
|
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/masterpb"
|
|
|
|
)
|
|
|
|
|
2021-01-19 04:10:49 +00:00
|
|
|
type allocator interface {
|
|
|
|
allocTimestamp() (Timestamp, error)
|
|
|
|
allocID() (UniqueID, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
type allocatorImpl struct {
|
2021-01-26 07:14:49 +00:00
|
|
|
masterClient MasterClient
|
2021-01-19 04:10:49 +00:00
|
|
|
}
|
|
|
|
|
2021-01-26 07:14:49 +00:00
|
|
|
func newAllocatorImpl(masterClient MasterClient) *allocatorImpl {
|
2021-01-22 11:43:27 +00:00
|
|
|
return &allocatorImpl{
|
|
|
|
masterClient: masterClient,
|
|
|
|
}
|
2021-01-19 04:10:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (allocator *allocatorImpl) allocTimestamp() (Timestamp, error) {
|
2021-01-22 11:43:27 +00:00
|
|
|
resp, err := allocator.masterClient.AllocTimestamp(&masterpb.TsoRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_kShowCollections,
|
|
|
|
MsgID: -1, // todo add msg id
|
|
|
|
Timestamp: 0, // todo
|
2021-01-26 07:14:49 +00:00
|
|
|
SourceID: Params.NodeID,
|
2021-01-22 11:43:27 +00:00
|
|
|
},
|
|
|
|
Count: 1,
|
|
|
|
})
|
2021-02-23 01:58:06 +00:00
|
|
|
if err = VerifyResponse(resp, err); err != nil {
|
2021-01-22 11:43:27 +00:00
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
return resp.Timestamp, nil
|
2021-01-19 04:10:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (allocator *allocatorImpl) allocID() (UniqueID, error) {
|
2021-01-22 11:43:27 +00:00
|
|
|
resp, err := allocator.masterClient.AllocID(&masterpb.IDRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_kShowCollections,
|
|
|
|
MsgID: -1, // todo add msg id
|
|
|
|
Timestamp: 0, // todo
|
2021-01-26 07:14:49 +00:00
|
|
|
SourceID: Params.NodeID,
|
2021-01-22 11:43:27 +00:00
|
|
|
},
|
|
|
|
Count: 1,
|
|
|
|
})
|
2021-02-23 01:58:06 +00:00
|
|
|
if err = VerifyResponse(resp, err); err != nil {
|
2021-01-22 11:43:27 +00:00
|
|
|
return 0, err
|
|
|
|
}
|
2021-02-23 01:58:06 +00:00
|
|
|
|
2021-01-22 11:43:27 +00:00
|
|
|
return resp.ID, nil
|
2021-01-19 04:10:49 +00:00
|
|
|
}
|