mirror of
https://gitee.com/milvus-io/milvus.git
synced 2026-01-07 19:31:51 +08:00
fix: Call AlterCollection when only rename collection (#43420)
issue: #43407 Signed-off-by: Cai Zhang <cai.zhang@zilliz.com>
This commit is contained in:
parent
42ad786f75
commit
2adc6ce0bc
@ -932,9 +932,16 @@ func (mt *MetaTable) RenameCollection(ctx context.Context, dbName string, oldNam
|
||||
newColl.Name = newName
|
||||
newColl.DBName = dbName
|
||||
newColl.DBID = targetDB.ID
|
||||
if err := mt.catalog.AlterCollectionDB(ctx, oldColl, newColl, ts); err != nil {
|
||||
log.Warn("alter collectionDB by catalog failed", zap.Error(err))
|
||||
return err
|
||||
if oldColl.DBID == newColl.DBID {
|
||||
if err := mt.catalog.AlterCollection(ctx, oldColl, newColl, metastore.MODIFY, ts, false); err != nil {
|
||||
log.Warn("alter collection by catalog failed", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if err := mt.catalog.AlterCollectionDB(ctx, oldColl, newColl, ts); err != nil {
|
||||
log.Warn("alter collectionDB by catalog failed", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
mt.names.insert(newDBName, newName, oldColl.CollectionID)
|
||||
|
||||
@ -1693,6 +1693,50 @@ func TestMetaTable_RenameCollection(t *testing.T) {
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, "new", coll.Name)
|
||||
})
|
||||
|
||||
t.Run("rename collection ok", func(t *testing.T) {
|
||||
catalog := mocks.NewRootCoordCatalog(t)
|
||||
catalog.On("AlterCollection",
|
||||
mock.Anything,
|
||||
mock.Anything,
|
||||
mock.Anything,
|
||||
mock.Anything,
|
||||
mock.Anything,
|
||||
mock.Anything,
|
||||
).Return(nil)
|
||||
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(nil),
|
||||
},
|
||||
catalog: catalog,
|
||||
names: newNameDb(),
|
||||
aliases: newNameDb(),
|
||||
collID2Meta: map[typeutil.UniqueID]*model.Collection{
|
||||
1: {
|
||||
CollectionID: 1,
|
||||
DBID: 1,
|
||||
Name: "old",
|
||||
},
|
||||
},
|
||||
}
|
||||
meta.names.insert(util.DefaultDBName, "old", 1)
|
||||
err := meta.RenameCollection(context.TODO(), util.DefaultDBName, "old", util.DefaultDBName, "new", 1000)
|
||||
assert.NoError(t, err)
|
||||
|
||||
id, ok := meta.names.get(util.DefaultDBName, "new")
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, int64(1), id)
|
||||
|
||||
coll, ok := meta.collID2Meta[1]
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, "new", coll.Name)
|
||||
})
|
||||
}
|
||||
|
||||
func TestMetaTable_ChangePartitionState(t *testing.T) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user