Skip to content

Commit

Permalink
perf(txn): de-duplicate the context keys and predicates (#7478)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
NamanJain8 authored Mar 4, 2021
1 parent 08d1bf0 commit 604cf63
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
7 changes: 1 addition & 6 deletions dgraph/cmd/zero/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,12 +367,7 @@ func (s *Server) commit(ctx context.Context, src *api.TxnContext) error {

checkPreds := func() error {
// Check if any of these tablets is being moved. If so, abort the transaction.
preds := make(map[string]struct{})

for _, k := range src.Preds {
preds[k] = struct{}{}
}
for pkey := range preds {
for _, pkey := range src.Preds {
splits := strings.Split(pkey, "-")
if len(splits) < 2 {
return errors.Errorf("Unable to find group id in %s", pkey)
Expand Down
5 changes: 5 additions & 0 deletions worker/mutation.go
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,11 @@ func CommitOverNetwork(ctx context.Context, tc *api.TxnContext) (uint64, error)
if pl == nil {
return 0, conn.ErrNoConnection
}

// Do de-duplication before sending the request to zero.
tc.Keys = x.Unique(tc.Keys)
tc.Preds = x.Unique(tc.Preds)

zc := pb.NewZeroClient(pl.Get())
tctx, err := zc.CommitOrAbort(ctx, tc)

Expand Down

0 comments on commit 604cf63

Please sign in to comment.