diff options
Diffstat (limited to 'src/mongo/db/s/balancer/balancer_policy.cpp')
-rw-r--r-- | src/mongo/db/s/balancer/balancer_policy.cpp | 83 |
1 files changed, 58 insertions, 25 deletions
diff --git a/src/mongo/db/s/balancer/balancer_policy.cpp b/src/mongo/db/s/balancer/balancer_policy.cpp index 022379992f0..44e3f1302b5 100644 --- a/src/mongo/db/s/balancer/balancer_policy.cpp +++ b/src/mongo/db/s/balancer/balancer_policy.cpp @@ -36,6 +36,7 @@ #include <random> #include "mongo/db/s/balancer/type_migration.h" +#include "mongo/logv2/log.h" #include "mongo/s/catalog/type_shard.h" #include "mongo/s/catalog/type_tags.h" #include "mongo/util/fail_point.h" @@ -342,8 +343,11 @@ MigrateInfo chooseRandomMigration(const ShardStatisticsVector& shardStats, const int destIndex = indices[choice]; const auto& destShardId = shardStats[destIndex].shardId; - LOG(1) << "balancerShouldReturnRandomMigrations: source: " << sourceShardId - << " dest: " << destShardId; + LOGV2_DEBUG(21880, + 1, + "balancerShouldReturnRandomMigrations: source: {sourceShardId} dest: {destShardId}", + "sourceShardId"_attr = sourceShardId, + "destShardId"_attr = destShardId); const auto& chunks = distribution.getChunks(sourceShardId); @@ -361,7 +365,7 @@ vector<MigrateInfo> BalancerPolicy::balance(const ShardStatisticsVector& shardSt if (MONGO_unlikely(balancerShouldReturnRandomMigrations.shouldFail()) && !distribution.nss().isConfigDB()) { - LOG(1) << "balancerShouldReturnRandomMigrations failpoint is set"; + LOGV2_DEBUG(21881, 1, "balancerShouldReturnRandomMigrations failpoint is set"); if (shardStats.size() < 2) return migrations; @@ -402,8 +406,10 @@ vector<MigrateInfo> BalancerPolicy::balance(const ShardStatisticsVector& shardSt _getLeastLoadedReceiverShard(shardStats, distribution, tag, *usedShards); if (!to.isValid()) { if (migrations.empty()) { - warning() << "Chunk " << redact(chunk.toString()) - << " is on a draining shard, but no appropriate recipient found"; + LOGV2_WARNING(21889, + "Chunk {chunk} is on a draining shard, but no appropriate " + "recipient found", + "chunk"_attr = redact(chunk.toString())); } continue; } @@ -417,8 +423,11 @@ vector<MigrateInfo> BalancerPolicy::balance(const ShardStatisticsVector& shardSt } if (migrations.empty()) { - warning() << "Unable to find any chunk to move from draining shard " << stat.shardId - << ". numJumboChunks: " << numJumboChunks; + LOGV2_WARNING(21890, + "Unable to find any chunk to move from draining shard " + "{stat_shardId}. numJumboChunks: {numJumboChunks}", + "stat_shardId"_attr = stat.shardId, + "numJumboChunks"_attr = numJumboChunks); } } } @@ -441,8 +450,11 @@ vector<MigrateInfo> BalancerPolicy::balance(const ShardStatisticsVector& shardSt continue; if (chunk.getJumbo()) { - warning() << "Chunk " << redact(chunk.toString()) << " violates zone " - << redact(tag) << ", but it is jumbo and cannot be moved"; + LOGV2_WARNING( + 21891, + "Chunk {chunk} violates zone {tag}, but it is jumbo and cannot be moved", + "chunk"_attr = redact(chunk.toString()), + "tag"_attr = redact(tag)); continue; } @@ -450,8 +462,11 @@ vector<MigrateInfo> BalancerPolicy::balance(const ShardStatisticsVector& shardSt _getLeastLoadedReceiverShard(shardStats, distribution, tag, *usedShards); if (!to.isValid()) { if (migrations.empty()) { - warning() << "Chunk " << redact(chunk.toString()) << " violates zone " - << redact(tag) << ", but no appropriate recipient found"; + LOGV2_WARNING( + 21892, + "Chunk {chunk} violates zone {tag}, but no appropriate recipient found", + "chunk"_attr = redact(chunk.toString()), + "tag"_attr = redact(tag)); } continue; } @@ -490,10 +505,14 @@ vector<MigrateInfo> BalancerPolicy::balance(const ShardStatisticsVector& shardSt // should not be possible so warn the operator to correct it. if (totalNumberOfShardsWithTag == 0) { if (!tag.empty()) { - warning() << "Zone " << redact(tag) << " in collection " << distribution.nss() - << " has no assigned shards and chunks which fall into it cannot be " - "balanced. This should be corrected by either assigning shards to the " - "zone or by deleting it."; + LOGV2_WARNING( + 21893, + "Zone {tag} in collection {distribution_nss} has no assigned shards and chunks " + "which fall into it cannot be " + "balanced. This should be corrected by either assigning shards to the " + "zone or by deleting it.", + "tag"_attr = redact(tag), + "distribution_nss"_attr = distribution.nss()); } continue; } @@ -552,7 +571,7 @@ bool BalancerPolicy::_singleZoneBalance(const ShardStatisticsVector& shardStats, const ShardId to = _getLeastLoadedReceiverShard(shardStats, distribution, tag, *usedShards); if (!to.isValid()) { if (migrations->empty()) { - log() << "No available shards to take chunks for zone [" << tag << "]"; + LOGV2(21882, "No available shards to take chunks for zone [{tag}]", "tag"_attr = tag); } return false; } @@ -565,12 +584,22 @@ bool BalancerPolicy::_singleZoneBalance(const ShardStatisticsVector& shardStats, const size_t imbalance = max - idealNumberOfChunksPerShardForTag; - LOG(1) << "collection : " << distribution.nss().ns(); - LOG(1) << "zone : " << tag; - LOG(1) << "donor : " << from << " chunks on " << max; - LOG(1) << "receiver : " << to << " chunks on " << min; - LOG(1) << "ideal : " << idealNumberOfChunksPerShardForTag; - LOG(1) << "threshold : " << kDefaultImbalanceThreshold; + LOGV2_DEBUG(21883, + 1, + "collection : {distribution_nss_ns}", + "distribution_nss_ns"_attr = distribution.nss().ns()); + LOGV2_DEBUG(21884, 1, "zone : {tag}", "tag"_attr = tag); + LOGV2_DEBUG( + 21885, 1, "donor : {from} chunks on {max}", "from"_attr = from, "max"_attr = max); + LOGV2_DEBUG(21886, 1, "receiver : {to} chunks on {min}", "to"_attr = to, "min"_attr = min); + LOGV2_DEBUG(21887, + 1, + "ideal : {idealNumberOfChunksPerShardForTag}", + "idealNumberOfChunksPerShardForTag"_attr = idealNumberOfChunksPerShardForTag); + LOGV2_DEBUG(21888, + 1, + "threshold : {kDefaultImbalanceThreshold}", + "kDefaultImbalanceThreshold"_attr = kDefaultImbalanceThreshold); // Check whether it is necessary to balance within this zone if (imbalance < kDefaultImbalanceThreshold) @@ -596,9 +625,13 @@ bool BalancerPolicy::_singleZoneBalance(const ShardStatisticsVector& shardStats, } if (numJumboChunks) { - warning() << "Shard: " << from << ", collection: " << distribution.nss().ns() - << " has only jumbo chunks for zone \'" << tag - << "\' and cannot be balanced. Jumbo chunks count: " << numJumboChunks; + LOGV2_WARNING(21894, + "Shard: {from}, collection: {distribution_nss_ns} has only jumbo chunks for " + "zone \'{tag}\' and cannot be balanced. Jumbo chunks count: {numJumboChunks}", + "from"_attr = from, + "distribution_nss_ns"_attr = distribution.nss().ns(), + "tag"_attr = tag, + "numJumboChunks"_attr = numJumboChunks); } return false; |