mirror of https://github.com/milvus-io/milvus.git
Cherry pick from master pr: #36981 Related to #36963 --------- Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>pull/37224/head
parent
79e6ef2617
commit
b44ef8207e
|
@ -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 {
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in New Issue