Skip to content

Commit 604cf63

Browse files
authored
perf(txn): de-duplicate the context keys and predicates (#7478)
The zero raft loop got stuck because the proposals took a long time to process. Hence, the goroutine which checks the quorum gets struck leading to leadership change (even in single zero single alpha). The real issue was the Keys in txnContext. While merging the conflict keys, deduplication was not done. Do deduplication before sending the request to zero.
1 parent 08d1bf0 commit 604cf63

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

dgraph/cmd/zero/oracle.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -367,12 +367,7 @@ func (s *Server) commit(ctx context.Context, src *api.TxnContext) error {
367367

368368
checkPreds := func() error {
369369
// Check if any of these tablets is being moved. If so, abort the transaction.
370-
preds := make(map[string]struct{})
371-
372-
for _, k := range src.Preds {
373-
preds[k] = struct{}{}
374-
}
375-
for pkey := range preds {
370+
for _, pkey := range src.Preds {
376371
splits := strings.Split(pkey, "-")
377372
if len(splits) < 2 {
378373
return errors.Errorf("Unable to find group id in %s", pkey)

worker/mutation.go

+5
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,11 @@ func CommitOverNetwork(ctx context.Context, tc *api.TxnContext) (uint64, error)
820820
if pl == nil {
821821
return 0, conn.ErrNoConnection
822822
}
823+
824+
// Do de-duplication before sending the request to zero.
825+
tc.Keys = x.Unique(tc.Keys)
826+
tc.Preds = x.Unique(tc.Preds)
827+
823828
zc := pb.NewZeroClient(pl.Get())
824829
tctx, err := zc.CommitOrAbort(ctx, tc)
825830

0 commit comments

Comments
 (0)