diff options
author | Benety Goh <benety@mongodb.com> | 2021-11-09 12:30:00 -0500 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-11-09 18:33:51 +0000 |
commit | d88b71c3d515043f1997afb0e89b9cbaf061fd61 (patch) | |
tree | ddf79d030bf23c857548cb28aa7b67337a73cbb3 | |
parent | 6b1562b7fa91472791399b6abd8b5365bad48680 (diff) | |
download | mongo-d88b71c3d515043f1997afb0e89b9cbaf061fd61.tar.gz |
SERVER-61159 add processCollModCommandForApplyOps()
This is used by applyCommand_inlock() to supply the current oplog application
mode to the collMod implementation.
-rw-r--r-- | src/mongo/db/catalog/coll_mod.cpp | 16 | ||||
-rw-r--r-- | src/mongo/db/catalog/coll_mod.h | 10 | ||||
-rw-r--r-- | src/mongo/db/catalog/coll_mod_index.cpp | 6 | ||||
-rw-r--r-- | src/mongo/db/catalog/coll_mod_index.h | 4 | ||||
-rw-r--r-- | src/mongo/db/repl/oplog.cpp | 3 |
5 files changed, 31 insertions, 8 deletions
diff --git a/src/mongo/db/catalog/coll_mod.cpp b/src/mongo/db/catalog/coll_mod.cpp index cbb6bcb5d97..90f4872d6af 100644 --- a/src/mongo/db/catalog/coll_mod.cpp +++ b/src/mongo/db/catalog/coll_mod.cpp @@ -473,7 +473,8 @@ void _setClusteredExpireAfterSeconds(OperationContext* opCtx, Status _collModInternal(OperationContext* opCtx, const NamespaceStringOrUUID& nsOrUUID, const CollMod& cmd, - BSONObjBuilder* result) { + BSONObjBuilder* result, + boost::optional<repl::OplogApplication::Mode> mode) { AutoGetCollection coll(opCtx, nsOrUUID, MODE_X, AutoGetCollectionViewMode::kViewsPermitted); auto nss = coll.getNss(); StringData dbName = nss.db(); @@ -615,7 +616,8 @@ Status _collModInternal(OperationContext* opCtx, } // Handle index modifications. - processCollModIndexRequest(opCtx, &coll, cmrNew.indexRequest, &indexCollModInfo, result); + processCollModIndexRequest( + opCtx, &coll, cmrNew.indexRequest, &indexCollModInfo, result, mode); if (cmrNew.collValidator) { coll.getWritableCollection()->setValidator(opCtx, *cmrNew.collValidator); @@ -704,7 +706,15 @@ Status processCollModCommand(OperationContext* opCtx, const NamespaceStringOrUUID& nsOrUUID, const CollMod& cmd, BSONObjBuilder* result) { - return _collModInternal(opCtx, nsOrUUID, cmd, result); + return _collModInternal(opCtx, nsOrUUID, cmd, result, boost::none); +} + +Status processCollModCommandForApplyOps(OperationContext* opCtx, + const NamespaceStringOrUUID& nsOrUUID, + const CollMod& cmd, + repl::OplogApplication::Mode mode) { + BSONObjBuilder resultWeDontCareAbout; + return _collModInternal(opCtx, nsOrUUID, cmd, &resultWeDontCareAbout, mode); } } // namespace mongo diff --git a/src/mongo/db/catalog/coll_mod.h b/src/mongo/db/catalog/coll_mod.h index 17a5d90f2d8..f08aca11444 100644 --- a/src/mongo/db/catalog/coll_mod.h +++ b/src/mongo/db/catalog/coll_mod.h @@ -31,6 +31,7 @@ #include "mongo/base/status_with.h" #include "mongo/db/catalog/collection_options.h" #include "mongo/db/coll_mod_gen.h" +#include "mongo/db/repl/oplog.h" namespace mongo { class BSONObj; @@ -54,4 +55,13 @@ Status processCollModCommand(OperationContext* opCtx, const CollMod& cmd, BSONObjBuilder* result); +/** + * Performs the collection modification described in "cmd" on the collection "ns". Only checks for + * duplicates for the 'applyOps' command. + */ +Status processCollModCommandForApplyOps(OperationContext* opCtx, + const NamespaceStringOrUUID& nsOrUUID, + const CollMod& cmd, + repl::OplogApplication::Mode mode); + } // namespace mongo diff --git a/src/mongo/db/catalog/coll_mod_index.cpp b/src/mongo/db/catalog/coll_mod_index.cpp index 31207f38d3e..9eda9848fb3 100644 --- a/src/mongo/db/catalog/coll_mod_index.cpp +++ b/src/mongo/db/catalog/coll_mod_index.cpp @@ -143,6 +143,7 @@ void _processCollModIndexRequestHidden(OperationContext* opCtx, void _processCollModIndexRequestUnique(OperationContext* opCtx, AutoGetCollection* autoColl, const IndexDescriptor* idx, + boost::optional<repl::OplogApplication::Mode> mode, BSONElement indexUnique, BSONElement* newUnique) { // Do not update catalog if index is already unique. @@ -159,7 +160,8 @@ void processCollModIndexRequest(OperationContext* opCtx, AutoGetCollection* autoColl, const CollModIndexRequest& collModIndexRequest, boost::optional<IndexCollModInfo>* indexCollModInfo, - BSONObjBuilder* result) { + BSONObjBuilder* result, + boost::optional<repl::OplogApplication::Mode> mode) { auto idx = collModIndexRequest.idx; auto indexExpireAfterSeconds = collModIndexRequest.indexExpireAfterSeconds; auto indexHidden = collModIndexRequest.indexHidden; @@ -191,7 +193,7 @@ void processCollModIndexRequest(OperationContext* opCtx, // User wants to convert an index to be unique. if (indexUnique) { - _processCollModIndexRequestUnique(opCtx, autoColl, idx, indexUnique, &newUnique); + _processCollModIndexRequestUnique(opCtx, autoColl, idx, mode, indexUnique, &newUnique); } *indexCollModInfo = IndexCollModInfo{ diff --git a/src/mongo/db/catalog/coll_mod_index.h b/src/mongo/db/catalog/coll_mod_index.h index 83b30138dac..ba6b7d64406 100644 --- a/src/mongo/db/catalog/coll_mod_index.h +++ b/src/mongo/db/catalog/coll_mod_index.h @@ -33,6 +33,7 @@ #include "mongo/db/index/index_descriptor.h" #include "mongo/db/op_observer.h" #include "mongo/db/operation_context.h" +#include "mongo/db/repl/oplog.h" namespace mongo { @@ -61,6 +62,7 @@ void processCollModIndexRequest(OperationContext* opCtx, AutoGetCollection* autoColl, const CollModIndexRequest& collModIndexRequest, boost::optional<IndexCollModInfo>* indexCollModInfo, - BSONObjBuilder* result); + BSONObjBuilder* result, + boost::optional<repl::OplogApplication::Mode> mode); } // namespace mongo diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp index 7f612d4865d..df142f4a773 100644 --- a/src/mongo/db/repl/oplog.cpp +++ b/src/mongo/db/repl/oplog.cpp @@ -928,8 +928,7 @@ const StringMap<ApplyOpMetadata> kOpsMap = { return {collModCmd.getDbName().toString(), *entry.getUuid()}; }()); - BSONObjBuilder resultWeDontCareAbout; - return processCollModCommand(opCtx, nssOrUUID, collModCmd, &resultWeDontCareAbout); + return processCollModCommandForApplyOps(opCtx, nssOrUUID, collModCmd, mode); }, {ErrorCodes::IndexNotFound, ErrorCodes::NamespaceNotFound}}}, {"dbCheck", {dbCheckOplogCommand, {}}}, |