diff options
author | Max Hirschhorn <max.hirschhorn@mongodb.com> | 2017-11-08 19:29:28 -0500 |
---|---|---|
committer | Max Hirschhorn <max.hirschhorn@mongodb.com> | 2017-11-08 19:29:28 -0500 |
commit | 6d8e6b9cce052cdd442e207a27df10e698b2bb00 (patch) | |
tree | 5a7bb7b5cf93902bf00a681dccb0f54adb2f1ab0 /src/mongo/client | |
parent | f7756c41c5ed54e8e546461395bc8898d885af0c (diff) | |
download | mongo-6d8e6b9cce052cdd442e207a27df10e698b2bb00.tar.gz |
SERVER-31296 Update sessions, causal, and retryable in the mongo shell.
* Removes the initialClusterTime and initialOperationTime session
options.
* Enables causal consistency by default when using an explicit
session.
* Adds a --retryWrites command line option to the mongo shell for
enabling retryable writes in the mongo shell. The retryWrites
options to SessionOptions is left for convenience with testing.
* Renames setClusterTime() to advanceClusterTime(), and adds a
corresponding advanceOperationTime() method to DriverSession.
* Enables assigning transaction numbers for write commands where
ordered=false.
* Prevents the mongo shell from sending afterClusterTime or assigning
transaction numbers when talking to a stand-alone mongod.
* Prevents the mongo shell from assigning transaction numbers when
using an unacknowledged (w=0) writeConcern.
* Changes DBClientRS to re-discover the current primary of the replica
set when it receives an error code representing "not master" in
addition to an error message representing "not master".
* Adds a shellPrint() pretty-printer for SessionOptions and
DriverSession instances so they no longer print out their entire
object definition.
Diffstat (limited to 'src/mongo/client')
-rw-r--r-- | src/mongo/client/dbclient.cpp | 15 | ||||
-rw-r--r-- | src/mongo/client/dbclientinterface.h | 8 |
2 files changed, 14 insertions, 9 deletions
diff --git a/src/mongo/client/dbclient.cpp b/src/mongo/client/dbclient.cpp index e3869b773df..8028cc1b3bc 100644 --- a/src/mongo/client/dbclient.cpp +++ b/src/mongo/client/dbclient.cpp @@ -998,7 +998,7 @@ std::pair<rpc::UniqueReply, DBClientBase*> DBClientConnection::runCommandWithTar if (!_parentReplSetName.empty()) { const auto replyBody = out.first->getCommandReply(); if (!isOk(replyBody)) { - handleNotMasterResponse(replyBody["errmsg"]); + handleNotMasterResponse(replyBody, "errmsg"); } } @@ -1011,7 +1011,7 @@ std::pair<rpc::UniqueReply, std::shared_ptr<DBClientBase>> DBClientConnection::r if (!_parentReplSetName.empty()) { const auto replyBody = out.first->getCommandReply(); if (!isOk(replyBody)) { - handleNotMasterResponse(replyBody["errmsg"]); + handleNotMasterResponse(replyBody, "errmsg"); } } @@ -1474,7 +1474,7 @@ void DBClientConnection::checkResponse(const std::vector<BSONObj>& batch, *host = _serverAddress.toString(); if (!_parentReplSetName.empty() && !batch.empty()) { - handleNotMasterResponse(getErrField(batch[0])); + handleNotMasterResponse(batch[0], "$err"); } } @@ -1482,8 +1482,13 @@ void DBClientConnection::setParentReplSetName(const string& replSetName) { _parentReplSetName = replSetName; } -void DBClientConnection::handleNotMasterResponse(const BSONElement& elemToCheck) { - if (!isNotMasterErrorString(elemToCheck)) { +void DBClientConnection::handleNotMasterResponse(const BSONObj& replyBody, + StringData errorMsgFieldName) { + const BSONElement errorMsgElem = replyBody[errorMsgFieldName]; + const BSONElement codeElem = replyBody["code"]; + + if (!isNotMasterErrorString(errorMsgElem) && + !ErrorCodes::isNotMasterError(ErrorCodes::Error(codeElem.numberInt()))) { return; } diff --git a/src/mongo/client/dbclientinterface.h b/src/mongo/client/dbclientinterface.h index fdfc816b126..de81dabdd92 100644 --- a/src/mongo/client/dbclientinterface.h +++ b/src/mongo/client/dbclientinterface.h @@ -1084,11 +1084,11 @@ protected: private: /** - * Checks the BSONElement for the 'not master' keyword and if it does exist, - * try to inform the replica set monitor that the host this connects to is - * no longer primary. + * Inspects the contents of 'replyBody' and informs the replica set monitor that the host 'this' + * is connected with is no longer the primary if a "not master" error message or error code was + * returned. */ - void handleNotMasterResponse(const BSONElement& elemToCheck); + void handleNotMasterResponse(const BSONObj& replyBody, StringData errorMsgFieldName); // Contains the string for the replica set name of the host this is connected to. // Should be empty if this connection is not pointing to a replica set member. |