MCPcopy
hub / github.com/dgraph-io/dgraph / CommitOverNetwork

Function CommitOverNetwork

worker/mutation.go:887–928  ·  view source on GitHub ↗

CommitOverNetwork makes a proxy call to Zero to commit or abort a transaction.

(ctx context.Context, tc *api.TxnContext)

Source from the content-addressed store, hash-verified

885
886// CommitOverNetwork makes a proxy call to Zero to commit or abort a transaction.
887func CommitOverNetwork(ctx context.Context, tc *api.TxnContext) (uint64, error) {
888 ctx, span := otel.Tracer("").Start(ctx, "worker.CommitOverNetwork")
889 defer span.End()
890
891 clientDiscard := false
892 if tc.Aborted {
893 // The client called Discard
894 ostats.Record(ctx, x.TxnDiscards.M(1))
895 clientDiscard = true
896 }
897
898 pl := groups().Leader(0)
899 if pl == nil {
900 return 0, conn.ErrNoConnection
901 }
902
903 // Do de-duplication before sending the request to zero.
904 tc.Keys = x.Unique(tc.Keys)
905 tc.Preds = x.Unique(tc.Preds)
906
907 zc := pb.NewZeroClient(pl.Get())
908 tctx, err := zc.CommitOrAbort(ctx, tc)
909
910 if err != nil {
911 span.AddEvent("Error in CommitOrAbort", trace.WithAttributes(
912 attribute.String("error", err.Error())))
913 return 0, err
914 }
915 span.AddEvent("Commit status", trace.WithAttributes(
916 attribute.Int64("commitTs", int64(tctx.CommitTs)),
917 attribute.Bool("committed", tctx.CommitTs > 0)))
918
919 if tctx.Aborted || tctx.CommitTs == 0 {
920 if !clientDiscard {
921 // The server aborted the txn (not the client)
922 ostats.Record(ctx, x.TxnAborts.M(1))
923 }
924 return 0, dgo.ErrAborted
925 }
926 ostats.Record(ctx, x.TxnCommits.M(1))
927 return tctx.CommitTs, nil
928}
929
930func (w *grpcWorker) proposeAndWait(ctx context.Context, txnCtx *api.TxnContext,
931 m *pb.Mutations) error {

Callers 3

doMutateMethod · 0.92
CommitOrAbortMethod · 0.92
UpdateGraphQLSchemaMethod · 0.85

Calls 10

CommitOrAbortMethod · 0.95
UniqueFunction · 0.92
NewZeroClientFunction · 0.92
groupsFunction · 0.85
RecordMethod · 0.80
StartMethod · 0.65
GetMethod · 0.65
LeaderMethod · 0.45
StringMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected