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)
| 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) |
| 421 | func (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 | |
| 438 | var errClosed = errors.New("Streaming closed by oracle") |
| 439 | var errNotLeader = errors.New("Node is no longer leader") |