[SERVER-34665] The mongo shell should retry writes on a WriteConcernFailure error response from the server Created: 25/Apr/18  Updated: 29/Oct/23  Resolved: 27/Apr/18

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: None
Fix Version/s: 3.6.5, 4.0.0-rc0

Type: Improvement Priority: Major - P3
Reporter: Max Hirschhorn Assignee: Max Hirschhorn
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Depends
is depended on by SERVER-34666 Reduce the number of retries needed f... Backlog
Related
Backwards Compatibility: Fully Compatible
Backport Requested:
v3.6
Sprint: TIG 2018-05-07
Participants:
Linked BF Score: 0

 Description   

At the time when SERVER-31194 was implemented, the Driver's specification only permitted retrying a write operation on "not master" errors. Since retrying on error responses matching the WriteConcernError class was found to be necessary for the correctness of the retryable_writes_jscore_stepdown_passthrough.yml test suite, it was done behind a TestData parameter to avoid having any impact on the user-facing version of the mongo shell.

function isRetryableCode(code) {
    return ErrorCodes.isNetworkError(code) || ErrorCodes.isNotMasterError(code) ||
        // The driver's spec does not allow retrying on writeConcern errors, so only do so
        // when testing retryable writes.
        (jsTest.options().alwaysInjectTransactionNumber &&
          ErrorCodes.isWriteConcernError(code));
}

There is now a list of retryable errors which permits the following definition for isRetryableCode():

function isRetryableCode(code) {
    return ErrorCodes.isNetworkError(code) || ErrorCodes.isNotMasterError(code) ||
        ErrorCodes.isShutdownError(code) || ErrorCodes.WriteConcernFailed === code;
}

Furthermore, the runClientFunctionWithRetries() function in src/mongo/shell/session.js must explicitly trigger retargeting when using a replica set connection and a non-"not master" error response is returned before attempting its retry. The mongo shell would otherwise always retry sending the command request to the server that is in the process of stepping down or has stepped down already. The desired behavior can be achieved by exposing a way to call ReplicaSetMonitor::failedHost() from JavaScript.



 Comments   
Comment by Githook User [ 06/May/18 ]

Author:

{'email': 'kyle.suarez@mongodb.com', 'name': 'Kyle Suarez', 'username': 'ksuarz'}

Message: SERVER-34665 skip retryable writes test if storage engine does not support retrying

(cherry picked from commit 7395b5fc63646c0499fffd887aae70f79e5f7049)
Branch: v3.6
https://github.com/mongodb/mongo/commit/91c8bb92f0b39348d4dfc0e30667acdf50027911

Comment by Githook User [ 06/May/18 ]

Author:

{'email': 'max.hirschhorn@mongodb.com', 'name': 'Max Hirschhorn', 'username': 'visemet'}

Message: SERVER-34665 Update definition of retryable error in the mongo shell.

Also exposes a way to explicitly trigger retargeting before the next
operation is run on the DBClientRS underlying a replica set connection
by calling ReplicaSetMonitor::failedHost().

(cherry picked from commit c7d12379bcd047c923b72bd29ac99d05edfbb82a)
Branch: v3.6
https://github.com/mongodb/mongo/commit/8763845a37eccc1d8e423d97dd0c85ca0b43f605

Comment by Githook User [ 01/May/18 ]

Author:

{'email': 'kyle.suarez@mongodb.com', 'name': 'Kyle Suarez', 'username': 'ksuarz'}

Message: SERVER-34665 skip retryable writes test if storage engine does not support retrying
Branch: master
https://github.com/mongodb/mongo/commit/7395b5fc63646c0499fffd887aae70f79e5f7049

Comment by Kyle Suarez [ 01/May/18 ]

The Githook User is slacking today.

Commit for test fix: https://github.com/mongodb/mongo/commit/7395b5fc63646c0499fffd887aae70f79e5f7049

Comment by Githook User [ 27/Apr/18 ]

Author:

{'email': 'max.hirschhorn@mongodb.com', 'username': 'visemet', 'name': 'Max Hirschhorn'}

Message: SERVER-34665 Update definition of retryable error in the mongo shell.

Also exposes a way to explicitly trigger retargeting before the next
operation is run on the DBClientRS underlying a replica set connection
by calling ReplicaSetMonitor::failedHost().
Branch: master
https://github.com/mongodb/mongo/commit/c7d12379bcd047c923b72bd29ac99d05edfbb82a

Generated at Thu Feb 08 04:37:26 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.