diff options
Diffstat (limited to 'src/mongo/db/repl')
-rw-r--r-- | src/mongo/db/repl/repl_coordinator_impl.cpp | 12 | ||||
-rw-r--r-- | src/mongo/db/repl/repl_coordinator_impl.h | 4 | ||||
-rw-r--r-- | src/mongo/db/repl/repl_coordinator_impl_test.cpp | 13 |
3 files changed, 27 insertions, 2 deletions
diff --git a/src/mongo/db/repl/repl_coordinator_impl.cpp b/src/mongo/db/repl/repl_coordinator_impl.cpp index ffb5a7ac45a..a284066aed7 100644 --- a/src/mongo/db/repl/repl_coordinator_impl.cpp +++ b/src/mongo/db/repl/repl_coordinator_impl.cpp @@ -103,6 +103,10 @@ namespace repl { return; } + // this is ok but micros or combo with some rand() and/or 64 bits might be better -- + // imagine a restart and a clock correction simultaneously (very unlikely but possible...) + _rbid = static_cast<int>(curTimeMillis64()); + _topCoord->registerStateChangeCallback( stdx::bind(&ReplicationCoordinatorImpl::_onSelfStateChange, this, @@ -708,11 +712,15 @@ namespace repl { } Status ReplicationCoordinatorImpl::processReplSetGetRBID(BSONObjBuilder* resultObj) { - // TODO + boost::lock_guard<boost::mutex> lk(_mutex); + resultObj->append("rbid", _rbid); return Status::OK(); } - void ReplicationCoordinatorImpl::incrementRollbackID() { /* TODO */ } + void ReplicationCoordinatorImpl::incrementRollbackID() { + boost::lock_guard<boost::mutex> lk(_mutex); + ++_rbid; + } Status ReplicationCoordinatorImpl::processReplSetFresh(const ReplSetFreshArgs& args, BSONObjBuilder* resultObj) { diff --git a/src/mongo/db/repl/repl_coordinator_impl.h b/src/mongo/db/repl/repl_coordinator_impl.h index 0a7b4465cb7..b93c5f4f21a 100644 --- a/src/mongo/db/repl/repl_coordinator_impl.h +++ b/src/mongo/db/repl/repl_coordinator_impl.h @@ -314,6 +314,10 @@ namespace repl { /// ============= All members below this line are guarded by _mutex ==================== /// + // Rollback ID. Used to check if a rollback happened during some interval of time + // TODO: ideally this should only change on rollbacks NOT on mongod restarts also. + int _rbid; + // list of information about clients waiting on replication. Does *not* own the // WaiterInfos. std::vector<WaiterInfo*> _replicationWaiterList; diff --git a/src/mongo/db/repl/repl_coordinator_impl_test.cpp b/src/mongo/db/repl/repl_coordinator_impl_test.cpp index d4fb42f277f..924ae02029f 100644 --- a/src/mongo/db/repl/repl_coordinator_impl_test.cpp +++ b/src/mongo/db/repl/repl_coordinator_impl_test.cpp @@ -251,6 +251,19 @@ namespace { ASSERT_OK(statusAndDur.status); } + TEST_F(ReplCoordTest, BasicRBIDUsage) { + start(); + BSONObjBuilder result; + getReplCoord()->processReplSetGetRBID(&result); + long long initialValue = result.obj()["rbid"].Int(); + getReplCoord()->incrementRollbackID(); + + BSONObjBuilder result2; + getReplCoord()->processReplSetGetRBID(&result2); + long long incrementedValue = result2.obj()["rbid"].Int(); + ASSERT_EQUALS(incrementedValue, initialValue + 1); + } + TEST_F(ReplCoordTest, AwaitReplicationNumberOfNodesNonBlocking) { assertStartSuccess( BSON("_id" << "mySet" << |