Skip to content

Commit

Permalink
fix: etcd txn exceeds limit due to too many fields (#33040) (#33049)
Browse files Browse the repository at this point in the history
fix: #33038
pr: #33040 

---------

Signed-off-by: longjiquan <jiquan.long@zilliz.com>
  • Loading branch information
longjiquan committed May 15, 2024
1 parent bfd8867 commit 0abc0d0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 7 additions & 0 deletions internal/metastore/kv/rootcoord/kv_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"sort"

"github.com/cockroachdb/errors"
"github.com/golang/protobuf/proto"
Expand Down Expand Up @@ -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)
}
Expand Down
7 changes: 5 additions & 2 deletions internal/metastore/kv/rootcoord/suffix_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0abc0d0

Please sign in to comment.