diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2017-07-12 11:50:55 -0400 |
---|---|---|
committer | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2017-07-13 09:19:05 -0400 |
commit | 411114cb3ec3119bb159b29b8ef65292e4d20de3 (patch) | |
tree | ef00e794b0477728cacf04fcc40d979cda9fe251 | |
parent | fc300ed58b943b93a3164103e4a767e3f81d1c3b (diff) | |
download | mongo-411114cb3ec3119bb159b29b8ef65292e4d20de3.tar.gz |
SERVER-30058 Balancer policy should not move chunks off shards on 'size exceeded' conditions
-rw-r--r-- | src/mongo/db/s/balancer/balancer_policy.cpp | 8 | ||||
-rw-r--r-- | src/mongo/db/s/balancer/balancer_policy_test.cpp | 26 | ||||
-rw-r--r-- | src/mongo/db/s/balancer/cluster_statistics.cpp | 8 | ||||
-rw-r--r-- | src/mongo/db/s/balancer/cluster_statistics.h | 6 |
4 files changed, 23 insertions, 25 deletions
diff --git a/src/mongo/db/s/balancer/balancer_policy.cpp b/src/mongo/db/s/balancer/balancer_policy.cpp index e3237063ac1..e606e8b305a 100644 --- a/src/mongo/db/s/balancer/balancer_policy.cpp +++ b/src/mongo/db/s/balancer/balancer_policy.cpp @@ -222,8 +222,7 @@ Status BalancerPolicy::isShardSuitableReceiver(const ClusterStatistics::ShardSta const string& chunkTag) { if (stat.isSizeMaxed()) { return {ErrorCodes::IllegalOperation, - str::stream() << stat.shardId - << " has already reached the maximum total chunk size."}; + str::stream() << stat.shardId << " has reached its maximum storage size."}; } if (stat.isDraining) { @@ -299,11 +298,10 @@ vector<MigrateInfo> BalancerPolicy::balance(const ShardStatisticsVector& shardSt // migrations for the same shard. set<ShardId> usedShards; - // 1) Check for shards, which are in draining mode or are above the size limit and must have - // chunks moved off of them + // 1) Check for shards, which are in draining mode { for (const auto& stat : shardStats) { - if (!stat.isDraining && !stat.isSizeExceeded()) + if (!stat.isDraining) continue; if (usedShards.count(stat.shardId)) diff --git a/src/mongo/db/s/balancer/balancer_policy_test.cpp b/src/mongo/db/s/balancer/balancer_policy_test.cpp index 11fe57e133d..de5ceafaa83 100644 --- a/src/mongo/db/s/balancer/balancer_policy_test.cpp +++ b/src/mongo/db/s/balancer/balancer_policy_test.cpp @@ -408,22 +408,36 @@ TEST(BalancerPolicy, NoBalancingDueToAllNodesEitherDrainingOrMaxedOut) { ASSERT(migrations.empty()); } -TEST(BalancerPolicy, BalancerMovesChunksOffSizeMaxedShards) { +TEST(BalancerPolicy, BalancerRespectsMaxShardSizeOnlyBalanceToNonMaxed) { // Note that maxSize of shard0 is 1, and it is therefore overloaded with currSize = 3. Other // shards have maxSize = 0 = unset. Even though the overloaded shard has the least number of // less chunks, we shouldn't move chunks to that shard. auto cluster = generateCluster( {{ShardStatistics(kShardId0, 1, 3, false, emptyTagSet, emptyShardVersion), 2}, - {ShardStatistics(kShardId1, kNoMaxSize, 4, false, emptyTagSet, emptyShardVersion), 4}, - {ShardStatistics(kShardId2, kNoMaxSize, 6, false, emptyTagSet, emptyShardVersion), 6}}); + {ShardStatistics(kShardId1, kNoMaxSize, 5, false, emptyTagSet, emptyShardVersion), 5}, + {ShardStatistics(kShardId2, kNoMaxSize, 10, false, emptyTagSet, emptyShardVersion), 10}}); const auto migrations(BalancerPolicy::balance( cluster.first, DistributionStatus(kNamespace, cluster.second), false)); ASSERT_EQ(1U, migrations.size()); - ASSERT_EQ(kShardId0, migrations[0].from); + ASSERT_EQ(kShardId2, migrations[0].from); ASSERT_EQ(kShardId1, migrations[0].to); - ASSERT_BSONOBJ_EQ(cluster.second[kShardId0][0].getMin(), migrations[0].minKey); - ASSERT_BSONOBJ_EQ(cluster.second[kShardId0][0].getMax(), migrations[0].maxKey); + ASSERT_BSONOBJ_EQ(cluster.second[kShardId2][0].getMin(), migrations[0].minKey); + ASSERT_BSONOBJ_EQ(cluster.second[kShardId2][0].getMax(), migrations[0].maxKey); +} + +TEST(BalancerPolicy, BalancerRespectsMaxShardSizeWhenAllBalanced) { + // Note that maxSize of shard0 is 1, and it is therefore overloaded with currSize = 4. Other + // shards have maxSize = 0 = unset. We check that being over the maxSize is NOT equivalent to + // draining, we don't want to empty shards for no other reason than they are over this limit. + auto cluster = generateCluster( + {{ShardStatistics(kShardId0, 1, 4, false, emptyTagSet, emptyShardVersion), 4}, + {ShardStatistics(kShardId1, kNoMaxSize, 4, false, emptyTagSet, emptyShardVersion), 4}, + {ShardStatistics(kShardId2, kNoMaxSize, 4, false, emptyTagSet, emptyShardVersion), 4}}); + + const auto migrations(BalancerPolicy::balance( + cluster.first, DistributionStatus(kNamespace, cluster.second), false)); + ASSERT(migrations.empty()); } TEST(BalancerPolicy, BalancerRespectsTagsWhenDraining) { diff --git a/src/mongo/db/s/balancer/cluster_statistics.cpp b/src/mongo/db/s/balancer/cluster_statistics.cpp index 125f11d3551..d51b4ec4a24 100644 --- a/src/mongo/db/s/balancer/cluster_statistics.cpp +++ b/src/mongo/db/s/balancer/cluster_statistics.cpp @@ -60,14 +60,6 @@ bool ClusterStatistics::ShardStatistics::isSizeMaxed() const { return currSizeMB >= maxSizeMB; } -bool ClusterStatistics::ShardStatistics::isSizeExceeded() const { - if (!maxSizeMB || !currSizeMB) { - return false; - } - - return currSizeMB > maxSizeMB; -} - BSONObj ClusterStatistics::ShardStatistics::toBSON() const { BSONObjBuilder builder; builder.append("id", shardId.toString()); diff --git a/src/mongo/db/s/balancer/cluster_statistics.h b/src/mongo/db/s/balancer/cluster_statistics.h index 59435bb8dde..a4cfa52d1fb 100644 --- a/src/mongo/db/s/balancer/cluster_statistics.h +++ b/src/mongo/db/s/balancer/cluster_statistics.h @@ -71,12 +71,6 @@ public: bool isSizeMaxed() const; /** - * Returns true if a shard must be relieved (if possible) of some of the chunks it hosts - * because it has exceeded its per-shard data size limit. - */ - bool isSizeExceeded() const; - - /** * Returns BSON representation of this shard's statistics, for reporting purposes. */ BSONObj toBSON() const; |