summaryrefslogtreecommitdiff
path: root/src/mongo/db/repl/sync_source_feedback.cpp
diff options
context:
space:
mode:
authorPavithra Vetriselvan <pavithra.vetriselvan@mongodb.com>2017-10-24 13:52:04 -0400
committerPavithra Vetriselvan <pavithra.vetriselvan@mongodb.com>2017-10-24 13:54:52 -0400
commit608f38a4fb0de96546dd0aa3eea2f244bbcf2bef (patch)
tree8be30a8c3fff92af1b94432e20d814d3e7cb0cdd /src/mongo/db/repl/sync_source_feedback.cpp
parent43b018194e1a49249092b871f3b7396e473d1426 (diff)
downloadmongo-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.cpp40
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) {