fix: etcd txn exceeds limit due to too many fields (#33040) (#33049)

fix: #33038
pr: #33040 

---------

Signed-off-by: longjiquan <jiquan.long@zilliz.com>
pull/33119/head
Jiquan Long 2024-05-15 10:07:34 +08:00 committed by GitHub
parent bfd88670ef
commit 0abc0d05a4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 2 deletions

View File

@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"sort"
"github.com/cockroachdb/errors"
"github.com/golang/protobuf/proto"
@ -94,6 +95,12 @@ func batchMultiSaveAndRemoveWithPrefix(snapshot kv.SnapShotKV, maxTxnNum int, sa
return err
}
// avoid a case that the former key is the prefix of the later key.
// for example, `root-coord/fields/collection_id/1` is the prefix of `root-coord/fields/collection_id/100`.
sort.Slice(removals, func(i, j int) bool {
return removals[i] > removals[j]
})
removeFn := func(partialKeys []string) error {
return snapshot.MultiSaveAndRemoveWithPrefix(nil, partialKeys, ts)
}

View File

@ -521,14 +521,17 @@ func (ss *SuffixSnapshot) MultiSaveAndRemoveWithPrefix(saves map[string]string,
// load each removal, change execution to adding tombstones
for _, removal := range removals {
keys, _, err := ss.MetaKv.LoadWithPrefix(removal)
keys, values, err := ss.MetaKv.LoadWithPrefix(removal)
if err != nil {
log.Warn("SuffixSnapshot MetaKv LoadwithPrefix failed", zap.String("key", removal), zap.Error(err))
return err
}
// add tombstone to original key and add ts entry
for _, key := range keys {
for idx, key := range keys {
if IsTombstone(values[idx]) {
continue
}
key = ss.hideRootPrefix(key)
execute[key] = string(SuffixSnapshotTombstone)
execute[ss.composeTSKey(key, ts)] = string(SuffixSnapshotTombstone)