Skip to content

Commit c91d9b1

Browse files
committed
DOCSP-34822: commitTxn is idempotent (#337)
* DOCSP-34822: commitTxn is idempotent * vale fixes * Server clarification * JS PR fix * language (cherry picked from commit 40d675e)
1 parent d15a255 commit c91d9b1

File tree

2 files changed

+45
-29
lines changed

2 files changed

+45
-29
lines changed

source/fundamentals/crud/write-operations/insert.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ to set with ``InsertManyOptions`` are:
195195

196196
* - ``Ordered``
197197
- | If ``true``, the driver sends documents to the server in the order provided.
198-
If an error occurs, the driver and server abort all remaining insert operations.
198+
If an error occurs, the driver and server end all remaining insert operations.
199199
To learn more, see :ref:`golang-ordered-behavior`.
200200

201201
| Default: ``false``

source/fundamentals/transactions.txt

Lines changed: 44 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,24 @@ Transactions
2020
Overview
2121
--------
2222

23-
In this guide, you can learn how to use **transactions** with the
24-
{+driver-long+}. :manual:`Transactions </core/transactions/>` allow you
25-
to run a series of operations that do not change any data until the
26-
transaction is committed. If any operation in the transaction fails, the
27-
driver cancels the transaction and discards all data changes before they
28-
ever become visible.
23+
In this guide, you can learn how to use the {+driver-long+} to perform
24+
**transactions**. :manual:`Transactions </core/transactions/>` allow
25+
you to run a series of operations that do not change any data until the
26+
transaction is committed. If any operation in the transaction returns an
27+
error, the driver cancels the transaction and discards all data changes
28+
before they ever become visible.
2929

3030
In MongoDB, transactions run within logical **sessions**. A
31-
:manual:`session </reference/server-sessions/>` is a
32-
grouping of related read or write operations that you intend to run
33-
sequentially. Sessions enable :manual:`causal consistency </core/read-isolation-consistency-recency/#causal-consistency>`
34-
for a group of operations or allow you to execute operations in an :website:`ACID
35-
transaction </basics/acid-transactions>`. MongoDB guarantees that the data
36-
involved in your transaction operations remains consistent, even if the operations
37-
encounter unexpected errors.
38-
39-
With the {+driver-short+}, you can create a new session from a
31+
:manual:`session </reference/server-sessions/>` is a grouping of related
32+
read or write operations that you intend to run sequentially. Sessions
33+
enable :manual:`causal consistency
34+
</core/read-isolation-consistency-recency/#causal-consistency>` for a
35+
group of operations or allow you to execute operations in an
36+
:website:`ACID transaction </basics/acid-transactions>`. MongoDB
37+
guarantees that the data involved in your transaction operations remains
38+
consistent, even if the operations encounter unexpected errors.
39+
40+
When using the {+driver-short+}, you can create a new session from a
4041
``Client`` instance as a ``Session`` type. We recommend that you reuse
4142
your client for multiple sessions and transactions instead of
4243
instantiating a new client each time.
@@ -45,7 +46,7 @@ instantiating a new client each time.
4546

4647
Use a ``Session`` only with the ``Client`` (or associated
4748
``Database`` or ``Collection``) that created it. Using a
48-
``Session`` with a different ``Client`` will result in operation
49+
``Session`` with a different ``Client`` results in operation
4950
errors.
5051

5152
.. warning::
@@ -56,8 +57,8 @@ instantiating a new client each time.
5657
Methods
5758
-------
5859

59-
After you start a session using the ``StartSession()`` method, you can modify
60-
the session state using the method set provided by the ``Session`` interface. The
60+
After you start a session by using the ``StartSession()`` method, you can modify
61+
the session state by using the method set provided by the ``Session`` interface. The
6162
following table describes these methods:
6263

6364
.. list-table::
@@ -70,26 +71,41 @@ following table describes these methods:
7071
* - ``StartTransaction()``
7172
- | Starts a new transaction, configured with the given options, on
7273
this session. Returns an error if there is already
73-
a transaction in progress for the session. For more
74-
information, see the :manual:`manual entry </reference/method/Session.startTransaction/>`.
74+
a transaction in progress for the session. To learn more about
75+
this method, see the :manual:`startTransaction() page
76+
</reference/method/Session.startTransaction/>` in the Server manual.
7577
|
7678
| **Parameter**: ``TransactionOptions``
7779
| **Return Type**: ``error``
7880

7981
* - ``AbortTransaction()``
80-
- | Aborts the active transaction for this session. Returns an
82+
- | Ends the active transaction for this session. Returns an
8183
error if there is no active transaction for the session or the
82-
transaction has been committed or aborted. For more
83-
information, see the :manual:`manual entry </reference/method/Session.abortTransaction/>`.
84+
transaction has been committed or ended. To learn more about
85+
this method, see the :manual:`abortTransaction() page
86+
</reference/method/Session.abortTransaction/>` in the Server manual.
8487
|
8588
| **Parameter**: ``Context``
8689
| **Return Type**: ``error``
8790

8891
* - ``CommitTransaction()``
8992
- | Commits the active transaction for this session. Returns an
90-
error if there is no active transaction for the session or the
91-
transaction has been aborted. For more
92-
information, see the :manual:`manual entry </reference/method/Session.commitTransaction/>`.
93+
error if there is no active transaction for the session or if the
94+
transaction was ended. To learn more about
95+
this method, see the :manual:`commitTransaction() page
96+
</reference/method/Session.commitTransaction/>` in the Server manual.
97+
98+
.. note:: Retrying a Transaction
99+
100+
The ``CommitTransaction()`` method is an idempotent function, which
101+
means that you can attempt to commit a transaction multiple times
102+
without changing data after the first successful commit.
103+
104+
A transaction can succeed but return an error with the
105+
``UnknownTransactionCommitResult`` label. If you rerun the
106+
``CommitTransaction()`` method after receiving this error,
107+
your data is not changed by the repeat attempts.
108+
93109
|
94110
| **Parameter**: ``Context``
95111
| **Return Type**: ``error``
@@ -102,7 +118,7 @@ following table describes these methods:
102118
| **Return Type**: ``interface{}``, ``error``
103119

104120
* - ``EndSession()``
105-
- | Aborts any existing transactions and closes the session.
121+
- | Ends any existing transactions and closes the session.
106122
|
107123
| **Parameter**: ``Context``
108124
| **Return Type**: none
@@ -133,7 +149,7 @@ following steps:
133149
:end-before: end-session
134150

135151
If you require more control over your transactions, you can find an example
136-
showing how to manually create, commit, and abort transactions in the
152+
showing how to manually create, commit, and end transactions in the
137153
`full code example <https://raw.githubusercontent.com/mongodb/docs-golang/{+docs-branch+}/source/includes/fundamentals/code-snippets/transaction.go>`__.
138154

139155
Additional Information

0 commit comments

Comments
 (0)