Skip to content

Commit 09d31a1

Browse files
Marcos José Grillo Ramírezevergreen
authored andcommitted
SERVER-43103 fix divison by zero when moving extremely small chunks
1 parent 7264dd0 commit 09d31a1

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,12 @@ Status MigrationChunkClonerSourceLegacy::_storeCurrentLocs(OperationContext* opC
778778
const long long totalRecs = collection->numRecords(opCtx);
779779
if (totalRecs > 0) {
780780
avgRecSize = collection->dataSize(opCtx) / totalRecs;
781+
// The calls to numRecords() and dataSize() are not atomic so it is possible that the data
782+
// size becomes smaller than the number of records between the two calls, which would result
783+
// in average record size of zero
784+
if (avgRecSize == 0) {
785+
avgRecSize = BSONObj::kMinBSONLength;
786+
}
781787
maxRecsWhenFull = _args.getMaxChunkSizeBytes() / avgRecSize;
782788
maxRecsWhenFull = 130 * maxRecsWhenFull / 100; // pad some slack
783789
} else {

0 commit comments

Comments
 (0)