diff options
-rw-r--r-- | src/mongo/db/s/shardsvr_get_stats_for_balancing_command.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/mongo/db/s/shardsvr_get_stats_for_balancing_command.cpp b/src/mongo/db/s/shardsvr_get_stats_for_balancing_command.cpp index 12dee9c12da..95459b8a827 100644 --- a/src/mongo/db/s/shardsvr_get_stats_for_balancing_command.cpp +++ b/src/mongo/db/s/shardsvr_get_stats_for_balancing_command.cpp @@ -125,7 +125,12 @@ public: return BalancerStatsRegistry::get(opCtx)->getCollNumOrphanDocs(*collUUID); }(); - invariant(numRecords >= numOrphanDocs); + if (numRecords <= numOrphanDocs) { + // The number of records and the number of orphans documents are not updated + // atomically, therefore it could totally happen that the total number of records is + // less than the total number of orphans. + return 0LL; + } const auto avgObjSizeBytes = static_cast<long long>(dataSizeBytes / numRecords); return avgObjSizeBytes * (numRecords - numOrphanDocs); |