summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorMatthew Saltz <matthew.saltz@mongodb.com>2019-11-04 22:18:43 +0000
committerevergreen <evergreen@mongodb.com>2019-11-04 22:18:43 +0000
commit13b7634057ea8f3278176f15e1299a52d7e0cdc8 (patch)
tree23e40becdf6a7f0814ed809ce48b5b1fd01b22b6 /src/mongo
parent75b580d614e9f36d804e81d0fc1b87ff764f852c (diff)
downloadmongo-13b7634057ea8f3278176f15e1299a52d7e0cdc8.tar.gz
SERVER-42914 Add failpoint to override balancer round interval (partial cherry pick)
(cherry picked from commit 5e14accc4ebe76366d7d2747fd30b603bf02eac2)
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/s/balancer/balancer.cpp25
-rw-r--r--src/mongo/db/s/balancer/balancer.h4
2 files changed, 22 insertions, 7 deletions
diff --git a/src/mongo/db/s/balancer/balancer.cpp b/src/mongo/db/s/balancer/balancer.cpp
index 6dcf93c5293..6caddbe97f5 100644
--- a/src/mongo/db/s/balancer/balancer.cpp
+++ b/src/mongo/db/s/balancer/balancer.cpp
@@ -56,6 +56,7 @@
#include "mongo/stdx/memory.h"
#include "mongo/util/concurrency/idle_thread_block.h"
#include "mongo/util/exit.h"
+#include "mongo/util/fail_point_service.h"
#include "mongo/util/log.h"
#include "mongo/util/timer.h"
#include "mongo/util/version.h"
@@ -68,6 +69,8 @@ using std::vector;
namespace {
+MONGO_FP_DECLARE(overrideBalanceRoundInterval);
+
const Seconds kBalanceRoundDefaultInterval(10);
// Sleep between balancer rounds in the case where the last round found some chunks which needed to
@@ -391,9 +394,21 @@ void Balancer::_mainThread() {
LOG(1) << "*** End of balancing round";
}
- _endRound(opCtx.get(),
- _balancedLastTime ? kShortBalanceRoundInterval
- : kBalanceRoundDefaultInterval);
+
+ auto balancerInterval = [&]() -> Milliseconds {
+ MONGO_FAIL_POINT_BLOCK(overrideBalanceRoundInterval, data) {
+ int interval = data.getData()["intervalMs"].numberInt();
+ log() << "overrideBalanceRoundInterval: using shorter balancing interval: "
+ << interval << "ms";
+
+ return Milliseconds(interval);
+ }
+
+ return _balancedLastTime ? kShortBalanceRoundInterval
+ : kBalanceRoundDefaultInterval;
+ }();
+
+ _endRound(opCtx.get(), balancerInterval);
} catch (const std::exception& e) {
log() << "caught exception while doing balance: " << e.what();
@@ -441,7 +456,7 @@ void Balancer::_beginRound(OperationContext* opCtx) {
_condVar.notify_all();
}
-void Balancer::_endRound(OperationContext* opCtx, Seconds waitTimeout) {
+void Balancer::_endRound(OperationContext* opCtx, Milliseconds waitTimeout) {
{
stdx::lock_guard<stdx::mutex> lock(_mutex);
_inBalancerRound = false;
@@ -453,7 +468,7 @@ void Balancer::_endRound(OperationContext* opCtx, Seconds waitTimeout) {
_sleepFor(opCtx, waitTimeout);
}
-void Balancer::_sleepFor(OperationContext* opCtx, Seconds waitTimeout) {
+void Balancer::_sleepFor(OperationContext* opCtx, Milliseconds waitTimeout) {
stdx::unique_lock<stdx::mutex> lock(_mutex);
_condVar.wait_for(lock, waitTimeout.toSystemDuration(), [&] { return _state != kRunning; });
}
diff --git a/src/mongo/db/s/balancer/balancer.h b/src/mongo/db/s/balancer/balancer.h
index eb0b143b6bc..da54de484ac 100644
--- a/src/mongo/db/s/balancer/balancer.h
+++ b/src/mongo/db/s/balancer/balancer.h
@@ -168,13 +168,13 @@ private:
* Signals the beginning and end of a balancing round.
*/
void _beginRound(OperationContext* opCtx);
- void _endRound(OperationContext* opCtx, Seconds waitTimeout);
+ void _endRound(OperationContext* opCtx, Milliseconds waitTimeout);
/**
* Blocks the caller for the specified timeout or until the balancer condition variable is
* signaled, whichever comes first.
*/
- void _sleepFor(OperationContext* opCtx, Seconds waitTimeout);
+ void _sleepFor(OperationContext* opCtx, Milliseconds waitTimeout);
/**
* Returns true if all the servers listed in configdb as being shards are reachable and are