MCPcopy Create free account
hub / github.com/dgraph-io/dgraph / CommitOrAbort

Method CommitOrAbort

dgraph/cmd/zero/oracle.go:421–436  ·  view source on GitHub ↗

CommitOrAbort either commits a transaction or aborts it. The abortion can happen under the following conditions 1) the api.TxnContext.Aborted flag is set in the src argument 2) if there's an error (e.g server is not the leader or there's a conflicting transaction)

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

Source from the content-addressed store, hash-verified

419// 1) the api.TxnContext.Aborted flag is set in the src argument
420// 2) if there's an error (e.g server is not the leader or there's a conflicting transaction)
421func (s *Server) CommitOrAbort(ctx context.Context, src *api.TxnContext) (*api.TxnContext, error) {
422 if ctx.Err() != nil {
423 return nil, ctx.Err()
424 }
425 ctx, span := otel.Tracer("").Start(ctx, "Zero.CommitOrAbort")
426 defer span.End()
427
428 if !s.Node.AmLeader() {
429 return nil, errors.Errorf("Only leader can decide to commit or abort")
430 }
431 err := s.commit(ctx, src)
432 if err != nil {
433 span.SetAttributes(attribute.Bool("error", true))
434 }
435 return src, err
436}
437
438var errClosed = errors.New("Streaming closed by oracle")
439var errNotLeader = errors.New("Node is no longer leader")

Callers

nothing calls this directly

Calls 4

commitMethod · 0.95
StartMethod · 0.65
AmLeaderMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected