diff options
author | Gregory Wlodarek <gregory.wlodarek@mongodb.com> | 2020-10-16 18:06:50 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-10-16 23:28:47 +0000 |
commit | e8c373424c6bd0460198b9a94936369e0a83b6f5 (patch) | |
tree | bfe6ca6b4c6a29aa3a9a3e590dea8d03bc524de9 | |
parent | e1363299a93f53ebbff4a24f11e5d132e25a5c40 (diff) | |
download | mongo-e8c373424c6bd0460198b9a94936369e0a83b6f5.tar.gz |
SERVER-45354 In renameCollectionAcrossDBs, writes to temporary collection must use correct timestamps
-rw-r--r-- | src/mongo/db/catalog/rename_collection.cpp | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/mongo/db/catalog/rename_collection.cpp b/src/mongo/db/catalog/rename_collection.cpp index 44c3b57ec9e..480dc086a8b 100644 --- a/src/mongo/db/catalog/rename_collection.cpp +++ b/src/mongo/db/catalog/rename_collection.cpp @@ -705,12 +705,12 @@ Status renameBetweenDBs(OperationContext* opCtx, // Cursor is left one past the end of the batch inside writeConflictRetry. auto beginBatchId = record->id; status = writeConflictRetry(opCtx, "renameCollection", tmpName.ns(), [&] { - WriteUnitOfWork wunit(opCtx); // Need to reset cursor if it gets a WCE midway through. if (!record || (beginBatchId != record->id)) { record = cursor->seekExact(beginBatchId); } for (int i = 0; record && (i < internalInsertMaxBatchSize.load()); i++) { + WriteUnitOfWork wunit(opCtx); const InsertStatement stmt(record->data.releaseToBson()); OpDebug* const opDebug = nullptr; auto status = tmpColl->insertDocument(opCtx, stmt, opDebug, true); @@ -718,6 +718,12 @@ Status renameBetweenDBs(OperationContext* opCtx, return status; } record = cursor->next(); + + // Used to make sure that a WCE can be handled by this logic without data loss. + if (MONGO_FAIL_POINT(writeConflictInRenameCollCopyToTmp)) { + throw WriteConflictException(); + } + wunit.commit(); } // Time to yield; make a safe copy of the current record before releasing our @@ -731,11 +737,6 @@ Status renameBetweenDBs(OperationContext* opCtx, writeConflictRetry( opCtx, "retryRestoreCursor", ns, [&cursor] { cursor->restore(); }); }); - // Used to make sure that a WCE can be handled by this logic without data loss. - if (MONGO_FAIL_POINT(writeConflictInRenameCollCopyToTmp)) { - throw WriteConflictException(); - } - wunit.commit(); return Status::OK(); }); if (!status.isOK()) |