fix: [2.5] Add save field schema log for kv_catalog.AlterCollection (#41242) (#41308)

Cherry-pick from master
pr: #41242
Related to #41241

---------

Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
pull/41346/head
congqixia 2025-04-15 23:42:36 +08:00 committed by GitHub
parent 55b37c3bb6
commit f4c541e94a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 1 deletions

View File

@ -654,8 +654,21 @@ func (kc *Catalog) alterModifyCollection(ctx context.Context, oldColl *model.Col
return err
}
saves := map[string]string{newKey: string(value)}
// no default aliases will be created.
// save fields info to new path.
for _, field := range newColl.Fields {
k := BuildFieldKey(newColl.CollectionID, field.FieldID)
fieldInfo := model.MarshalFieldModel(field)
v, err := proto.Marshal(fieldInfo)
if err != nil {
return err
}
saves[k] = string(v)
}
if oldKey == newKey {
return kc.Snapshot.Save(ctx, newKey, string(value), ts)
return etcd.SaveByBatchWithLimit(saves, util.MaxEtcdTxnNum/2, func(partialKvs map[string]string) error {
return kc.Snapshot.MultiSave(ctx, partialKvs, ts)
})
}
return kc.Snapshot.MultiSaveAndRemove(ctx, saves, []string{oldKey}, ts)
}

View File

@ -1036,6 +1036,12 @@ func TestCatalog_AlterCollection(t *testing.T) {
kvs[key] = value
return nil
}
snapshot.MultiSaveFunc = func(ctx context.Context, saveKvs map[string]string, _ typeutil.Timestamp) error {
for k, v := range saveKvs {
kvs[k] = v
}
return nil
}
kc := NewCatalog(nil, snapshot).(*Catalog)
ctx := context.Background()
var collectionID int64 = 1