summaryrefslogtreecommitdiff
path: root/src/mongo/db/s
diff options
context:
space:
mode:
authorMarcos José Grillo Ramírez <marcos.grillo@10gen.com>2019-10-16 14:30:44 +0000
committerevergreen <evergreen@mongodb.com>2019-10-16 14:30:44 +0000
commit09d31a1231f42eb84057938d15a3bae333e75f39 (patch)
tree50368eeabd14b4c1928c7c30ad0b7342890b67ed /src/mongo/db/s
parent7264dd03a981ea9cc86dcdc073e7a6dedaa995af (diff)
downloadmongo-09d31a1231f42eb84057938d15a3bae333e75f39.tar.gz
SERVER-43103 fix divison by zero when moving extremely small chunks
Diffstat (limited to 'src/mongo/db/s')
-rw-r--r--src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp b/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp
index 7b891cf8e18..6a5ce99c1c7 100644
--- a/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp
+++ b/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp
@@ -778,6 +778,12 @@ Status MigrationChunkClonerSourceLegacy::_storeCurrentLocs(OperationContext* opC
const long long totalRecs = collection->numRecords(opCtx);
if (totalRecs > 0) {
avgRecSize = collection->dataSize(opCtx) / totalRecs;
+ // The calls to numRecords() and dataSize() are not atomic so it is possible that the data
+ // size becomes smaller than the number of records between the two calls, which would result
+ // in average record size of zero
+ if (avgRecSize == 0) {
+ avgRecSize = BSONObj::kMinBSONLength;
+ }
maxRecsWhenFull = _args.getMaxChunkSizeBytes() / avgRecSize;
maxRecsWhenFull = 130 * maxRecsWhenFull / 100; // pad some slack
} else {