diff options
Diffstat (limited to 'src/mongo/db/s/balancer/balancer.cpp')
-rw-r--r-- | src/mongo/db/s/balancer/balancer.cpp | 110 |
1 files changed, 72 insertions, 38 deletions
diff --git a/src/mongo/db/s/balancer/balancer.cpp b/src/mongo/db/s/balancer/balancer.cpp index 25109941176..212b6d79713 100644 --- a/src/mongo/db/s/balancer/balancer.cpp +++ b/src/mongo/db/s/balancer/balancer.cpp @@ -46,6 +46,7 @@ #include "mongo/db/s/balancer/balancer_chunk_selection_policy_impl.h" #include "mongo/db/s/balancer/cluster_statistics_impl.h" #include "mongo/db/s/sharding_logging.h" +#include "mongo/logv2/log.h" #include "mongo/s/balancer_configuration.h" #include "mongo/s/catalog/type_chunk.h" #include "mongo/s/catalog_cache.h" @@ -157,7 +158,7 @@ void warnOnMultiVersion(const vector<ClusterStatistics::ShardStatistics>& cluste sb << stat.shardId << " is at " << stat.mongoVersion << "; "; } - warning() << sb.str(); + LOGV2_WARNING(21875, "{sb_str}", "sb_str"_attr = sb.str()); } } // namespace @@ -247,7 +248,10 @@ Status Balancer::rebalanceSingleChunk(OperationContext* opCtx, const ChunkType& auto migrateInfo = std::move(migrateStatus.getValue()); if (!migrateInfo) { - LOG(1) << "Unable to find more appropriate location for chunk " << redact(chunk.toString()); + LOGV2_DEBUG(21854, + 1, + "Unable to find more appropriate location for chunk {chunk}", + "chunk"_attr = redact(chunk.toString())); return Status::OK(); } @@ -307,14 +311,14 @@ void Balancer::_mainThread() { _state = kStopped; _joinCond.notify_all(); - LOG(1) << "Balancer thread terminated"; + LOGV2_DEBUG(21855, 1, "Balancer thread terminated"); }); Client::initThread("Balancer"); auto opCtx = cc().makeOperationContext(); auto shardingContext = Grid::get(opCtx.get()); - log() << "CSRS balancer is starting"; + LOGV2(21856, "CSRS balancer is starting"); { stdx::lock_guard<Latch> scopedLock(_mutex); @@ -327,9 +331,13 @@ void Balancer::_mainThread() { while (!_stopRequested()) { Status refreshStatus = balancerConfig->refreshAndCheck(opCtx.get()); if (!refreshStatus.isOK()) { - warning() << "Balancer settings could not be loaded and will be retried in " - << durationCount<Seconds>(kInitBackoffInterval) << " seconds" - << causedBy(refreshStatus); + LOGV2_WARNING( + 21876, + "Balancer settings could not be loaded and will be retried in " + "{durationCount_Seconds_kInitBackoffInterval} seconds{causedBy_refreshStatus}", + "durationCount_Seconds_kInitBackoffInterval"_attr = + durationCount<Seconds>(kInitBackoffInterval), + "causedBy_refreshStatus"_attr = causedBy(refreshStatus)); _sleepFor(opCtx.get(), kInitBackoffInterval); continue; @@ -338,13 +346,13 @@ void Balancer::_mainThread() { break; } - log() << "CSRS balancer thread is recovering"; + LOGV2(21857, "CSRS balancer thread is recovering"); _migrationManager.finishRecovery(opCtx.get(), balancerConfig->getMaxChunkSizeBytes(), balancerConfig->getSecondaryThrottle()); - log() << "CSRS balancer thread is recovered"; + LOGV2(21858, "CSRS balancer thread is recovered"); // Main balancer loop while (!_stopRequested()) { @@ -359,22 +367,28 @@ void Balancer::_mainThread() { Status refreshStatus = balancerConfig->refreshAndCheck(opCtx.get()); if (!refreshStatus.isOK()) { - warning() << "Skipping balancing round" << causedBy(refreshStatus); + LOGV2_WARNING(21877, + "Skipping balancing round{causedBy_refreshStatus}", + "causedBy_refreshStatus"_attr = causedBy(refreshStatus)); _endRound(opCtx.get(), kBalanceRoundDefaultInterval); continue; } if (!balancerConfig->shouldBalance()) { - LOG(1) << "Skipping balancing round because balancing is disabled"; + LOGV2_DEBUG(21859, 1, "Skipping balancing round because balancing is disabled"); _endRound(opCtx.get(), kBalanceRoundDefaultInterval); continue; } { - LOG(1) << "*** start balancing round. " - << "waitForDelete: " << balancerConfig->waitForDelete() - << ", secondaryThrottle: " - << balancerConfig->getSecondaryThrottle().toBSON(); + LOGV2_DEBUG( + 21860, + 1, + "*** start balancing round. waitForDelete: {balancerConfig_waitForDelete}, " + "secondaryThrottle: {balancerConfig_getSecondaryThrottle}", + "balancerConfig_waitForDelete"_attr = balancerConfig->waitForDelete(), + "balancerConfig_getSecondaryThrottle"_attr = + balancerConfig->getSecondaryThrottle().toBSON()); static Occasionally sampler; if (sampler.tick()) { @@ -383,16 +397,18 @@ void Balancer::_mainThread() { Status status = _enforceTagRanges(opCtx.get()); if (!status.isOK()) { - warning() << "Failed to enforce tag ranges" << causedBy(status); + LOGV2_WARNING(21878, + "Failed to enforce tag ranges{causedBy_status}", + "causedBy_status"_attr = causedBy(status)); } else { - LOG(1) << "Done enforcing tag range boundaries."; + LOGV2_DEBUG(21861, 1, "Done enforcing tag range boundaries."); } const auto candidateChunks = uassertStatusOK(_chunkSelectionPolicy->selectChunksToMove(opCtx.get())); if (candidateChunks.empty()) { - LOG(1) << "no need to move any chunk"; + LOGV2_DEBUG(21862, 1, "no need to move any chunk"); _balancedLastTime = 0; } else { _balancedLastTime = _moveChunks(opCtx.get(), candidateChunks); @@ -405,7 +421,7 @@ void Balancer::_mainThread() { .ignore(); } - LOG(1) << "*** End of balancing round"; + LOGV2_DEBUG(21863, 1, "*** End of balancing round"); } Milliseconds balancerInterval = @@ -413,16 +429,19 @@ void Balancer::_mainThread() { overrideBalanceRoundInterval.execute([&](const BSONObj& data) { balancerInterval = Milliseconds(data["intervalMs"].numberInt()); - log() << "overrideBalanceRoundInterval: using shorter balancing interval: " - << balancerInterval; + LOGV2(21864, + "overrideBalanceRoundInterval: using shorter balancing interval: " + "{balancerInterval}", + "balancerInterval"_attr = balancerInterval); }); _endRound(opCtx.get(), balancerInterval); } catch (const DBException& e) { - log() << "caught exception while doing balance: " << e.what(); + LOGV2( + 21865, "caught exception while doing balance: {e_what}", "e_what"_attr = e.what()); // Just to match the opening statement if in log level 1 - LOG(1) << "*** End of balancing round"; + LOGV2_DEBUG(21866, 1, "*** End of balancing round"); // This round failed, tell the world! roundDetails.setFailed(e.what()); @@ -451,7 +470,7 @@ void Balancer::_mainThread() { _threadOperationContext = nullptr; } - log() << "CSRS balancer is now stopped"; + LOGV2(21867, "CSRS balancer is now stopped"); } bool Balancer::_stopRequested() { @@ -516,8 +535,11 @@ bool Balancer::_checkOIDs(OperationContext* opCtx) { if (oids.count(x) == 0) { oids[x] = shardId; } else { - log() << "error: 2 machines have " << x << " as oid machine piece: " << shardId - << " and " << oids[x]; + LOGV2(21868, + "error: 2 machines have {x} as oid machine piece: {shardId} and {oids_x}", + "x"_attr = x, + "shardId"_attr = shardId, + "oids_x"_attr = oids[x]); result = uassertStatusOK(s->runCommandWithFixedRetryAttempts( opCtx, @@ -542,7 +564,7 @@ bool Balancer::_checkOIDs(OperationContext* opCtx) { return false; } } else { - log() << "warning: oidMachine not set on: " << s->toString(); + LOGV2(21869, "warning: oidMachine not set on: {s}", "s"_attr = s->toString()); } } @@ -574,8 +596,11 @@ Status Balancer::_enforceTagRanges(OperationContext* opCtx) { ChunkRange(splitInfo.minKey, splitInfo.maxKey), splitInfo.splitKeys); if (!splitStatus.isOK()) { - warning() << "Failed to enforce tag range for chunk " << redact(splitInfo.toString()) - << causedBy(redact(splitStatus.getStatus())); + LOGV2_WARNING( + 21879, + "Failed to enforce tag range for chunk {splitInfo}{causedBy_splitStatus_getStatus}", + "splitInfo"_attr = redact(splitInfo.toString()), + "causedBy_splitStatus_getStatus"_attr = causedBy(redact(splitStatus.getStatus()))); } } @@ -588,7 +613,7 @@ int Balancer::_moveChunks(OperationContext* opCtx, // If the balancer was disabled since we started this round, don't start new chunk moves if (_stopRequested() || !balancerConfig->shouldBalance()) { - LOG(1) << "Skipping balancing round because balancer was stopped"; + LOGV2_DEBUG(21870, 1, "Skipping balancing round because balancer was stopped"); return 0; } @@ -626,15 +651,20 @@ int Balancer::_moveChunks(OperationContext* opCtx, if (status == ErrorCodes::ChunkTooBig || status == ErrorCodes::ExceededMemoryLimit) { numChunksProcessed++; - log() << "Performing a split because migration " << redact(requestIt->toString()) - << " failed for size reasons" << causedBy(redact(status)); + LOGV2(21871, + "Performing a split because migration {requestIt} failed for size " + "reasons{causedBy_status}", + "requestIt"_attr = redact(requestIt->toString()), + "causedBy_status"_attr = causedBy(redact(status))); _splitOrMarkJumbo(opCtx, requestIt->nss, requestIt->minKey); continue; } - log() << "Balancer move " << redact(requestIt->toString()) << " failed" - << causedBy(redact(status)); + LOGV2(21872, + "Balancer move {requestIt} failed{causedBy_status}", + "requestIt"_attr = redact(requestIt->toString()), + "causedBy_status"_attr = causedBy(redact(status))); } return numChunksProcessed; @@ -660,7 +690,8 @@ void Balancer::_splitOrMarkJumbo(OperationContext* opCtx, boost::none)); if (splitPoints.empty()) { - log() << "Marking chunk " << redact(chunk.toString()) << " as jumbo."; + LOGV2( + 21873, "Marking chunk {chunk} as jumbo.", "chunk"_attr = redact(chunk.toString())); chunk.markAsJumbo(); auto status = Grid::get(opCtx)->catalogClient()->updateConfigDocument( @@ -671,9 +702,12 @@ void Balancer::_splitOrMarkJumbo(OperationContext* opCtx, false, ShardingCatalogClient::kMajorityWriteConcern); if (!status.isOK()) { - log() << "Couldn't set jumbo for chunk with namespace " << redact(nss.ns()) - << " and min key " << redact(chunk.getMin()) - << causedBy(redact(status.getStatus())); + LOGV2(21874, + "Couldn't set jumbo for chunk with namespace {nss_ns} and min key " + "{chunk_getMin}{causedBy_status_getStatus}", + "nss_ns"_attr = redact(nss.ns()), + "chunk_getMin"_attr = redact(chunk.getMin()), + "causedBy_status_getStatus"_attr = causedBy(redact(status.getStatus()))); } return; |