diff options
author | Pavithra Vetriselvan <pavithra.vetriselvan@mongodb.com> | 2017-10-24 13:52:04 -0400 |
---|---|---|
committer | Pavithra Vetriselvan <pavithra.vetriselvan@mongodb.com> | 2017-10-24 13:54:52 -0400 |
commit | 608f38a4fb0de96546dd0aa3eea2f244bbcf2bef (patch) | |
tree | 8be30a8c3fff92af1b94432e20d814d3e7cb0cdd /src/mongo/db/repl/sync_source_feedback.cpp | |
parent | 43b018194e1a49249092b871f3b7396e473d1426 (diff) | |
download | mongo-608f38a4fb0de96546dd0aa3eea2f244bbcf2bef.tar.gz |
SERVER-31589 Replaces OpContext pts with ReplicationCoordinator ptrs.
Diffstat (limited to 'src/mongo/db/repl/sync_source_feedback.cpp')
-rw-r--r-- | src/mongo/db/repl/sync_source_feedback.cpp | 40 |
1 files changed, 17 insertions, 23 deletions
diff --git a/src/mongo/db/repl/sync_source_feedback.cpp b/src/mongo/db/repl/sync_source_feedback.cpp index dceeb7422d2..8fd1e66d6a5 100644 --- a/src/mongo/db/repl/sync_source_feedback.cpp +++ b/src/mongo/db/repl/sync_source_feedback.cpp @@ -50,24 +50,19 @@ namespace repl { namespace { /** - * Calculates the keep alive interval based on the current configuration in the replication - * coordinator. + * Calculates the keep alive interval based on the given ReplSetConfig. */ -Milliseconds calculateKeepAliveInterval(OperationContext* opCtx, stdx::mutex& mtx) { - stdx::lock_guard<stdx::mutex> lock(mtx); - auto replCoord = repl::ReplicationCoordinator::get(opCtx); - auto rsConfig = replCoord->getConfig(); - auto keepAliveInterval = rsConfig.getElectionTimeoutPeriod() / 2; - return keepAliveInterval; +Milliseconds calculateKeepAliveInterval(const ReplSetConfig& rsConfig) { + return rsConfig.getElectionTimeoutPeriod() / 2; } /** * Returns function to prepare update command */ Reporter::PrepareReplSetUpdatePositionCommandFn makePrepareReplSetUpdatePositionCommandFn( - OperationContext* opCtx, const HostAndPort& syncTarget, BackgroundSync* bgsync) { - return [syncTarget, opCtx, bgsync](ReplicationCoordinator::ReplSetUpdatePositionCommandStyle - commandStyle) -> StatusWith<BSONObj> { + ReplicationCoordinator* replCoord, const HostAndPort& syncTarget, BackgroundSync* bgsync) { + return [syncTarget, replCoord, bgsync](ReplicationCoordinator::ReplSetUpdatePositionCommandStyle + commandStyle) -> StatusWith<BSONObj> { auto currentSyncTarget = bgsync->getSyncTarget(); if (currentSyncTarget != syncTarget) { if (currentSyncTarget.empty()) { @@ -83,7 +78,6 @@ Reporter::PrepareReplSetUpdatePositionCommandFn makePrepareReplSetUpdatePosition } } - auto replCoord = repl::ReplicationCoordinator::get(opCtx); if (replCoord->getMemberState().primary()) { // Primary has no one to send updates to. return Status(ErrorCodes::InvalidSyncSource, @@ -141,7 +135,9 @@ void SyncSourceFeedback::shutdown() { _cond.notify_all(); } -void SyncSourceFeedback::run(executor::TaskExecutor* executor, BackgroundSync* bgsync) { +void SyncSourceFeedback::run(executor::TaskExecutor* executor, + BackgroundSync* bgsync, + ReplicationCoordinator* replCoord) { Client::initThread("SyncSourceFeedback"); HostAndPort syncTarget; @@ -150,10 +146,9 @@ void SyncSourceFeedback::run(executor::TaskExecutor* executor, BackgroundSync* b Milliseconds keepAliveInterval(0); while (true) { // breaks once _shutdownSignaled is true - auto opCtx = cc().makeOperationContext(); if (keepAliveInterval == Milliseconds(0)) { - keepAliveInterval = calculateKeepAliveInterval(opCtx.get(), _mtx); + keepAliveInterval = calculateKeepAliveInterval(replCoord->getConfig()); } { @@ -169,7 +164,7 @@ void SyncSourceFeedback::run(executor::TaskExecutor* executor, BackgroundSync* b continue; } } - MemberState state = ReplicationCoordinator::get(opCtx.get())->getMemberState(); + MemberState state = replCoord->getMemberState(); if (!(state.primary() || state.startup())) { break; } @@ -184,7 +179,7 @@ void SyncSourceFeedback::run(executor::TaskExecutor* executor, BackgroundSync* b { stdx::lock_guard<stdx::mutex> lock(_mtx); - MemberState state = ReplicationCoordinator::get(opCtx.get())->getMemberState(); + MemberState state = replCoord->getMemberState(); if (state.primary() || state.startup()) { continue; } @@ -206,18 +201,17 @@ void SyncSourceFeedback::run(executor::TaskExecutor* executor, BackgroundSync* b // Update keepalive value from config. auto oldKeepAliveInterval = keepAliveInterval; - keepAliveInterval = calculateKeepAliveInterval(opCtx.get(), _mtx); + keepAliveInterval = calculateKeepAliveInterval(replCoord->getConfig()); if (oldKeepAliveInterval != keepAliveInterval) { LOG(1) << "new syncSourceFeedback keep alive duration = " << keepAliveInterval << " (previously " << oldKeepAliveInterval << ")"; } } - Reporter reporter( - executor, - makePrepareReplSetUpdatePositionCommandFn(opCtx.get(), syncTarget, bgsync), - syncTarget, - keepAliveInterval); + Reporter reporter(executor, + makePrepareReplSetUpdatePositionCommandFn(replCoord, syncTarget, bgsync), + syncTarget, + keepAliveInterval); { stdx::lock_guard<stdx::mutex> lock(_mtx); if (_shutdownSignaled) { |