summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Wlodarek <gregory.wlodarek@mongodb.com>2020-10-08 22:21:54 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-10-09 04:04:41 +0000
commitf955f22b43229a73ff788127bd37ce651ad6f75e (patch)
tree784349809086ed92ef5107599ccae5b364906f8f
parent4a3557f4532014ed82b00d3ea0419e73d7fa80fd (diff)
downloadmongo-f955f22b43229a73ff788127bd37ce651ad6f75e.tar.gz
SERVER-45354 In renameCollectionAcrossDBs, writes to temporary collection must use correct timestamps
-rw-r--r--src/mongo/db/catalog/rename_collection.cpp13
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 4719e38eb31..70bddf8dbcb 100644
--- a/src/mongo/db/catalog/rename_collection.cpp
+++ b/src/mongo/db/catalog/rename_collection.cpp
@@ -696,12 +696,12 @@ Status renameBetweenDBs(OperationContext* opCtx,
// Cursor is left one past the end of the batch inside writeConflictRetry.
auto beginBatchId = record->id;
Status 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);
@@ -709,6 +709,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_unlikely(writeConflictInRenameCollCopyToTmp.shouldFail())) {
+ throw WriteConflictException();
+ }
+ wunit.commit();
}
// Time to yield; make a safe copy of the current record before releasing our
@@ -722,11 +728,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_unlikely(writeConflictInRenameCollCopyToTmp.shouldFail())) {
- throw WriteConflictException();
- }
- wunit.commit();
return Status::OK();
});
if (!status.isOK())