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

Method CommitOrAbort

edgraph/server.go:2108–2145  ·  view source on GitHub ↗

CommitOrAbort commits or aborts a transaction.

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

Source from the content-addressed store, hash-verified

2106
2107// CommitOrAbort commits or aborts a transaction.
2108func (s *Server) CommitOrAbort(ctx context.Context, tc *api.TxnContext) (*api.TxnContext, error) {
2109 ctx, span := otel.Tracer("").Start(ctx, "Server.CommitOrAbort")
2110 defer span.End()
2111
2112 if err := x.HealthCheck(); err != nil {
2113 return &api.TxnContext{}, err
2114 }
2115
2116 tctx := &api.TxnContext{}
2117 if tc.StartTs == 0 {
2118 return &api.TxnContext{}, errors.Errorf(
2119 "StartTs cannot be zero while committing a transaction")
2120 }
2121 if ns, err := x.ExtractNamespaceFrom(ctx); err == nil {
2122 annotateNamespace(span, ns)
2123 }
2124 annotateStartTs(span, tc.StartTs)
2125
2126 if err := validateNamespace(ctx, tc); err != nil {
2127 return &api.TxnContext{}, err
2128 }
2129
2130 span.AddEvent("Txn Context received", trace.WithAttributes(attribute.Stringer("txn", tc)))
2131 commitTs, err := worker.CommitOverNetwork(ctx, tc)
2132 if err == dgo.ErrAborted {
2133 // If err returned is dgo.ErrAborted and tc.Aborted was set, that means the client has
2134 // aborted the transaction by calling txn.Discard(). Hence return a nil error.
2135 tctx.Aborted = true
2136 if tc.Aborted {
2137 return tctx, nil
2138 }
2139
2140 return tctx, status.Error(codes.Aborted, err.Error())
2141 }
2142 tctx.StartTs = tc.StartTs
2143 tctx.CommitTs = commitTs
2144 return tctx, err
2145}
2146
2147// CheckVersion returns the version of this Dgraph instance.
2148func (s *Server) CheckVersion(ctx context.Context, c *api.Check) (v *api.Version, err error) {

Callers

nothing calls this directly

Calls 9

HealthCheckFunction · 0.92
ExtractNamespaceFromFunction · 0.92
CommitOverNetworkFunction · 0.92
annotateNamespaceFunction · 0.85
annotateStartTsFunction · 0.85
validateNamespaceFunction · 0.85
StartMethod · 0.65
ErrorfMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected