Skip to content

Commit 79f4e63

Browse files
committed
Enable retryable writes by default
GODRIVER-822 Change-Id: If65229bcea45fb79f1541b92f4015ba4e69cb9f9
1 parent 617a5bd commit 79f4e63

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+156
-427
lines changed

data/retryable-writes/README.rst

Lines changed: 5 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ the cluster.
2424
Server Fail Point
2525
=================
2626

27-
The tests depend on a server fail point, ``onPrimaryTransactionalWrite``, which
27+
Some tests depend on a server fail point, ``onPrimaryTransactionalWrite``, which
2828
allows us to force a network error before the server would return a write result
2929
to the client. The fail point also allows control whether the server will
3030
successfully commit the write via its ``failBeforeCommitExceptionCode`` option.
@@ -140,8 +140,8 @@ Each YAML file has the following keys:
140140

141141
- ``clientOptions``: Parameters to pass to MongoClient().
142142

143-
- ``failPoint``: The ``configureFailPoint`` command document to run to
144-
configure a fail point on the primary server. Drivers must ensure that
143+
- ``failPoint`` (optional): The ``configureFailPoint`` command document to run
144+
to configure a fail point on the primary server. Drivers must ensure that
145145
``configureFailPoint`` is the first field in the command.
146146

147147
- ``operation``: Document describing the operation to be executed. The
@@ -187,9 +187,9 @@ The YAML tests specify bulk write operations that are split by command type
187187
operations may also be split due to ``maxWriteBatchSize``,
188188
``maxBsonObjectSize``, or ``maxMessageSizeBytes``.
189189

190-
For instance, an insertMany operation with five 10 MB documents executed using
190+
For instance, an insertMany operation with five 10 MiB documents executed using
191191
OP_MSG payload type 0 (i.e. entire command in one document) would be split into
192-
five insert commands in order to respect the 16 MB ``maxBsonObjectSize`` limit.
192+
five insert commands in order to respect the 16 MiB ``maxBsonObjectSize`` limit.
193193
The same insertMany operation executed using OP_MSG payload type 1 (i.e. command
194194
arguments pulled out into a separate payload vector) would be split into two
195195
insert commands in order to respect the 48 MB ``maxMessageSizeBytes`` limit.
@@ -210,59 +210,6 @@ testing an update or delete that is split into two commands, the ``skip`` should
210210
be set to the number of statements in the first command to allow the fail point
211211
to trigger on the second command.
212212

213-
Replica Set Failover Test
214-
=========================
215-
216-
In addition to network errors, writes should also be retried in the event of a
217-
primary failover, which results in a "not master" command error (or similar).
218-
The ``stepdownHangBeforePerformingPostMemberStateUpdateActions`` fail point
219-
implemented in `d4eb562`_ for `SERVER-31355`_ may be used for this test, as it
220-
allows a primary to keep its client connections open after a step down. This
221-
fail point operates by hanging the step down procedure (i.e. ``replSetStepDown``
222-
command) until the fail point is later deactivated.
223-
224-
.. _d4eb562: https://github.com/mongodb/mongo/commit/d4eb562ac63717904f24de4a22e395070687bc62
225-
.. _SERVER-31355: https://jira.mongodb.org/browse/SERVER-31355
226-
227-
The following test requires three MongoClient instances and will generally
228-
require two execution contexts (async drivers may get by with a single thread).
229-
230-
- The client under test will connect to the replica set and be used to execute
231-
write operations.
232-
- The fail point client will connect directly to the initial primary and be used
233-
to toggle the fail point.
234-
- The step down client will connect to the replica set and be used to step down
235-
the primary. This client will generally require its own execution context,
236-
since the step down will hang.
237-
238-
In order to guarantee that the client under test does not detect the stepped
239-
down primary's state change via SDAM, it must be configured with a large
240-
`heartbeatFrequencyMS`_ value (e.g. 60 seconds). Single-threaded drivers may
241-
also need to set `serverSelectionTryOnce`_ to ``false`` to ensure that server
242-
selection for the retry attempt waits until a new primary is elected.
243-
244-
.. _heartbeatFrequencyMS: https://github.com/mongodb/specifications/blob/master/source/server-discovery-and-monitoring/server-discovery-and-monitoring.rst#heartbeatfrequencyms
245-
.. _serverSelectionTryOnce: https://github.com/mongodb/specifications/blob/master/source/server-selection/server-selection.rst#serverselectiontryonce
246-
247-
The test proceeds as follows:
248-
249-
- Using the client under test, insert a document and observe a successful write
250-
result. This will ensure that initial discovery takes place.
251-
- Using the fail point client, activate the fail point by setting ``mode``
252-
to ``"alwaysOn"``.
253-
- Using the step down client, step down the primary by executing the command
254-
``{ replSetStepDown: 60, force: true}``. This operation will hang so long as
255-
the fail point is activated. When the fail point is later deactivated, the
256-
step down will complete and the primary's client connections will be dropped.
257-
At that point, any ensuing network error should be ignored.
258-
- Using the client under test, insert a document and observe a successful write
259-
result. The test MUST assert that the insert command fails once against the
260-
stepped down node and is successfully retried on the newly elected primary
261-
(after SDAM discovers the topology change). The test MAY use APM or another
262-
means to observe both attempts.
263-
- Using the fail point client, deactivate the fail point by setting ``mode``
264-
to ``"off"``.
265-
266213
Command Construction Tests
267214
==========================
268215

data/retryable-writes/bulkWrite-serverErrors.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
"tests": [
1414
{
1515
"description": "BulkWrite succeeds after PrimarySteppedDown",
16-
"clientOptions": {
17-
"retryWrites": true
18-
},
1916
"failPoint": {
2017
"configureFailPoint": "failCommand",
2118
"mode": {
@@ -71,6 +68,7 @@
7168
"outcome": {
7269
"result": {
7370
"deletedCount": 1,
71+
"insertedCount": 1,
7472
"insertedIds": {
7573
"1": 3
7674
},
@@ -95,9 +93,6 @@
9593
},
9694
{
9795
"description": "BulkWrite succeeds after WriteConcernError ShutdownInProgress",
98-
"clientOptions": {
99-
"retryWrites": true
100-
},
10196
"failPoint": {
10297
"configureFailPoint": "failCommand",
10398
"mode": {
@@ -156,6 +151,7 @@
156151
"outcome": {
157152
"result": {
158153
"deletedCount": 1,
154+
"insertedCount": 1,
159155
"insertedIds": {
160156
"1": 3
161157
},

data/retryable-writes/bulkWrite-serverErrors.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ minServerVersion: '3.99'
88
tests:
99
-
1010
description: "BulkWrite succeeds after PrimarySteppedDown"
11-
clientOptions:
12-
retryWrites: true
1311
failPoint:
1412
configureFailPoint: failCommand
1513
mode: { times: 1 }
@@ -37,6 +35,7 @@ tests:
3735
outcome:
3836
result:
3937
deletedCount: 1
38+
insertedCount: 1
4039
insertedIds: { 1: 3 }
4140
matchedCount: 1
4241
modifiedCount: 1
@@ -48,8 +47,6 @@ tests:
4847
- { _id: 3, x: 33 }
4948
-
5049
description: "BulkWrite succeeds after WriteConcernError ShutdownInProgress"
51-
clientOptions:
52-
retryWrites: true
5350
failPoint:
5451
configureFailPoint: failCommand
5552
mode: { times: 1 }
@@ -79,6 +76,7 @@ tests:
7976
outcome:
8077
result:
8178
deletedCount: 1
79+
insertedCount: 1
8280
insertedIds: { 1: 3 }
8381
matchedCount: 1
8482
modifiedCount: 1

data/retryable-writes/bulkWrite.json

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
"tests": [
1010
{
1111
"description": "First command is retried",
12-
"clientOptions": {
13-
"retryWrites": true
14-
},
1512
"failPoint": {
1613
"configureFailPoint": "onPrimaryTransactionalWrite",
1714
"mode": {
@@ -61,6 +58,7 @@
6158
"outcome": {
6259
"result": {
6360
"deletedCount": 1,
61+
"insertedCount": 1,
6462
"insertedIds": {
6563
"0": 2
6664
},
@@ -81,9 +79,6 @@
8179
},
8280
{
8381
"description": "All commands are retried",
84-
"clientOptions": {
85-
"retryWrites": true
86-
},
8782
"failPoint": {
8883
"configureFailPoint": "onPrimaryTransactionalWrite",
8984
"mode": {
@@ -178,6 +173,7 @@
178173
"outcome": {
179174
"result": {
180175
"deletedCount": 1,
176+
"insertedCount": 3,
181177
"insertedIds": {
182178
"0": 2,
183179
"2": 3,
@@ -214,9 +210,6 @@
214210
},
215211
{
216212
"description": "Both commands are retried after their first statement fails",
217-
"clientOptions": {
218-
"retryWrites": true
219-
},
220213
"failPoint": {
221214
"configureFailPoint": "onPrimaryTransactionalWrite",
222215
"mode": {
@@ -271,6 +264,7 @@
271264
"outcome": {
272265
"result": {
273266
"deletedCount": 0,
267+
"insertedCount": 1,
274268
"insertedIds": {
275269
"0": 2
276270
},
@@ -295,9 +289,6 @@
295289
},
296290
{
297291
"description": "Second command is retried after its second statement fails",
298-
"clientOptions": {
299-
"retryWrites": true
300-
},
301292
"failPoint": {
302293
"configureFailPoint": "onPrimaryTransactionalWrite",
303294
"mode": {
@@ -352,6 +343,7 @@
352343
"outcome": {
353344
"result": {
354345
"deletedCount": 0,
346+
"insertedCount": 1,
355347
"insertedIds": {
356348
"0": 2
357349
},
@@ -376,9 +368,6 @@
376368
},
377369
{
378370
"description": "BulkWrite with unordered execution",
379-
"clientOptions": {
380-
"retryWrites": true
381-
},
382371
"failPoint": {
383372
"configureFailPoint": "onPrimaryTransactionalWrite",
384373
"mode": {
@@ -416,6 +405,7 @@
416405
"outcome": {
417406
"result": {
418407
"deletedCount": 0,
408+
"insertedCount": 2,
419409
"insertedIds": {
420410
"0": 2,
421411
"1": 3
@@ -445,9 +435,6 @@
445435
},
446436
{
447437
"description": "First insertOne is never committed",
448-
"clientOptions": {
449-
"retryWrites": true
450-
},
451438
"failPoint": {
452439
"configureFailPoint": "onPrimaryTransactionalWrite",
453440
"mode": {
@@ -501,6 +488,7 @@
501488
"error": true,
502489
"result": {
503490
"deletedCount": 0,
491+
"insertedCount": 0,
504492
"insertedIds": {},
505493
"matchedCount": 0,
506494
"modifiedCount": 0,
@@ -519,9 +507,6 @@
519507
},
520508
{
521509
"description": "Second updateOne is never committed",
522-
"clientOptions": {
523-
"retryWrites": true
524-
},
525510
"failPoint": {
526511
"configureFailPoint": "onPrimaryTransactionalWrite",
527512
"mode": {
@@ -575,6 +560,7 @@
575560
"error": true,
576561
"result": {
577562
"deletedCount": 0,
563+
"insertedCount": 1,
578564
"insertedIds": {
579565
"0": 2
580566
},
@@ -599,9 +585,6 @@
599585
},
600586
{
601587
"description": "Third updateOne is never committed",
602-
"clientOptions": {
603-
"retryWrites": true
604-
},
605588
"failPoint": {
606589
"configureFailPoint": "onPrimaryTransactionalWrite",
607590
"mode": {
@@ -660,6 +643,7 @@
660643
"error": true,
661644
"result": {
662645
"deletedCount": 0,
646+
"insertedCount": 1,
663647
"insertedIds": {
664648
"1": 2
665649
},
@@ -684,9 +668,6 @@
684668
},
685669
{
686670
"description": "Single-document write following deleteMany is retried",
687-
"clientOptions": {
688-
"retryWrites": true
689-
},
690671
"failPoint": {
691672
"configureFailPoint": "onPrimaryTransactionalWrite",
692673
"mode": {
@@ -726,6 +707,7 @@
726707
"outcome": {
727708
"result": {
728709
"deletedCount": 1,
710+
"insertedCount": 1,
729711
"insertedIds": {
730712
"1": 2
731713
},
@@ -746,9 +728,6 @@
746728
},
747729
{
748730
"description": "Single-document write following updateMany is retried",
749-
"clientOptions": {
750-
"retryWrites": true
751-
},
752731
"failPoint": {
753732
"configureFailPoint": "onPrimaryTransactionalWrite",
754733
"mode": {
@@ -793,6 +772,7 @@
793772
"outcome": {
794773
"result": {
795774
"deletedCount": 0,
775+
"insertedCount": 1,
796776
"insertedIds": {
797777
"1": 2
798778
},

0 commit comments

Comments
 (0)