Skip to content

DOCSP-35201 Transaction Retry Logic in Core API #1164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 36 additions & 16 deletions source/crud/transactions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -304,19 +304,39 @@ the ``startTransaction()`` method:
Transaction Errors
------------------

If you are using the Core API to perform a transaction, you must incorporate
error-handling logic into your application for the following errors:

- ``TransientTransactionError``: Raised if a write operation errors
before the driver commits the transaction. To learn more about this error, see the
:manual:`TransientTransactionError description
</core/transactions-in-applications/#transienttransactionerror>` on
the Driver API page in the Server manual.
- ``UnknownTransactionCommitResult``: Raised if the commit operation
encounters an error. To learn more about this error, see the
:manual:`UnknownTransactionCommitResult description
</core/transactions-in-applications/#unknowntransactioncommitresult>` on
the Driver API page in the Server manual.

The Convenient Transaction API incorporates retry logic for these error
types, so the driver retries the transaction until there is a successful commit.
Since MongoDB transactions are :website:`ACID compliant
</basics/acid-transactions>`, the driver may produce errors during operation to
ensure your data maintains consistent. If the following errors occur, the
transaction must be retried:

- ``TransientTransactionError``: Raised if a write operation encounters an error
before the driver commits the transaction. To learn more about this error
type, see the :manual:`TransientTransactionError
description </core/transactions-in-applications/#transienttransactionerror>` on
the Drivers API page in the Server manual.
- ``UnknownTransactionCommitResult``: Raised if the commit operation encounters
an error. To learn more about this error type, see the
:manual:`UnknownTransactionCommitResult
description </core/transactions-in-applications/#unknowntransactioncommitresult>`
on the Drivers API page in the Server manual.

The Convenient Transaction API incorporates retry logic for these error types,
so the driver automatically retries the transaction until there is a successful
commit.

Core API Error Handling
~~~~~~~~~~~~~~~~~~~~~~~

If you are using the Core API to perform a transaction, you must implement the
error-handling logic into your application. To do so, you must create the
following functions:

- A function that retries the entire transaction when the driver encounters a
``TransientTransactionError``
- A function that retries the commit operation when the driver encounters an
``UnknownTransactionCommitResult``

These functions must run until there is a successful commit or a different
error. For an example of this retry logic, see the :manual:`Core API section
</core/transactions-in-applications/#core-api>` on the Drivers API page in the
Server manual.
Loading