summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Schwerin <schwerin@mongodb.com>2017-01-25 13:12:37 -0500
committerAndy Schwerin <schwerin@mongodb.com>2017-01-25 13:12:37 -0500
commit60185f785b617c775fd15cd6c7212373d936f0d5 (patch)
tree04a350ace79e26ff6938ff27604a5558aa181382
parentef208c94e55a04978b9b5dede6764a7b6c587b41 (diff)
downloadmongo-60185f785b617c775fd15cd6c7212373d936f0d5.tar.gz
SERVER-27800 Change ReplicationCoordinatorImpl and ReplicationExecutor constructors to take owned objects by unique_ptr
The constructors of ReplicationCoordinatorImpl and ReplicationExecutor predate C++11 support in the MongoDB codebase, and so receive bare pointers to objects that they actually own. This patch is to changes the constructors and some of the associated test infrastructure to transfer ownership by passing unique_ptr, as in more modern components.
-rw-r--r--src/mongo/db/db.cpp6
-rw-r--r--src/mongo/db/repl/check_quorum_for_config_change_test.cpp5
-rw-r--r--src/mongo/db/repl/elect_cmd_runner_test.cpp5
-rw-r--r--src/mongo/db/repl/freshness_checker_test.cpp5
-rw-r--r--src/mongo/db/repl/freshness_scanner_test.cpp5
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl.cpp13
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl.h7
-rw-r--r--src/mongo/db/repl/replication_coordinator_test_fixture.cpp17
-rw-r--r--src/mongo/db/repl/replication_executor.cpp5
-rw-r--r--src/mongo/db/repl/replication_executor.h2
-rw-r--r--src/mongo/db/repl/replication_executor_test.cpp4
-rw-r--r--src/mongo/db/repl/replication_executor_test_fixture.cpp2
-rw-r--r--src/mongo/db/repl/scatter_gather_test.cpp5
-rw-r--r--src/mongo/executor/task_executor_test_common.cpp4
-rw-r--r--src/mongo/executor/task_executor_test_common.h2
-rw-r--r--src/mongo/executor/thread_pool_task_executor_test.cpp4
16 files changed, 52 insertions, 39 deletions
diff --git a/src/mongo/db/db.cpp b/src/mongo/db/db.cpp
index cbcf906326e..2822fae92c2 100644
--- a/src/mongo/db/db.cpp
+++ b/src/mongo/db/db.cpp
@@ -884,9 +884,9 @@ MONGO_INITIALIZER_WITH_PREREQUISITES(CreateReplicationManager,
auto replCoord = stdx::make_unique<repl::ReplicationCoordinatorImpl>(
getGlobalReplSettings(),
- new repl::ReplicationCoordinatorExternalStateImpl(storageInterface),
- executor::makeNetworkInterface("NetworkInterfaceASIO-Replication").release(),
- new repl::TopologyCoordinatorImpl(topoCoordOptions),
+ stdx::make_unique<repl::ReplicationCoordinatorExternalStateImpl>(storageInterface),
+ executor::makeNetworkInterface("NetworkInterfaceASIO-Replication"),
+ stdx::make_unique<repl::TopologyCoordinatorImpl>(topoCoordOptions),
storageInterface,
static_cast<int64_t>(curTimeMillis64()));
repl::ReplicationCoordinator::set(serviceContext, std::move(replCoord));
diff --git a/src/mongo/db/repl/check_quorum_for_config_change_test.cpp b/src/mongo/db/repl/check_quorum_for_config_change_test.cpp
index e6480598f80..9354c9c5f32 100644
--- a/src/mongo/db/repl/check_quorum_for_config_change_test.cpp
+++ b/src/mongo/db/repl/check_quorum_for_config_change_test.cpp
@@ -97,8 +97,9 @@ CheckQuorumTest::CheckQuorumTest()
: _quorumCheckStatus(ErrorCodes::InternalError, "Not executed") {}
void CheckQuorumTest::setUp() {
- _net = new NetworkInterfaceMock;
- _executor = stdx::make_unique<ReplicationExecutor>(_net, 1 /* prng seed */);
+ auto net = stdx::make_unique<NetworkInterfaceMock>();
+ _net = net.get();
+ _executor = stdx::make_unique<ReplicationExecutor>(std::move(net), 1 /* prng seed */);
_executorThread.reset(new stdx::thread(stdx::bind(&ReplicationExecutor::run, _executor.get())));
}
diff --git a/src/mongo/db/repl/elect_cmd_runner_test.cpp b/src/mongo/db/repl/elect_cmd_runner_test.cpp
index 680689e713d..dc644874d5b 100644
--- a/src/mongo/db/repl/elect_cmd_runner_test.cpp
+++ b/src/mongo/db/repl/elect_cmd_runner_test.cpp
@@ -79,8 +79,9 @@ private:
};
void ElectCmdRunnerTest::setUp() {
- _net = new NetworkInterfaceMock;
- _executor = stdx::make_unique<ReplicationExecutor>(_net, 1 /* prng seed */);
+ auto net = stdx::make_unique<NetworkInterfaceMock>();
+ _net = net.get();
+ _executor = stdx::make_unique<ReplicationExecutor>(std::move(net), 1 /* prng seed */);
_executorThread.reset(new stdx::thread(stdx::bind(&ReplicationExecutor::run, _executor.get())));
}
diff --git a/src/mongo/db/repl/freshness_checker_test.cpp b/src/mongo/db/repl/freshness_checker_test.cpp
index 5c33c8988bb..40cd0786e9d 100644
--- a/src/mongo/db/repl/freshness_checker_test.cpp
+++ b/src/mongo/db/repl/freshness_checker_test.cpp
@@ -90,8 +90,9 @@ private:
};
void FreshnessCheckerTest::setUp() {
- _net = new NetworkInterfaceMock;
- _executor = stdx::make_unique<ReplicationExecutor>(_net, 1 /* prng seed */);
+ auto net = stdx::make_unique<NetworkInterfaceMock>();
+ _net = net.get();
+ _executor = stdx::make_unique<ReplicationExecutor>(std::move(net), 1 /* prng seed */);
_executorThread.reset(new stdx::thread(stdx::bind(&ReplicationExecutor::run, _executor.get())));
_checker.reset(new FreshnessChecker);
}
diff --git a/src/mongo/db/repl/freshness_scanner_test.cpp b/src/mongo/db/repl/freshness_scanner_test.cpp
index d931ef55b70..9e34741c70a 100644
--- a/src/mongo/db/repl/freshness_scanner_test.cpp
+++ b/src/mongo/db/repl/freshness_scanner_test.cpp
@@ -83,8 +83,9 @@ public:
<< 0)))));
ASSERT_OK(_config.validate());
- _net = new NetworkInterfaceMock;
- _executor = stdx::make_unique<ReplicationExecutor>(_net, 1 /* prng seed */);
+ auto net = stdx::make_unique<NetworkInterfaceMock>();
+ _net = net.get();
+ _executor = stdx::make_unique<ReplicationExecutor>(std::move(net), 1 /* prng seed */);
_executorThread =
stdx::make_unique<stdx::thread>(stdx::bind(&ReplicationExecutor::run, _executor.get()));
}
diff --git a/src/mongo/db/repl/replication_coordinator_impl.cpp b/src/mongo/db/repl/replication_coordinator_impl.cpp
index 66db01ccfe9..c275ad246e8 100644
--- a/src/mongo/db/repl/replication_coordinator_impl.cpp
+++ b/src/mongo/db/repl/replication_coordinator_impl.cpp
@@ -73,6 +73,7 @@
#include "mongo/db/write_concern.h"
#include "mongo/db/write_concern_options.h"
#include "mongo/executor/connection_pool_stats.h"
+#include "mongo/executor/network_interface.h"
#include "mongo/rpc/metadata/oplog_query_metadata.h"
#include "mongo/rpc/metadata/repl_set_metadata.h"
#include "mongo/rpc/metadata/server_selection_metadata.h"
@@ -305,16 +306,16 @@ std::string ReplicationCoordinatorImpl::SnapshotInfo::toString() const {
ReplicationCoordinatorImpl::ReplicationCoordinatorImpl(
const ReplSettings& settings,
- ReplicationCoordinatorExternalState* externalState,
- NetworkInterface* network,
- TopologyCoordinator* topCoord,
+ std::unique_ptr<ReplicationCoordinatorExternalState> externalState,
+ std::unique_ptr<NetworkInterface> network,
+ std::unique_ptr<TopologyCoordinator> topCoord,
StorageInterface* storage,
int64_t prngSeed)
: _settings(settings),
_replMode(getReplicationModeFromSettings(settings)),
- _topCoord(topCoord),
- _replExecutor(network, prngSeed),
- _externalState(externalState),
+ _topCoord(std::move(topCoord)),
+ _replExecutor(std::move(network), prngSeed),
+ _externalState(std::move(externalState)),
_inShutdown(false),
_memberState(MemberState::RS_STARTUP),
_isWaitingForDrainToComplete(false),
diff --git a/src/mongo/db/repl/replication_coordinator_impl.h b/src/mongo/db/repl/replication_coordinator_impl.h
index b8f19b16271..e31f218bbd0 100644
--- a/src/mongo/db/repl/replication_coordinator_impl.h
+++ b/src/mongo/db/repl/replication_coordinator_impl.h
@@ -89,11 +89,10 @@ class ReplicationCoordinatorImpl : public ReplicationCoordinator {
MONGO_DISALLOW_COPYING(ReplicationCoordinatorImpl);
public:
- // Takes ownership of the "externalState", "topCoord" and "network" objects.
ReplicationCoordinatorImpl(const ReplSettings& settings,
- ReplicationCoordinatorExternalState* externalState,
- executor::NetworkInterface* network,
- TopologyCoordinator* topoCoord,
+ std::unique_ptr<ReplicationCoordinatorExternalState> externalState,
+ std::unique_ptr<executor::NetworkInterface> network,
+ std::unique_ptr<TopologyCoordinator> topoCoord,
StorageInterface* storage,
int64_t prngSeed);
diff --git a/src/mongo/db/repl/replication_coordinator_test_fixture.cpp b/src/mongo/db/repl/replication_coordinator_test_fixture.cpp
index f293486b946..b77836029b4 100644
--- a/src/mongo/db/repl/replication_coordinator_test_fixture.cpp
+++ b/src/mongo/db/repl/replication_coordinator_test_fixture.cpp
@@ -121,11 +121,18 @@ void ReplCoordTest::init() {
const int64_t seed = 0;
TopologyCoordinatorImpl::Options settings;
- _topo = new TopologyCoordinatorImpl(settings);
- _net = new NetworkInterfaceMock;
- _externalState = new ReplicationCoordinatorExternalStateMock;
- _repl.reset(new ReplicationCoordinatorImpl(
- _settings, _externalState, _net, _topo, storageInterface, seed));
+ auto topo = stdx::make_unique<TopologyCoordinatorImpl>(settings);
+ _topo = topo.get();
+ auto net = stdx::make_unique<NetworkInterfaceMock>();
+ _net = net.get();
+ auto externalState = stdx::make_unique<ReplicationCoordinatorExternalStateMock>();
+ _externalState = externalState.get();
+ _repl = stdx::make_unique<ReplicationCoordinatorImpl>(_settings,
+ std::move(externalState),
+ std::move(net),
+ std::move(topo),
+ storageInterface,
+ seed);
auto service = getGlobalServiceContext();
service->setFastClockSource(stdx::make_unique<executor::NetworkInterfaceMockClockSource>(_net));
service->setPreciseClockSource(
diff --git a/src/mongo/db/repl/replication_executor.cpp b/src/mongo/db/repl/replication_executor.cpp
index 7497793b6ca..f4070ac5d9e 100644
--- a/src/mongo/db/repl/replication_executor.cpp
+++ b/src/mongo/db/repl/replication_executor.cpp
@@ -56,9 +56,10 @@ using executor::NetworkInterface;
using executor::RemoteCommandRequest;
using executor::RemoteCommandResponse;
-ReplicationExecutor::ReplicationExecutor(NetworkInterface* netInterface, int64_t prngSeed)
+ReplicationExecutor::ReplicationExecutor(std::unique_ptr<NetworkInterface> netInterface,
+ int64_t prngSeed)
: _random(prngSeed),
- _networkInterface(netInterface),
+ _networkInterface(std::move(netInterface)),
_inShutdown(false),
_dblockWorkers(OldThreadPool::DoNotStartThreadsTag(), 3, "replExecDBWorker-"),
_dblockTaskRunner(&_dblockWorkers),
diff --git a/src/mongo/db/repl/replication_executor.h b/src/mongo/db/repl/replication_executor.h
index b317ca587ec..26f8e522317 100644
--- a/src/mongo/db/repl/replication_executor.h
+++ b/src/mongo/db/repl/replication_executor.h
@@ -98,7 +98,7 @@ public:
*
* Takes ownership of the passed NetworkInterface object.
*/
- ReplicationExecutor(executor::NetworkInterface* netInterface, int64_t pnrgSeed);
+ ReplicationExecutor(std::unique_ptr<executor::NetworkInterface> netInterface, int64_t pnrgSeed);
/**
* Destroys an executor.
diff --git a/src/mongo/db/repl/replication_executor_test.cpp b/src/mongo/db/repl/replication_executor_test.cpp
index 98cb267f0da..e630a4a2e30 100644
--- a/src/mongo/db/repl/replication_executor_test.cpp
+++ b/src/mongo/db/repl/replication_executor_test.cpp
@@ -61,8 +61,8 @@ const int64_t prngSeed = 1;
MONGO_INITIALIZER(ReplExecutorCommonTests)(InitializerContext*) {
mongo::executor::addTestsForExecutor(
- "ReplicationExecutorCommon", [](std::unique_ptr<executor::NetworkInterfaceMock>* net) {
- return stdx::make_unique<ReplicationExecutor>(net->release(), prngSeed);
+ "ReplicationExecutorCommon", [](std::unique_ptr<executor::NetworkInterfaceMock> net) {
+ return stdx::make_unique<ReplicationExecutor>(std::move(net), prngSeed);
});
return Status::OK();
}
diff --git a/src/mongo/db/repl/replication_executor_test_fixture.cpp b/src/mongo/db/repl/replication_executor_test_fixture.cpp
index f245e4becc8..bdc1f976e9e 100644
--- a/src/mongo/db/repl/replication_executor_test_fixture.cpp
+++ b/src/mongo/db/repl/replication_executor_test_fixture.cpp
@@ -53,7 +53,7 @@ void ReplicationExecutorTest::postExecutorThreadLaunch() {
std::unique_ptr<executor::TaskExecutor> ReplicationExecutorTest::makeTaskExecutor(
std::unique_ptr<executor::NetworkInterfaceMock> net) {
- return stdx::make_unique<ReplicationExecutor>(net.release(), prngSeed);
+ return stdx::make_unique<ReplicationExecutor>(std::move(net), prngSeed);
}
} // namespace repl
diff --git a/src/mongo/db/repl/scatter_gather_test.cpp b/src/mongo/db/repl/scatter_gather_test.cpp
index e231c251d35..63915e0df98 100644
--- a/src/mongo/db/repl/scatter_gather_test.cpp
+++ b/src/mongo/db/repl/scatter_gather_test.cpp
@@ -118,8 +118,9 @@ private:
};
void ScatterGatherTest::setUp() {
- _net = new NetworkInterfaceMock;
- _executor = stdx::make_unique<ReplicationExecutor>(_net, 1 /* prng seed */);
+ auto net = stdx::make_unique<NetworkInterfaceMock>();
+ _net = net.get();
+ _executor = stdx::make_unique<ReplicationExecutor>(std::move(net), 1 /* prng seed */);
_executorThread.reset(new stdx::thread(stdx::bind(&ReplicationExecutor::run, _executor.get())));
}
diff --git a/src/mongo/executor/task_executor_test_common.cpp b/src/mongo/executor/task_executor_test_common.cpp
index 57c12813250..94984a32381 100644
--- a/src/mongo/executor/task_executor_test_common.cpp
+++ b/src/mongo/executor/task_executor_test_common.cpp
@@ -51,7 +51,7 @@ namespace executor {
namespace {
using ExecutorFactory =
- stdx::function<std::unique_ptr<TaskExecutor>(std::unique_ptr<NetworkInterfaceMock>*)>;
+ stdx::function<std::unique_ptr<TaskExecutor>(std::unique_ptr<NetworkInterfaceMock>)>;
class CommonTaskExecutorTestFixture : public TaskExecutorTest {
public:
@@ -61,7 +61,7 @@ public:
private:
std::unique_ptr<TaskExecutor> makeTaskExecutor(
std::unique_ptr<NetworkInterfaceMock> net) override {
- return _makeExecutor(&net);
+ return _makeExecutor(std::move(net));
}
ExecutorFactory _makeExecutor;
diff --git a/src/mongo/executor/task_executor_test_common.h b/src/mongo/executor/task_executor_test_common.h
index b9fd7e7235c..0f4895f5ae4 100644
--- a/src/mongo/executor/task_executor_test_common.h
+++ b/src/mongo/executor/task_executor_test_common.h
@@ -51,7 +51,7 @@ class TaskExecutor;
*/
void addTestsForExecutor(const std::string& suiteName,
stdx::function<std::unique_ptr<TaskExecutor>(
- std::unique_ptr<NetworkInterfaceMock>*)> makeExecutor);
+ std::unique_ptr<NetworkInterfaceMock>)> makeExecutor);
} // namespace executor
} // namespace mongo
diff --git a/src/mongo/executor/thread_pool_task_executor_test.cpp b/src/mongo/executor/thread_pool_task_executor_test.cpp
index 350c475ed01..db0cc594f42 100644
--- a/src/mongo/executor/thread_pool_task_executor_test.cpp
+++ b/src/mongo/executor/thread_pool_task_executor_test.cpp
@@ -48,8 +48,8 @@ namespace executor {
namespace {
MONGO_INITIALIZER(ThreadPoolExecutorCommonTests)(InitializerContext*) {
- addTestsForExecutor("ThreadPoolExecutorCommon", [](std::unique_ptr<NetworkInterfaceMock>* net) {
- return makeThreadPoolTestExecutor(std::move(*net));
+ addTestsForExecutor("ThreadPoolExecutorCommon", [](std::unique_ptr<NetworkInterfaceMock> net) {
+ return makeThreadPoolTestExecutor(std::move(net));
});
return Status::OK();
}