From d8c1bd24f2bfbed3a968dfd260b1de88114ed8c9 Mon Sep 17 00:00:00 2001 From: congqixia Date: Mon, 28 Oct 2024 18:54:23 +0800 Subject: [PATCH] enhance: Utilize proxy metacache for `HasCollection` (#37185) Related to #37183 Utilize proxy metacache for `HasCollection` request, if collection exists in metacache, it could be deducted that collection must exist in system. Signed-off-by: Congqi Xia --- internal/proxy/task.go | 13 ++++++++++--- internal/proxy/task_test.go | 17 ++++++++++++++++- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/internal/proxy/task.go b/internal/proxy/task.go index 850bbd25fd..5bfcf4ab3f 100644 --- a/internal/proxy/task.go +++ b/internal/proxy/task.go @@ -564,9 +564,16 @@ func (t *hasCollectionTask) PreExecute(ctx context.Context) error { } func (t *hasCollectionTask) Execute(ctx context.Context) error { - var err error - t.result, err = t.rootCoord.HasCollection(ctx, t.HasCollectionRequest) - return merr.CheckRPCCall(t.result, err) + _, err := globalMetaCache.GetCollectionID(ctx, t.HasCollectionRequest.GetDbName(), t.HasCollectionRequest.GetCollectionName()) + t.result = &milvuspb.BoolResponse{} + // error other than + if err != nil && !errors.Is(err, merr.ErrCollectionNotFound) { + return err + } + // if collection not nil, means error is ErrCollectionNotFound, result is false + // otherwise, result is true + t.result.Value = (err == nil) + return nil } func (t *hasCollectionTask) PostExecute(ctx context.Context) error { diff --git a/internal/proxy/task_test.go b/internal/proxy/task_test.go index e60d046f2d..2eb4b219e2 100644 --- a/internal/proxy/task_test.go +++ b/internal/proxy/task_test.go @@ -1081,8 +1081,23 @@ func TestHasCollectionTask(t *testing.T) { err = task.PreExecute(ctx) assert.Error(t, err) - rc.updateState(commonpb.StateCode_Abnormal) task.CollectionName = collectionName + + // invalidate collection cache, trigger rootcoord rpc + globalMetaCache.RemoveCollection(ctx, dbName, collectionName) + + // rc return collection not found error + rc.describeCollectionFunc = func(ctx context.Context, request *milvuspb.DescribeCollectionRequest) (*milvuspb.DescribeCollectionResponse, error) { + return nil, merr.WrapErrCollectionNotFoundWithDB(dbName, collectionName) + } + err = task.PreExecute(ctx) + assert.NoError(t, err) + err = task.Execute(ctx) + assert.NoError(t, err) + assert.False(t, task.result.GetValue()) + + // rootcoord failed to get response + rc.updateState(commonpb.StateCode_Abnormal) err = task.PreExecute(ctx) assert.NoError(t, err) err = task.Execute(ctx)