diff --git a/internal/proxy/meta_cache.go b/internal/proxy/meta_cache.go index 1d360f758c734..4d558893723c5 100644 --- a/internal/proxy/meta_cache.go +++ b/internal/proxy/meta_cache.go @@ -89,8 +89,6 @@ type Cache interface { RemoveDatabase(ctx context.Context, database string) HasDatabase(ctx context.Context, database string) bool GetDatabaseInfo(ctx context.Context, database string) (*databaseInfo, error) - // AllocID is only using on requests that need to skip timestamp allocation, don't overuse it. - AllocID(ctx context.Context) (int64, error) } type collectionBasicInfo struct { collID typeutil.UniqueID diff --git a/internal/proxy/meta_cache_test.go b/internal/proxy/meta_cache_test.go index 3f97a1dca6bbc..efe3568ca9e27 100644 --- a/internal/proxy/meta_cache_test.go +++ b/internal/proxy/meta_cache_test.go @@ -887,71 +887,6 @@ func TestGetDatabaseInfo(t *testing.T) { }) } -func TestMetaCache_AllocID(t *testing.T) { - ctx := context.Background() - queryCoord := &mocks.MockQueryCoordClient{} - shardMgr := newShardClientMgr() - - t.Run("success", func(t *testing.T) { - rootCoord := mocks.NewMockRootCoordClient(t) - rootCoord.EXPECT().AllocID(mock.Anything, mock.Anything).Return(&rootcoordpb.AllocIDResponse{ - Status: merr.Status(nil), - ID: 11198, - Count: 10, - }, nil) - rootCoord.EXPECT().ListPolicy(mock.Anything, mock.Anything).Return(&internalpb.ListPolicyResponse{ - Status: merr.Success(), - PolicyInfos: []string{"policy1", "policy2", "policy3"}, - }, nil) - - err := InitMetaCache(ctx, rootCoord, queryCoord, shardMgr) - assert.NoError(t, err) - assert.Equal(t, globalMetaCache.HasDatabase(ctx, dbName), false) - - id, err := globalMetaCache.AllocID(ctx) - assert.NoError(t, err) - assert.Equal(t, id, int64(11198)) - }) - - t.Run("error", func(t *testing.T) { - rootCoord := mocks.NewMockRootCoordClient(t) - rootCoord.EXPECT().AllocID(mock.Anything, mock.Anything).Return(&rootcoordpb.AllocIDResponse{ - Status: merr.Status(nil), - }, fmt.Errorf("mock error")) - rootCoord.EXPECT().ListPolicy(mock.Anything, mock.Anything).Return(&internalpb.ListPolicyResponse{ - Status: merr.Success(), - PolicyInfos: []string{"policy1", "policy2", "policy3"}, - }, nil) - - err := InitMetaCache(ctx, rootCoord, queryCoord, shardMgr) - assert.NoError(t, err) - assert.Equal(t, globalMetaCache.HasDatabase(ctx, dbName), false) - - id, err := globalMetaCache.AllocID(ctx) - assert.Error(t, err) - assert.Equal(t, id, int64(0)) - }) - - t.Run("failed", func(t *testing.T) { - rootCoord := mocks.NewMockRootCoordClient(t) - rootCoord.EXPECT().AllocID(mock.Anything, mock.Anything).Return(&rootcoordpb.AllocIDResponse{ - Status: merr.Status(fmt.Errorf("mock failed")), - }, nil) - rootCoord.EXPECT().ListPolicy(mock.Anything, mock.Anything).Return(&internalpb.ListPolicyResponse{ - Status: merr.Success(), - PolicyInfos: []string{"policy1", "policy2", "policy3"}, - }, nil) - - err := InitMetaCache(ctx, rootCoord, queryCoord, shardMgr) - assert.NoError(t, err) - assert.Equal(t, globalMetaCache.HasDatabase(ctx, dbName), false) - - id, err := globalMetaCache.AllocID(ctx) - assert.Error(t, err) - assert.Equal(t, id, int64(0)) - }) -} - func TestMetaCache_InvalidateShardLeaderCache(t *testing.T) { paramtable.Init() paramtable.Get().Save(Params.ProxyCfg.ShardLeaderCacheInterval.Key, "1") diff --git a/internal/proxy/mock_cache.go b/internal/proxy/mock_cache.go index cb1697b7f2ace..47c372d477cbc 100644 --- a/internal/proxy/mock_cache.go +++ b/internal/proxy/mock_cache.go @@ -24,62 +24,6 @@ func (_m *MockCache) EXPECT() *MockCache_Expecter { return &MockCache_Expecter{mock: &_m.Mock} } -// AllocID provides a mock function with given fields: ctx -func (_m *MockCache) AllocID(ctx context.Context) (int64, error) { - ret := _m.Called(ctx) - - if len(ret) == 0 { - panic("no return value specified for AllocID") - } - - var r0 int64 - var r1 error - if rf, ok := ret.Get(0).(func(context.Context) (int64, error)); ok { - return rf(ctx) - } - if rf, ok := ret.Get(0).(func(context.Context) int64); ok { - r0 = rf(ctx) - } else { - r0 = ret.Get(0).(int64) - } - - if rf, ok := ret.Get(1).(func(context.Context) error); ok { - r1 = rf(ctx) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// MockCache_AllocID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllocID' -type MockCache_AllocID_Call struct { - *mock.Call -} - -// AllocID is a helper method to define mock.On call -// - ctx context.Context -func (_e *MockCache_Expecter) AllocID(ctx interface{}) *MockCache_AllocID_Call { - return &MockCache_AllocID_Call{Call: _e.mock.On("AllocID", ctx)} -} - -func (_c *MockCache_AllocID_Call) Run(run func(ctx context.Context)) *MockCache_AllocID_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context)) - }) - return _c -} - -func (_c *MockCache_AllocID_Call) Return(_a0 int64, _a1 error) *MockCache_AllocID_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *MockCache_AllocID_Call) RunAndReturn(run func(context.Context) (int64, error)) *MockCache_AllocID_Call { - _c.Call.Return(run) - return _c -} - // DeprecateShardCache provides a mock function with given fields: database, collectionName func (_m *MockCache) DeprecateShardCache(database string, collectionName string) { _m.Called(database, collectionName) diff --git a/internal/proxy/task_scheduler.go b/internal/proxy/task_scheduler.go index 05a8199844f94..d36b9980533e9 100644 --- a/internal/proxy/task_scheduler.go +++ b/internal/proxy/task_scheduler.go @@ -177,18 +177,14 @@ func (queue *baseTaskQueue) Enqueue(t task) error { var id UniqueID if t.CanSkipAllocTimestamp() { ts = tsoutil.ComposeTS(time.Now().UnixMilli(), 0) - id, err = globalMetaCache.AllocID(t.TraceCtx()) - if err != nil { - return err - } } else { ts, err = queue.tsoAllocatorIns.AllocOne(t.TraceCtx()) if err != nil { return err } - // we always use same msg id and ts for now. - id = UniqueID(ts) } + // we always use same msg id and ts for now. + id = UniqueID(ts) t.SetTs(ts) t.SetID(id) diff --git a/internal/proxy/task_scheduler_test.go b/internal/proxy/task_scheduler_test.go index 9b16150b4cf5e..6952a931d690f 100644 --- a/internal/proxy/task_scheduler_test.go +++ b/internal/proxy/task_scheduler_test.go @@ -625,7 +625,6 @@ func TestTaskScheduler_SkipAllocTimestamp(t *testing.T) { collID: collID, consistencyLevel: commonpb.ConsistencyLevel_Eventually, }, nil) - mockMetaCache.EXPECT().AllocID(mock.Anything).Return(1, nil).Twice() t.Run("query", func(t *testing.T) { qt := &queryTask{ @@ -658,21 +657,4 @@ func TestTaskScheduler_SkipAllocTimestamp(t *testing.T) { err := queue.Enqueue(st) assert.NoError(t, err) }) - - mockMetaCache.EXPECT().AllocID(mock.Anything).Return(0, fmt.Errorf("mock error")).Once() - t.Run("failed", func(t *testing.T) { - st := &searchTask{ - SearchRequest: &internalpb.SearchRequest{ - Base: &commonpb.MsgBase{}, - }, - request: &milvuspb.SearchRequest{ - DbName: dbName, - CollectionName: collName, - UseDefaultConsistency: true, - }, - } - - err := queue.Enqueue(st) - assert.Error(t, err) - }) }