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 <congqi.xia@zilliz.com>
This commit is contained in:
congqixia 2024-10-28 18:54:23 +08:00 committed by GitHub
parent fc69df44a1
commit d8c1bd24f2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 4 deletions

View File

@ -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 {

View File

@ -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)