summaryrefslogtreecommitdiff
path: root/src/mongo/db/s/periodic_balancer_config_refresher.cpp
diff options
context:
space:
mode:
authorBen Caimano <ben.caimano@10gen.com>2019-04-26 15:03:46 -0400
committerBen Caimano <ben.caimano@10gen.com>2019-06-21 17:02:30 -0400
commit1eff33bd1a8d48eb607675f87faf1836ba325006 (patch)
tree80149c8ff06158f7fdaaa0014500c06d080575a4 /src/mongo/db/s/periodic_balancer_config_refresher.cpp
parent8c4dfc2ba0568bd128a27f6481994758ce5f1c10 (diff)
downloadmongo-1eff33bd1a8d48eb607675f87faf1836ba325006.tar.gz
SERVER-39936 Use PeriodicRunner handles to simplify shutdown ordering
Diffstat (limited to 'src/mongo/db/s/periodic_balancer_config_refresher.cpp')
-rw-r--r--src/mongo/db/s/periodic_balancer_config_refresher.cpp15
1 files changed, 7 insertions, 8 deletions
diff --git a/src/mongo/db/s/periodic_balancer_config_refresher.cpp b/src/mongo/db/s/periodic_balancer_config_refresher.cpp
index 87b8ad55a4d..f9cab569d89 100644
--- a/src/mongo/db/s/periodic_balancer_config_refresher.cpp
+++ b/src/mongo/db/s/periodic_balancer_config_refresher.cpp
@@ -46,8 +46,7 @@ namespace {
const auto getPeriodicBalancerConfigRefresher =
ServiceContext::declareDecoration<PeriodicBalancerConfigRefresher>();
-std::unique_ptr<PeriodicRunner::PeriodicJobHandle> launchBalancerConfigRefresher(
- ServiceContext* serviceContext) {
+PeriodicJobAnchor launchBalancerConfigRefresher(ServiceContext* serviceContext) {
auto periodicRunner = serviceContext->getPeriodicRunner();
invariant(periodicRunner);
@@ -66,7 +65,7 @@ std::unique_ptr<PeriodicRunner::PeriodicJobHandle> launchBalancerConfigRefresher
},
Seconds(30));
auto balancerConfigRefresher = periodicRunner->makeJob(std::move(job));
- balancerConfigRefresher->start();
+ balancerConfigRefresher.start();
return balancerConfigRefresher;
}
@@ -86,7 +85,7 @@ void PeriodicBalancerConfigRefresher::onShardingInitialization(ServiceContext* s
_isPrimary = isPrimary;
// This function is called on sharding state initialization, so go ahead
// and start up the balancer config refresher task if we're a primary.
- if (isPrimary && !_balancerConfigRefresher) {
+ if (isPrimary && !_balancerConfigRefresher.isValid()) {
_balancerConfigRefresher = launchBalancerConfigRefresher(serviceContext);
}
}
@@ -95,12 +94,12 @@ void PeriodicBalancerConfigRefresher::onStepUp(ServiceContext* serviceContext) {
_isPrimary = true;
// If this is the first time we're stepping up, start a thread to periodically refresh the
// balancer configuration.
- if (!_balancerConfigRefresher) {
+ if (!_balancerConfigRefresher.isValid()) {
_balancerConfigRefresher = launchBalancerConfigRefresher(serviceContext);
} else {
// If we're stepping up again after having stepped down, just resume
// the existing task.
- _balancerConfigRefresher->resume();
+ _balancerConfigRefresher.resume();
}
}
}
@@ -108,9 +107,9 @@ void PeriodicBalancerConfigRefresher::onStepUp(ServiceContext* serviceContext) {
void PeriodicBalancerConfigRefresher::onStepDown() {
if (_isPrimary) {
_isPrimary = false;
- invariant(_balancerConfigRefresher);
+ invariant(_balancerConfigRefresher.isValid());
// We don't need to be refreshing the balancer configuration unless we're primary.
- _balancerConfigRefresher->pause();
+ _balancerConfigRefresher.pause();
}
}