diff options
author | Dianna Hohensee <dianna.hohensee@10gen.com> | 2016-10-25 16:30:38 -0400 |
---|---|---|
committer | Dianna Hohensee <dianna.hohensee@10gen.com> | 2016-10-26 15:19:13 -0400 |
commit | d187c9ee45046a32c2fde033550f4ddbc6229794 (patch) | |
tree | 458f3fd8479d44f41da0679a667e435558d0b380 | |
parent | 5077c3a69145577c3193ea4c0111cdee415e1de6 (diff) | |
download | mongo-d187c9ee45046a32c2fde033550f4ddbc6229794.tar.gz |
SERVER-26769 Balancer loads balancer settings before recovery and accepting/starting new migrations
-rw-r--r-- | jstests/sharding/jumbo1.js | 4 | ||||
-rw-r--r-- | src/mongo/db/s/balancer/balancer.cpp | 18 |
2 files changed, 19 insertions, 3 deletions
diff --git a/jstests/sharding/jumbo1.js b/jstests/sharding/jumbo1.js index ee5516b0bd7..f3f0e8d2a9d 100644 --- a/jstests/sharding/jumbo1.js +++ b/jstests/sharding/jumbo1.js @@ -14,12 +14,15 @@ big += "."; } + // Create sufficient documents to create a jumbo chunk, and use the same shard key in all of + // them so that the chunk cannot be split. var x = 0; var bulk = db.foo.initializeUnorderedBulkOp(); for (var i = 0; i < 500; i++) { bulk.insert({x: x, big: big}); } + // Create documents with different shard keys that can be split and moved without issue. for (; x < 1500; x++) { bulk.insert({x: x, big: big}); } @@ -43,6 +46,7 @@ return d < 5; }, "balance didn't happen", 1000 * 60 * 5, 5000); + // Check that the jumbo chunk did not move, which shouldn't be possible. var jumboChunk = s.getDB('config').chunks.findOne({ns: 'test.foo', min: {$lte: {x: 0}}, max: {$gt: {x: 0}}}); assert.eq('shard0001', jumboChunk.shard, 'jumbo chunk ' + tojson(jumboChunk) + ' was moved'); diff --git a/src/mongo/db/s/balancer/balancer.cpp b/src/mongo/db/s/balancer/balancer.cpp index 27b099935c7..4fddac5707f 100644 --- a/src/mongo/db/s/balancer/balancer.cpp +++ b/src/mongo/db/s/balancer/balancer.cpp @@ -327,9 +327,23 @@ void Balancer::_mainThread() { break; } + auto balancerConfig = shardingContext->getBalancerConfiguration(); + while (!_stopRequested()) { + Status refreshStatus = balancerConfig->refreshAndCheck(txn.get()); + if (!refreshStatus.isOK()) { + warning() << "Balancer settings could not be loaded and will be retried in " + << durationCount<Seconds>(kInitBackoffInterval) << " seconds" + << causedBy(refreshStatus); + + _sleepFor(txn.get(), kInitBackoffInterval); + continue; + } + + break; + } + log() << "CSRS balancer thread is recovering"; - auto balancerConfig = Grid::get(txn.get())->getBalancerConfiguration(); _migrationManager.finishRecovery(txn.get(), balancerConfig->getMaxChunkSizeBytes(), balancerConfig->getSecondaryThrottle(), @@ -339,8 +353,6 @@ void Balancer::_mainThread() { // Main balancer loop while (!_stopRequested()) { - auto balancerConfig = shardingContext->getBalancerConfiguration(); - BalanceRoundDetails roundDetails; _beginRound(txn.get()); |