allocator.go 805 字节
Newer Older
X
XuanYang-cn 已提交
1 2 3
package datanode

import (
G
godchen 已提交
4 5
	"context"

X
XuanYang-cn 已提交
6 7 8 9 10
	"github.com/zilliztech/milvus-distributed/internal/proto/commonpb"
	"github.com/zilliztech/milvus-distributed/internal/proto/masterpb"
)

type (
11
	allocatorInterface interface {
X
XuanYang-cn 已提交
12 13 14
		allocID() (UniqueID, error)
	}

15
	allocator struct {
X
XuanYang-cn 已提交
16 17 18 19
		masterService MasterServiceInterface
	}
)

20 21
func newAllocator(s MasterServiceInterface) *allocator {
	return &allocator{
X
XuanYang-cn 已提交
22 23 24 25
		masterService: s,
	}
}

26
func (alloc *allocator) allocID() (UniqueID, error) {
G
godchen 已提交
27 28
	ctx := context.TODO()
	resp, err := alloc.masterService.AllocID(ctx, &masterpb.IDRequest{
X
XuanYang-cn 已提交
29
		Base: &commonpb.MsgBase{
X
Xiangyu Wang 已提交
30
			MsgType:   commonpb.MsgType_kRequestID,
31
			MsgID:     1, // GOOSE TODO
X
XuanYang-cn 已提交
32 33 34 35 36 37 38 39 40 41
			Timestamp: 0, // GOOSE TODO
			SourceID:  Params.NodeID,
		},
		Count: 1,
	})
	if err != nil {
		return 0, err
	}
	return resp.ID, nil
}