Disable dropping collection via alias (#8850)

Signed-off-by: Yusup <yusup@lsgrep.com>
This commit is contained in:
Yusup 2021-10-08 09:37:53 +00:00 committed by GitHub
parent 8f44518faf
commit 49198dbce1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 42 additions and 9 deletions

View File

@ -1321,3 +1321,10 @@ func (mt *MetaTable) AlterAlias(collectionAlias string, collectionName string, t
}
return nil
}
func (mt *MetaTable) IsAlias(collectionAlias string) bool {
mt.ddLock.RLock()
defer mt.ddLock.RUnlock()
_, ok := mt.collAlias2ID[collectionAlias]
return ok
}

View File

@ -283,10 +283,14 @@ func TestMetaTable(t *testing.T) {
t.Run("add alias", func(t *testing.T) {
ts := ftso()
exists := mt.IsAlias("alias1")
assert.False(t, exists)
err = mt.AddAlias("alias1", "testColl", ts, ddOp)
assert.Nil(t, err)
aliases := mt.ListAliases(collID)
assert.Equal(t, aliases, []string{"alias1"})
exists = mt.IsAlias("alias1")
assert.True(t, exists)
})
t.Run("alter alias", func(t *testing.T) {

View File

@ -1866,14 +1866,29 @@ func TestRootCoord(t *testing.T) {
assert.Equal(t, commonpb.ErrorCode_Success, rsp.ErrorCode)
})
t.Run("drop alias", func(t *testing.T) {
req := &milvuspb.DropAliasRequest{
t.Run("drop collection with alias", func(t *testing.T) {
req := &milvuspb.DropCollectionRequest{
Base: &commonpb.MsgBase{
MsgType: commonpb.MsgType_DropAlias,
MsgID: 3016,
Timestamp: 3016,
SourceID: 3016,
},
CollectionName: aliasName,
}
rsp, err := core.DropCollection(ctx, req)
assert.Nil(t, err)
assert.NotEqual(t, commonpb.ErrorCode_Success, rsp.ErrorCode)
})
t.Run("drop alias", func(t *testing.T) {
req := &milvuspb.DropAliasRequest{
Base: &commonpb.MsgBase{
MsgType: commonpb.MsgType_DropAlias,
MsgID: 3017,
Timestamp: 3017,
SourceID: 3017,
},
Alias: aliasName,
}
rsp, err := core.DropAlias(ctx, req)
@ -1884,9 +1899,9 @@ func TestRootCoord(t *testing.T) {
status, err = core.DropCollection(ctx, &milvuspb.DropCollectionRequest{
Base: &commonpb.MsgBase{
MsgType: commonpb.MsgType_DropCollection,
MsgID: 3017,
Timestamp: 3017,
SourceID: 3017,
MsgID: 3018,
Timestamp: 3018,
SourceID: 3018,
},
DbName: dbName,
CollectionName: collName,
@ -1897,9 +1912,9 @@ func TestRootCoord(t *testing.T) {
status, err = core.DropCollection(ctx, &milvuspb.DropCollectionRequest{
Base: &commonpb.MsgBase{
MsgType: commonpb.MsgType_DropCollection,
MsgID: 3018,
Timestamp: 3018,
SourceID: 3018,
MsgID: 3019,
Timestamp: 3019,
SourceID: 3019,
},
DbName: dbName,
CollectionName: collName2,

View File

@ -247,6 +247,9 @@ func (t *DropCollectionReqTask) Execute(ctx context.Context) error {
if t.Type() != commonpb.MsgType_DropCollection {
return fmt.Errorf("drop collection, msg type = %s", commonpb.MsgType_name[int32(t.Type())])
}
if t.core.MetaTable.IsAlias(t.Req.CollectionName) {
return fmt.Errorf("cannot drop the collection via alias = %s", t.Req.CollectionName)
}
collMeta, err := t.core.MetaTable.GetCollectionByName(t.Req.CollectionName, 0)
if err != nil {

View File

@ -345,7 +345,11 @@ class TestAliasOperation(TestcaseBase):
check_items={exp_name: alias_name,
exp_schema: default_schema})
assert self.utility_wrap.has_collection(c_name)[0]
self.utility_wrap.drop_collection(alias_name)
error = {ct.err_code: 1, ct.err_msg: f"cannot drop the collection via alias = {alias_name}"}
self.utility_wrap.drop_collection(alias_name,
check_task=CheckTasks.err_res,
check_items=error)
self.utility_wrap.drop_collection(c_name)
assert not self.utility_wrap.has_collection(c_name)[0]
@pytest.mark.tags(CaseLabel.L1)