Skip to content

Commit e4a5564

Browse files
DRIVERS-2327 NoWritesPerformed Retryable Writes Error Handling (#1297)
1 parent eaec267 commit e4a5564

File tree

2 files changed

+68
-3
lines changed

2 files changed

+68
-3
lines changed

source/retryable-writes/retryable-writes.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ Retryable Writes
33
================
44

55
:Spec Title: Retryable Writes
6-
:Spec Version: 1.8.0
6+
:Spec Version: 1.8.1
77
:Author: Jeremy Mikola
88
:Lead: \A. Jesse Jiryu Davis
99
:Advisors: Robert Stam, Esha Maharishi, Samantha Ritter, and Kaloian Manassiev
1010
:Status: Accepted
1111
:Type: Standards
1212
:Minimum Server Version: 3.6
13-
:Last Modified: 2022-01-25
13+
:Last Modified: 2022-08-30
1414

1515
.. contents::
1616

@@ -409,6 +409,9 @@ error should be raised instead as the caller can infer that an attempt was made
409409
and the second error is likely more relevant (with respect to the current
410410
topology state).
411411

412+
If a retry attempt fails with an error labeled NoWritesPerformed, drivers MUST
413+
return the original error.
414+
412415
Drivers MUST NOT attempt to retry a write command with the same transaction ID
413416
more than once.
414417

source/retryable-writes/tests/README.rst

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ and sharded clusters.
353353
retryWrites=false to your connection string.
354354

355355
and the error code is 20.
356-
356+
357357
**Note**: Drivers that rely on ``serverStatus`` to determine the storage engine
358358
in use MAY skip this test for sharded clusters, since ``mongos`` does not report
359359
this information in its ``serverStatus`` response.
@@ -395,10 +395,72 @@ and sharded clusters.
395395

396396
9. Disable the failpoint.
397397

398+
#. Test that drivers return the original error after encountering a
399+
WriteConcernError with a RetryableWriteError label. This test MUST
400+
401+
1. be implemented by any driver that implements the Command Monitoring
402+
specification,
403+
404+
2. only run against replica sets as mongos does not propagate the
405+
NoWritesPerformed label to the drivers.
406+
407+
Additionally, this test requires drivers to set a fail point after an
408+
``insertOne`` operation but before the subsequent retry. Drivers that are
409+
unable to set a failCommand after the CommandSucceededEvent SHOULD use
410+
mocking or write a unit test to cover the same sequence of events.
411+
412+
413+
1. Create a client with ``retryWrites=true``.
414+
415+
2. Configure a fail point with error code ``91`` (ShutdownInProgress)::
416+
417+
db.adminCommand({
418+
configureFailPoint: "failCommand",
419+
mode: {times: 1},
420+
data: {
421+
writeConcernError: {
422+
code: 91,
423+
errorLabels: ["RetryableWriteError"],
424+
},
425+
failCommands: ["insert"],
426+
},
427+
});
428+
429+
3. Via the command monitoring CommandSucceededEvent, configure a fail point
430+
with error code ``10107`` (NotWritablePrimary) and a NoWritesPerformed
431+
label::
432+
433+
db.adminCommand({
434+
configureFailPoint: "failCommand",
435+
mode: {times: 1},
436+
data: {
437+
errorCode: 10107,
438+
errorLabels: ["RetryableWriteError", "NoWritesPerformed"],
439+
failCommands: ["insert"],
440+
},
441+
});
442+
443+
Drivers SHOULD only configure the ``10107`` fail point command if the the
444+
succeeded event is for the ``91`` error configured in step 2.
445+
446+
4. Attempt an ``insertOne`` operation on any record for any database and
447+
collection. For the resulting error, assert that the associated error code
448+
is ``91``.
449+
450+
5. Disable the fail point::
451+
452+
db.adminCommand({
453+
configureFailPoint: "failCommand",
454+
mode: "off",
455+
})
398456

399457
Changelog
400458
=========
401459

460+
:2022-08-30: Add prose test verifying correct error handling for errors with
461+
the NoWritesPerformed label, which is to return the original
462+
error.
463+
402464
:2022-04-22: Clarifications to ``serverless`` and ``useMultipleMongoses``.
403465

404466
:2021-08-27: Add ``serverless`` to ``runOn``. Clarify behavior of

0 commit comments

Comments
 (0)