diff options
author | Benety Goh <benety@mongodb.com> | 2017-08-17 21:50:05 -0400 |
---|---|---|
committer | Benety Goh <benety@mongodb.com> | 2017-08-18 11:24:04 -0400 |
commit | 52007c747ca483bba871c5c71684b18717222019 (patch) | |
tree | fc37b3a8ae79aa4544f01076428dc8b28a761ca6 | |
parent | 58649cdfda534881c1cbfb5a5cdbbaddf523a3e0 (diff) | |
download | mongo-52007c747ca483bba871c5c71684b18717222019.tar.gz |
SERVER-30212 add renameOpTime argument to renameCollectionForApplyOps()
This supports two phase drops for renameCollection when the target collection is
dropped (dropTarget=true).
-rw-r--r-- | src/mongo/db/catalog/rename_collection.cpp | 8 | ||||
-rw-r--r-- | src/mongo/db/catalog/rename_collection.h | 10 | ||||
-rw-r--r-- | src/mongo/db/repl/oplog.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/repl/rs_rollback.cpp | 6 |
4 files changed, 18 insertions, 8 deletions
diff --git a/src/mongo/db/catalog/rename_collection.cpp b/src/mongo/db/catalog/rename_collection.cpp index a90bad18e89..71dd05aca2b 100644 --- a/src/mongo/db/catalog/rename_collection.cpp +++ b/src/mongo/db/catalog/rename_collection.cpp @@ -76,6 +76,7 @@ Status renameCollectionCommon(OperationContext* opCtx, const NamespaceString& source, const NamespaceString& target, OptionalCollectionUUID targetUUID, + repl::OpTime renameOpTimeFromApplyOps, const RenameCollectionOptions& options) { DisableDocumentValidation validationDisabler(opCtx); @@ -349,14 +350,15 @@ Status renameCollection(OperationContext* opCtx, const NamespaceString& target, const RenameCollectionOptions& options) { OptionalCollectionUUID noTargetUUID; - return renameCollectionCommon(opCtx, source, target, noTargetUUID, options); + return renameCollectionCommon(opCtx, source, target, noTargetUUID, {}, options); } Status renameCollectionForApplyOps(OperationContext* opCtx, const std::string& dbName, const BSONElement& ui, - const BSONObj& cmd) { + const BSONObj& cmd, + const repl::OpTime& renameOpTime) { const auto sourceNsElt = cmd.firstElement(); const auto targetNsElt = cmd["to"]; @@ -412,6 +414,6 @@ Status renameCollectionForApplyOps(OperationContext* opCtx, RenameCollectionOptions options; options.dropTarget = cmd["dropTarget"].trueValue(); options.stayTemp = cmd["stayTemp"].trueValue(); - return renameCollectionCommon(opCtx, sourceNss, targetNss, targetUUID, options); + return renameCollectionCommon(opCtx, sourceNss, targetNss, targetUUID, renameOpTime, options); } } // namespace mongo diff --git a/src/mongo/db/catalog/rename_collection.h b/src/mongo/db/catalog/rename_collection.h index 03ab05b76d1..69e29a5ee27 100644 --- a/src/mongo/db/catalog/rename_collection.h +++ b/src/mongo/db/catalog/rename_collection.h @@ -34,6 +34,10 @@ namespace mongo { class NamespaceString; class OperationContext; +namespace repl { +class OpTime; +} // namespace repl + /** * Renames the collection "source" to "target" and drops the existing collection named "target" * iff "dropTarget" is true. "stayTemp" indicates whether a collection should maintain its @@ -51,10 +55,14 @@ Status renameCollection(OperationContext* opCtx, /** * As above, but may only be called from applyCommand_inlock. This allows creating a collection * with a specific UUID for cross-database renames. + * + * When 'cmd' contains dropTarget=true, 'renameOpTime' is used to rename the target collection to a + * drop-pending collection. */ Status renameCollectionForApplyOps(OperationContext* opCtx, const std::string& dbName, const BSONElement& ui, - const BSONObj& cmd); + const BSONObj& cmd, + const repl::OpTime& renameOpTime); } // namespace mongo diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp index f22cc9a8ede..3aead459d1d 100644 --- a/src/mongo/db/repl/oplog.cpp +++ b/src/mongo/db/repl/oplog.cpp @@ -826,7 +826,7 @@ std::map<std::string, ApplyOpMetadata> opsMap = { const BSONElement& ui, BSONObj& cmd, const OpTime& opTime) -> Status { - return renameCollectionForApplyOps(opCtx, nsToDatabase(ns), ui, cmd); + return renameCollectionForApplyOps(opCtx, nsToDatabase(ns), ui, cmd, opTime); }, {ErrorCodes::NamespaceNotFound, ErrorCodes::NamespaceExists}}}, {"applyOps", diff --git a/src/mongo/db/repl/rs_rollback.cpp b/src/mongo/db/repl/rs_rollback.cpp index a6ac87e169a..8daad87bd8b 100644 --- a/src/mongo/db/repl/rs_rollback.cpp +++ b/src/mongo/db/repl/rs_rollback.cpp @@ -812,7 +812,7 @@ void renameOutOfTheWay(OperationContext* opCtx, RenameCollectionInfo info, Datab // Renaming the collection that was clashing with the attempted rename // operation to a different collection name. auto renameStatus = renameCollectionForApplyOps( - opCtx, db->name(), tempRenameCollUUID.getField("uuid"), tempRenameCmd.obj()); + opCtx, db->name(), tempRenameCollUUID.getField("uuid"), tempRenameCmd.obj(), {}); if (!renameStatus.isOK()) { severe() << "Unable to rename collection " << info.renameTo << " out of the way to " @@ -839,7 +839,7 @@ void rollbackRenameCollection(OperationContext* opCtx, UUID uuid, RenameCollecti cmd.append("dropTarget", false); BSONObj obj = cmd.obj(); - auto status = renameCollectionForApplyOps(opCtx, dbName, ui.getField("uuid"), obj); + auto status = renameCollectionForApplyOps(opCtx, dbName, ui.getField("uuid"), obj, {}); // If we try to roll back a collection to a collection name that currently exists // because another collection was renamed or created with the same collection name, @@ -850,7 +850,7 @@ void rollbackRenameCollection(OperationContext* opCtx, UUID uuid, RenameCollecti // Retrying to renameCollection command again now that the conflicting // collection has been renamed out of the way. - status = renameCollectionForApplyOps(opCtx, dbName, ui.getField("uuid"), obj); + status = renameCollectionForApplyOps(opCtx, dbName, ui.getField("uuid"), obj, {}); if (!status.isOK()) { severe() << "Rename collection failed to roll back twice. We were unable to rename " |