2021-01-24 21:20:11 +08:00
|
|
|
package datanode
|
|
|
|
|
|
|
|
import (
|
2021-02-26 17:44:24 +08:00
|
|
|
"context"
|
|
|
|
|
2021-03-05 20:41:34 +08:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/types"
|
|
|
|
|
2021-01-24 21:20:11 +08:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/commonpb"
|
|
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/masterpb"
|
|
|
|
)
|
|
|
|
|
2021-03-05 20:41:34 +08:00
|
|
|
type allocatorInterface interface {
|
|
|
|
allocID() (UniqueID, error)
|
|
|
|
}
|
|
|
|
type allocator struct {
|
|
|
|
masterService types.MasterService
|
|
|
|
}
|
2021-01-24 21:20:11 +08:00
|
|
|
|
2021-03-05 20:41:34 +08:00
|
|
|
func newAllocator(s types.MasterService) *allocator {
|
2021-03-05 16:52:45 +08:00
|
|
|
return &allocator{
|
2021-01-24 21:20:11 +08:00
|
|
|
masterService: s,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-05 16:52:45 +08:00
|
|
|
func (alloc *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 := alloc.masterService.AllocID(ctx, &masterpb.AllocIDRequest{
|
2021-01-24 21:20:11 +08:00
|
|
|
Base: &commonpb.MsgBase{
|
2021-03-10 14:45:35 +08:00
|
|
|
MsgType: commonpb.MsgType_RequestID,
|
2021-01-25 18:33:10 +08:00
|
|
|
MsgID: 1, // GOOSE TODO
|
2021-01-24 21:20:11 +08:00
|
|
|
Timestamp: 0, // GOOSE TODO
|
|
|
|
SourceID: Params.NodeID,
|
|
|
|
},
|
|
|
|
Count: 1,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
return resp.ID, nil
|
|
|
|
}
|