mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-11-29 18:38:44 +08:00
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:
parent
fc69df44a1
commit
d8c1bd24f2
@ -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 {
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user