mirror of
https://gitee.com/milvus-io/milvus.git
synced 2025-12-08 01:58:34 +08:00
Fix golint error in proxy (#9834)
Signed-off-by: zhenshan.cao <zhenshan.cao@zilliz.com>
This commit is contained in:
parent
c2c927bd55
commit
3b230b5cd9
@ -32,7 +32,6 @@ type idAllocatorInterface interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// use timestampAllocatorInterface to keep other components testable
|
// use timestampAllocatorInterface to keep other components testable
|
||||||
// include: TimestampAllocator
|
|
||||||
type timestampAllocatorInterface interface {
|
type timestampAllocatorInterface interface {
|
||||||
AllocTimestamp(ctx context.Context, req *rootcoordpb.AllocTimestampRequest) (*rootcoordpb.AllocTimestampResponse, error)
|
AllocTimestamp(ctx context.Context, req *rootcoordpb.AllocTimestampRequest) (*rootcoordpb.AllocTimestampResponse, error)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -69,7 +69,7 @@ type Proxy struct {
|
|||||||
chTicker channelsTimeTicker
|
chTicker channelsTimeTicker
|
||||||
|
|
||||||
idAllocator *allocator.IDAllocator
|
idAllocator *allocator.IDAllocator
|
||||||
tsoAllocator *TimestampAllocator
|
tsoAllocator *timestampAllocator
|
||||||
segAssigner *segIDAssigner
|
segAssigner *segIDAssigner
|
||||||
|
|
||||||
metricsCacheManager *metricsinfo.MetricsCacheManager
|
metricsCacheManager *metricsinfo.MetricsCacheManager
|
||||||
@ -180,7 +180,7 @@ func (node *Proxy) Init() error {
|
|||||||
|
|
||||||
node.idAllocator = idAllocator
|
node.idAllocator = idAllocator
|
||||||
|
|
||||||
tsoAllocator, err := NewTimestampAllocator(node.ctx, node.rootCoord, Params.ProxyID)
|
tsoAllocator, err := newTimestampAllocator(node.ctx, node.rootCoord, Params.ProxyID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,14 +20,14 @@ import (
|
|||||||
"github.com/milvus-io/milvus/internal/proto/rootcoordpb"
|
"github.com/milvus-io/milvus/internal/proto/rootcoordpb"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TimestampAllocator struct {
|
type timestampAllocator struct {
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
tso timestampAllocatorInterface
|
tso timestampAllocatorInterface
|
||||||
peerID UniqueID
|
peerID UniqueID
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTimestampAllocator(ctx context.Context, tso timestampAllocatorInterface, peerID UniqueID) (*TimestampAllocator, error) {
|
func newTimestampAllocator(ctx context.Context, tso timestampAllocatorInterface, peerID UniqueID) (*timestampAllocator, error) {
|
||||||
a := &TimestampAllocator{
|
a := ×tampAllocator{
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
peerID: peerID,
|
peerID: peerID,
|
||||||
tso: tso,
|
tso: tso,
|
||||||
@ -35,7 +35,7 @@ func NewTimestampAllocator(ctx context.Context, tso timestampAllocatorInterface,
|
|||||||
return a, nil
|
return a, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ta *TimestampAllocator) Alloc(count uint32) ([]Timestamp, error) {
|
func (ta *timestampAllocator) alloc(count uint32) ([]Timestamp, error) {
|
||||||
ctx, cancel := context.WithTimeout(ta.ctx, 5*time.Second)
|
ctx, cancel := context.WithTimeout(ta.ctx, 5*time.Second)
|
||||||
req := &rootcoordpb.AllocTimestampRequest{
|
req := &rootcoordpb.AllocTimestampRequest{
|
||||||
Base: &commonpb.MsgBase{
|
Base: &commonpb.MsgBase{
|
||||||
@ -65,8 +65,8 @@ func (ta *TimestampAllocator) Alloc(count uint32) ([]Timestamp, error) {
|
|||||||
return ret, nil
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ta *TimestampAllocator) AllocOne() (Timestamp, error) {
|
func (ta *timestampAllocator) AllocOne() (Timestamp, error) {
|
||||||
ret, err := ta.Alloc(1)
|
ret, err := ta.alloc(1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,22 +26,22 @@ func TestNewTimestampAllocator(t *testing.T) {
|
|||||||
tso := newMockTimestampAllocatorInterface()
|
tso := newMockTimestampAllocatorInterface()
|
||||||
peerID := UniqueID(uniquegenerator.GetUniqueIntGeneratorIns().GetInt())
|
peerID := UniqueID(uniquegenerator.GetUniqueIntGeneratorIns().GetInt())
|
||||||
|
|
||||||
tsAllocator, err := NewTimestampAllocator(ctx, tso, peerID)
|
tsAllocator, err := newTimestampAllocator(ctx, tso, peerID)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.NotNil(t, tsAllocator)
|
assert.NotNil(t, tsAllocator)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTimestampAllocator_Alloc(t *testing.T) {
|
func TestTimestampAllocator_alloc(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
tso := newMockTimestampAllocatorInterface()
|
tso := newMockTimestampAllocatorInterface()
|
||||||
peerID := UniqueID(uniquegenerator.GetUniqueIntGeneratorIns().GetInt())
|
peerID := UniqueID(uniquegenerator.GetUniqueIntGeneratorIns().GetInt())
|
||||||
|
|
||||||
tsAllocator, err := NewTimestampAllocator(ctx, tso, peerID)
|
tsAllocator, err := newTimestampAllocator(ctx, tso, peerID)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.NotNil(t, tsAllocator)
|
assert.NotNil(t, tsAllocator)
|
||||||
|
|
||||||
count := rand.Uint32()%100 + 1
|
count := rand.Uint32()%100 + 1
|
||||||
ret, err := tsAllocator.Alloc(count)
|
ret, err := tsAllocator.alloc(count)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, int(count), len(ret))
|
assert.Equal(t, int(count), len(ret))
|
||||||
}
|
}
|
||||||
@ -51,7 +51,7 @@ func TestTimestampAllocator_AllocOne(t *testing.T) {
|
|||||||
tso := newMockTimestampAllocatorInterface()
|
tso := newMockTimestampAllocatorInterface()
|
||||||
peerID := UniqueID(uniquegenerator.GetUniqueIntGeneratorIns().GetInt())
|
peerID := UniqueID(uniquegenerator.GetUniqueIntGeneratorIns().GetInt())
|
||||||
|
|
||||||
tsAllocator, err := NewTimestampAllocator(ctx, tso, peerID)
|
tsAllocator, err := newTimestampAllocator(ctx, tso, peerID)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.NotNil(t, tsAllocator)
|
assert.NotNil(t, tsAllocator)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user