diff options
author | Scott Hernandez <scotthernandez@gmail.com> | 2014-11-17 09:23:16 -0500 |
---|---|---|
committer | Scott Hernandez <scotthernandez@gmail.com> | 2014-11-17 14:40:41 -0500 |
commit | 764b53c3432c0b01f8d44fe3cea1a5f6d07d805b (patch) | |
tree | a091b2a4ca53ae7929da5f46b231c380efa41859 /src/mongo/db/repl/is_master_response.cpp | |
parent | e98a99d0a51b14dab253ec84eec9aa41f163c517 (diff) | |
download | mongo-764b53c3432c0b01f8d44fe3cea1a5f6d07d805b.tar.gz |
SERVER-13542: include electionId in isMaster when primary
Diffstat (limited to 'src/mongo/db/repl/is_master_response.cpp')
-rw-r--r-- | src/mongo/db/repl/is_master_response.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/mongo/db/repl/is_master_response.cpp b/src/mongo/db/repl/is_master_response.cpp index 4ac169e2f10..a789fd7b6dd 100644 --- a/src/mongo/db/repl/is_master_response.cpp +++ b/src/mongo/db/repl/is_master_response.cpp @@ -33,6 +33,7 @@ #include "mongo/db/repl/is_master_response.h" #include "mongo/base/status.h" +#include "mongo/bson/oid.h" #include "mongo/bson/util/bson_extract.h" #include "mongo/db/jsobj.h" #include "mongo/util/mongoutils/str.h" @@ -56,6 +57,7 @@ namespace { const std::string kSlaveDelayFieldName = "slaveDelay"; const std::string kTagsFieldName = "tags"; const std::string kMeFieldName = "me"; + const std::string kElectionIdFieldName = "electionId"; // field name constants that don't directly correspond to member variables const std::string kInfoFieldName = "info"; @@ -89,6 +91,7 @@ namespace { _slaveDelaySet(false), _tagsSet(false), _meSet(false), + _electionId(OID()), _configSet(true), _shutdownInProgress(false) {} @@ -159,6 +162,8 @@ namespace { } invariant(_meSet); builder->append(kMeFieldName, _me.toString()); + if (_electionId.isSet()) + builder->append(kElectionIdFieldName, _electionId); } BSONObj IsMasterResponse::toBSON() const { @@ -344,6 +349,15 @@ namespace { _tagsSet = true; } + if (doc.hasField(kElectionIdFieldName)) { + BSONElement electionIdElem; + status = bsonExtractTypedField(doc, kElectionIdFieldName, jstOID, &electionIdElem); + if (!status.isOK()) { + return status; + } + _electionId = electionIdElem.OID(); + } + std::string meString; status = bsonExtractStringField(doc, kMeFieldName, &meString); if (!status.isOK()) { @@ -430,6 +444,10 @@ namespace { _me = me; } + void IsMasterResponse::setElectionId(const OID& electionId) { + _electionId = electionId; + } + void IsMasterResponse::markAsNoConfig() { _configSet = false; } void IsMasterResponse::markAsShutdownInProgress() { _shutdownInProgress = true; } |