|
| __construct (callable $callback, array $transactionOptions=[]) |
|
| execute (Session $session) |
| Execute the operation in the given session.
|
|
◆ __construct()
MongoDB\Operation\WithTransaction::__construct |
( |
callable | $callback, |
|
|
array | $transactionOptions = [] ) |
- See also
- Session\startTransaction for supported transaction options
- Parameters
-
callable | $callback | A callback that will be invoked within the transaction |
array | $transactionOptions | Additional options that are passed to Session\startTransaction |
◆ execute()
MongoDB\Operation\WithTransaction::execute |
( |
Session | $session | ) |
|
Execute the operation in the given session.
This helper takes care of retrying the commit operation or the entire transaction if an error occurs.
If the commit fails because of an UnknownTransactionCommitResult error, the commit is retried without re-invoking the callback. If the commit fails because of a TransientTransactionError, the entire transaction will be retried. In this case, the callback will be invoked again. It is important that the logic inside the callback is idempotent.
In case of failures, the commit or transaction are retried until 120 seconds from the initial call have elapsed. After that, no retries will happen and the helper will throw the last exception received from the driver.
- See also
- Client\startSession
- Parameters
-
Session | $session | A session object as retrieved by Client\startSession |
- Exceptions
-
RuntimeException | for driver errors while committing the transaction |
Exception | for any other errors, including those thrown in the callback |
The documentation for this class was generated from the following file:
- cache/stores/mongodb/MongoDB/Operation/WithTransaction.php