Skip to content

Commit

Permalink
fix: [2.4] Check whether new collection name is alias (milvus-io#36981)…
Browse files Browse the repository at this point in the history
… (milvus-io#37208)

Cherry pick from master
pr: milvus-io#36981

Related to milvus-io#36963

---------

Signed-off-by: Congqi Xia <[email protected]>
  • Loading branch information
congqixia authored Oct 28, 2024
1 parent 79e6ef2 commit b44ef82
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/rootcoord/meta_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,12 @@ func (mt *MetaTable) RenameCollection(ctx context.Context, dbName string, oldNam
return fmt.Errorf("unsupported use an alias to rename collection, alias:%s", oldName)
}

_, ok = mt.aliases.get(newDBName, newName)
if ok {
log.Warn("cannot rename collection to an existing alias")
return fmt.Errorf("cannot rename collection to an existing alias: %s", newName)
}

// check new collection already exists
newColl, err := mt.getCollectionByNameInternal(ctx, newDBName, newName, ts)
if newColl != nil {
Expand Down
30 changes: 30 additions & 0 deletions internal/rootcoord/meta_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1582,6 +1582,36 @@ func TestMetaTable_RenameCollection(t *testing.T) {
assert.Error(t, err)
})

t.Run("rename db name fails if aliases exists", func(t *testing.T) {
catalog := mocks.NewRootCoordCatalog(t)
catalog.On("GetCollectionByName",
mock.Anything,
mock.Anything,
mock.Anything,
mock.Anything,
).Return(nil, merr.WrapErrCollectionNotFound("error"))
meta := &MetaTable{
dbName2Meta: map[string]*model.Database{
util.DefaultDBName: model.NewDefaultDatabase(),
"db1": model.NewDatabase(2, "db1", pb.DatabaseState_DatabaseCreated, nil),
},
catalog: catalog,
names: newNameDb(),
aliases: newNameDb(),
collID2Meta: map[typeutil.UniqueID]*model.Collection{
1: {
CollectionID: 1,
Name: "old",
},
},
}
meta.names.insert(util.DefaultDBName, "old", 1)
meta.aliases.insert(util.DefaultDBName, "new", 1)

err := meta.RenameCollection(context.TODO(), util.DefaultDBName, "old", "db1", "new", 1000)
assert.Error(t, err)
})

t.Run("alter collection ok", func(t *testing.T) {
catalog := mocks.NewRootCoordCatalog(t)
catalog.On("AlterCollection",
Expand Down

0 comments on commit b44ef82

Please sign in to comment.