[SERVER-38746] Provide reason for transaction abort Created: 21/Dec/18  Updated: 29/Oct/23  Resolved: 15/Feb/19

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 4.0.7, 4.1.9

Type: Improvement Priority: Minor - P4
Reporter: Oleg Pudeyev (Inactive) Assignee: Tess Avitabile (Inactive)
Resolution: Fixed Votes: 0
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Related
related to RUBY-1625 POC : Convenient API for Transactions Closed
Backwards Compatibility: Fully Compatible
Backport Requested:
v4.0
Sprint: Repl 2019-02-25
Participants:

 Description   

While implementing convenient API for transactions spec, I ran into an unhelpful error from the server. The command sent was commitTransaction, and the result was "Transaction X has been aborted", as follows:

W, [2018-12-21T14:41:16.988684 #14570]  WARN -- : COMMAND | localhost:27741 | admin.commitTransaction | STARTED | {"commitTransaction"=>1, "$clusterTime"=>{"clusterTime"=>#<BSON::Timestamp:0x00005556c9b31440 @seconds=1545421260, @increment=4>, "signature"=>{"hash"=><BSON::Binary:0x46915619752340 type=generic data=0x0000000000000000...>, "keyId"=>0}}, "txnNumber"=>#<BSON::Int64:0x00005556c985afa0 @integer=2>, "lsid"=>{"id"=><BSON::Binary:0x46915619787740 type=uuid data=0xb2079f3024db4db8...>}, "autocommit"=>false, "writeConcern"=>{"w"=>2}}
W, [2018-12-21T14:41:16.989890 #14570]  WARN -- : COMMAND | localhost:27741 | admin.commitTransaction | FAILED | Transaction 2 has been aborted. (251) | 0.0011884130000000001s

In other words, the driver requested that a transaction be committed, and the server replied saying transaction was aborted, but did not say why.

Examining the code in the server which returned this string yielded the following:

void Session::_beginOrContinueTxn(WithLock wl,
...
            if (_txnState == MultiDocumentTransactionState::kInProgress && !_txnResourceStash) {
                // This indicates that the first command in the transaction failed but did not
                // implicitly abort the transaction. It is not safe to continue the transaction, in
                // particular because we have not saved the readConcern from the first statement of
                // the transaction.
                _abortTransaction(wl);
                uasserted(ErrorCodes::NoSuchTransaction,
                          str::stream() << "Transaction " << txnNumber << " has been aborted.");
            }

In other words, the server chose to abort the transaction when a commit was requested because a prior operation in the transaction failed.

The server should specify that this was the reason for transaction abort in the returned response, for instance the following message would be much more helpful:

Transaction 2 has been aborted because an earlier command in this transaction failed. (251)

Or, perhaps:

Aborting transaction 2 because an earlier command in this transaction failed. (251)



 Comments   
Comment by Githook User [ 22/Feb/19 ]

Author:

{'name': 'Tess Avitabile', 'username': 'tessavitabile', 'email': 'tess.avitabile@mongodb.com'}

Message: SERVER-38746 Improve error message when transaction aborts due to earlier command failure

(cherry picked from commit 6c28401a87f1a4a950b2b8cea6b58ef475fb7b4b)
Branch: v4.0
https://github.com/mongodb/mongo/commit/68093b9e483fd0fff66993e49c43b3d5f8b2a1e8

Comment by Githook User [ 15/Feb/19 ]

Author:

{'name': 'Tess Avitabile', 'email': 'tess.avitabile@mongodb.com', 'username': 'tessavitabile'}

Message: SERVER-38746 Improve error message when transaction aborts due to earlier command failure
Branch: master
https://github.com/mongodb/mongo/commit/6c28401a87f1a4a950b2b8cea6b58ef475fb7b4b

Comment by Oleg Pudeyev (Inactive) [ 22/Jan/19 ]

The change in error message that transaction is being aborted due to an earlier error is sufficient, without tracking the error code of the original error.

Generated at Thu Feb 08 04:49:53 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.