Refactor master scheduler: has_collection

Signed-off-by: XuanYang-cn <xuan.yang@zilliz.com>
This commit is contained in:
XuanYang-cn 2020-11-13 15:44:02 +08:00 committed by yefu.chen
parent 0b478b614a
commit 1b48e84c35
2 changed files with 48 additions and 2 deletions

View File

@ -113,6 +113,37 @@ func TestMaster_CreateCollectionTask(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, st.ErrorCode, commonpb.ErrorCode_SUCCESS)
reqHasCollection := internalpb.HasCollectionRequest{
MsgType: internalpb.MsgType_kHasCollection,
ReqID: 1,
Timestamp: 11,
ProxyID: 1,
CollectionName: &servicepb.CollectionName{
CollectionName: "col1",
},
}
// HasCollection "col1" is true
log.Printf("... [Has] collection col1\n")
boolResp, err := cli.HasCollection(ctx, &reqHasCollection)
assert.Nil(t, err)
assert.Equal(t, true, boolResp.Value)
assert.Equal(t, boolResp.Status.ErrorCode, commonpb.ErrorCode_SUCCESS)
// HasCollection "colNotExist" is false
reqHasCollection.CollectionName.CollectionName = "colNotExist"
boolResp, err = cli.HasCollection(ctx, &reqHasCollection)
assert.Nil(t, err)
assert.Equal(t, boolResp.Value, false)
assert.Equal(t, boolResp.Status.ErrorCode, commonpb.ErrorCode_SUCCESS)
// HasCollection error
reqHasCollection.Timestamp = Timestamp(10)
reqHasCollection.CollectionName.CollectionName = "col1"
boolResp, err = cli.HasCollection(ctx, &reqHasCollection)
assert.Nil(t, err)
assert.NotEqual(t, boolResp.Status.ErrorCode, commonpb.ErrorCode_SUCCESS)
collMeta, err := svr.mt.GetCollectionByName(sch.Name)
assert.Nil(t, err)
t.Logf("collection id = %d", collMeta.ID)
@ -150,8 +181,8 @@ func TestMaster_CreateCollectionTask(t *testing.T) {
st, err = cli.CreateCollection(ctx, &req)
assert.Nil(t, err)
assert.NotEqual(t, st.ErrorCode, commonpb.ErrorCode_SUCCESS)
// ------------------------------DropCollectionTask---------------------------
// ------------------------------DropCollectionTask---------------------------
log.Printf("... [Drop] collection col1\n")
ser := servicepb.CollectionName{CollectionName: "col1"}
@ -163,6 +194,7 @@ func TestMaster_CreateCollectionTask(t *testing.T) {
CollectionName: &ser,
}
// DropCollection
st, err = cli.DropCollection(ctx, &reqDrop)
assert.Nil(t, err)
assert.Equal(t, st.ErrorCode, commonpb.ErrorCode_SUCCESS)
@ -170,6 +202,14 @@ func TestMaster_CreateCollectionTask(t *testing.T) {
collMeta, err = svr.mt.GetCollectionByName(sch.Name)
assert.NotNil(t, err)
// HasCollection "col1" is false
reqHasCollection.Timestamp = Timestamp(11)
reqHasCollection.CollectionName.CollectionName = "col1"
boolResp, err = cli.HasCollection(ctx, &reqHasCollection)
assert.Nil(t, err)
assert.Equal(t, false, boolResp.Value)
assert.Equal(t, commonpb.ErrorCode_SUCCESS, boolResp.Status.ErrorCode)
// Drop again
st, err = cli.DropCollection(ctx, &reqDrop)
assert.Nil(t, err)
@ -182,5 +222,10 @@ func TestMaster_CreateCollectionTask(t *testing.T) {
log.Printf(st.Reason)
assert.Equal(t, st.ErrorCode, commonpb.ErrorCode_SUCCESS)
boolResp, err = cli.HasCollection(ctx, &reqHasCollection)
assert.Nil(t, err)
assert.Equal(t, true, boolResp.Value)
assert.Equal(t, commonpb.ErrorCode_SUCCESS, boolResp.Status.ErrorCode)
svr.Close()
}

View File

@ -93,7 +93,7 @@ func (s *Master) HasCollection(ctx context.Context, in *internalpb.HasCollection
response := &servicepb.BoolResponse{
Status: st,
Value: t.(*hasCollectionTask).hasCollection,
Value: false,
}
var err = s.scheduler.Enqueue(t)
@ -109,6 +109,7 @@ func (s *Master) HasCollection(ctx context.Context, in *internalpb.HasCollection
}
st.ErrorCode = commonpb.ErrorCode_SUCCESS
response.Value = t.(*hasCollectionTask).hasCollection
return response, nil
}