CommitOverNetwork makes a proxy call to Zero to commit or abort a transaction.
(ctx context.Context, tc *api.TxnContext)
| 885 | |
| 886 | // CommitOverNetwork makes a proxy call to Zero to commit or abort a transaction. |
| 887 | func 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 | |
| 930 | func (w *grpcWorker) proposeAndWait(ctx context.Context, txnCtx *api.TxnContext, |
| 931 | m *pb.Mutations) error { |
no test coverage detected