summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Hernandez <scotthernandez@gmail.com>2014-11-17 09:23:16 -0500
committerScott Hernandez <scotthernandez@gmail.com>2014-11-17 14:40:41 -0500
commit764b53c3432c0b01f8d44fe3cea1a5f6d07d805b (patch)
treea091b2a4ca53ae7929da5f46b231c380efa41859
parente98a99d0a51b14dab253ec84eec9aa41f163c517 (diff)
downloadmongo-764b53c3432c0b01f8d44fe3cea1a5f6d07d805b.tar.gz
SERVER-13542: include electionId in isMaster when primary
-rw-r--r--src/mongo/db/repl/is_master_response.cpp18
-rw-r--r--src/mongo/db/repl/is_master_response.h6
-rw-r--r--src/mongo/db/repl/repl_coordinator_impl.cpp2
-rw-r--r--src/mongo/db/repl/repl_coordinator_impl.h2
-rw-r--r--src/mongo/db/repl/repl_coordinator_impl_elect.cpp4
-rw-r--r--src/mongo/db/repl/topology_coordinator_impl.cpp3
6 files changed, 31 insertions, 4 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; }
diff --git a/src/mongo/db/repl/is_master_response.h b/src/mongo/db/repl/is_master_response.h
index 91bcc400ebe..dd0eda70e2b 100644
--- a/src/mongo/db/repl/is_master_response.h
+++ b/src/mongo/db/repl/is_master_response.h
@@ -31,6 +31,7 @@
#include <string>
#include <vector>
+#include "mongo/bson/oid.h"
#include "mongo/platform/unordered_map.h"
#include "mongo/util/net/hostandport.h"
#include "mongo/util/time_support.h"
@@ -106,6 +107,8 @@ namespace repl {
const HostAndPort& getMe() const { return _me; }
+ const OID& getElectionId() const { return _electionId; }
+
/**
* If false, calls to toBSON/addToBSON will ignore all other fields and add a specific
* message to indicate that we have no replica set config.
@@ -151,6 +154,8 @@ namespace repl {
void setMe(const HostAndPort& me);
+ void setElectionId(const OID& electionId);
+
/**
* Marks _configSet as false, which will cause future calls to toBSON/addToBSON to ignore
* all other member variables and output a hardcoded response indicating that we have no
@@ -197,6 +202,7 @@ namespace repl {
bool _tagsSet;
HostAndPort _me;
bool _meSet;
+ OID _electionId;
// If _configSet is false this means we don't have a valid repl set config, so toBSON
// will return a set of hardcoded values that indicate this.
diff --git a/src/mongo/db/repl/repl_coordinator_impl.cpp b/src/mongo/db/repl/repl_coordinator_impl.cpp
index b2dd2968b00..cdd1be23537 100644
--- a/src/mongo/db/repl/repl_coordinator_impl.cpp
+++ b/src/mongo/db/repl/repl_coordinator_impl.cpp
@@ -1267,7 +1267,7 @@ namespace {
OID ReplicationCoordinatorImpl::getElectionId() {
boost::lock_guard<boost::mutex> lock(_mutex);
- return _electionID;
+ return _electionId;
}
OID ReplicationCoordinatorImpl::getMyRID() const {
diff --git a/src/mongo/db/repl/repl_coordinator_impl.h b/src/mongo/db/repl/repl_coordinator_impl.h
index 13bfaada056..76b7e817d68 100644
--- a/src/mongo/db/repl/repl_coordinator_impl.h
+++ b/src/mongo/db/repl/repl_coordinator_impl.h
@@ -797,7 +797,7 @@ namespace repl {
bool _inShutdown; // (M)
// Election ID of the last election that resulted in this node becoming primary.
- OID _electionID; // (M)
+ OID _electionId; // (M)
// Vector containing known information about each member (such as replication
// progress and member ID) in our replica set or each member replicating from
diff --git a/src/mongo/db/repl/repl_coordinator_impl_elect.cpp b/src/mongo/db/repl/repl_coordinator_impl_elect.cpp
index 601787f96f4..b2e349e65f2 100644
--- a/src/mongo/db/repl/repl_coordinator_impl_elect.cpp
+++ b/src/mongo/db/repl/repl_coordinator_impl_elect.cpp
@@ -257,8 +257,8 @@ namespace {
_freshnessChecker.reset(NULL);
_electCmdRunner.reset(NULL);
boost::unique_lock<boost::mutex> lk(_mutex);
- _electionID = OID::gen();
- _topCoord->processWinElection(_electionID,
+ _electionId = OID::gen();
+ _topCoord->processWinElection(_electionId,
OpTime(Milliseconds(_replExecutor.now()).total_seconds(), 0));
const PostMemberStateUpdateAction action =
_updateCurrentMemberStateFromTopologyCoordinator_inlock();
diff --git a/src/mongo/db/repl/topology_coordinator_impl.cpp b/src/mongo/db/repl/topology_coordinator_impl.cpp
index b1cb52460a7..aa19f8a29cf 100644
--- a/src/mongo/db/repl/topology_coordinator_impl.cpp
+++ b/src/mongo/db/repl/topology_coordinator_impl.cpp
@@ -1468,6 +1468,9 @@ namespace {
}
}
response->setMe(selfConfig.getHostAndPort());
+ if (_iAmPrimary()) {
+ response->setElectionId(_electionId);
+ }
}
void TopologyCoordinatorImpl::prepareFreezeResponse(