diff options
Diffstat (limited to 'src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp')
-rw-r--r-- | src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp | 26 |
1 files changed, 12 insertions, 14 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 1cb8c5c3bda..a9b324eaaad 100644 --- a/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp +++ b/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp @@ -402,24 +402,22 @@ Status MigrationChunkClonerSourceLegacy::nextCloneBatch(OperationContext* txn, std::set<RecordId>::iterator it; for (it = _cloneLocs.begin(); it != _cloneLocs.end(); ++it) { - Snapshotted<BSONObj> doc; - if (!collection->findDoc(txn, *it, &doc)) { - // Document must have been deleted - continue; - } - - // Use the builder size instead of accumulating the document sizes directly so that we take - // into consideration the overhead of BSONArray indices, and *always* append at least one - // document. - if (arrBuilder->arrSize() && - (arrBuilder->len() + doc.value().objsize() + 1024) > BSONObjMaxUserSize) { + // We must always make progress in this method by at least one document because empty return + // indicates there is no more initial clone data. + if (arrBuilder->arrSize() && tracker.intervalHasElapsed()) { break; } - arrBuilder->append(doc.value()); + Snapshotted<BSONObj> doc; + if (collection->findDoc(txn, *it, &doc)) { + // Use the builder size instead of accumulating the document sizes directly so that we + // take into consideration the overhead of BSONArray indices. + if (arrBuilder->arrSize() && + (arrBuilder->len() + doc.value().objsize() + 1024) > BSONObjMaxUserSize) { + break; + } - if (tracker.intervalHasElapsed()) { - break; + arrBuilder->append(doc.value()); } } |