diff options
author | Hugh Tong <hugh.tong@mongodb.com> | 2022-07-11 16:41:43 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-07-11 22:49:28 +0000 |
commit | d4f322da12a6a52b1f32c39187f04b961f8cf206 (patch) | |
tree | acf1df6c1f3f2546c74f7054371ad0ed4e639310 /src | |
parent | 9b821336550ba150374d78e10852d5d883e6f323 (diff) | |
download | mongo-d4f322da12a6a52b1f32c39187f04b961f8cf206.tar.gz |
SERVER-62781 Include tid in oplog entries for commands
Diffstat (limited to 'src')
30 files changed, 275 insertions, 81 deletions
diff --git a/src/mongo/db/auth/auth_op_observer.cpp b/src/mongo/db/auth/auth_op_observer.cpp index f7a77a7c2a6..922069978e7 100644 --- a/src/mongo/db/auth/auth_op_observer.cpp +++ b/src/mongo/db/auth/auth_op_observer.cpp @@ -127,7 +127,7 @@ void AuthOpObserver::onCollMod(OperationContext* opCtx, ->logOp(opCtx, "c", cmdNss, cmdObj, nullptr); } -void AuthOpObserver::onDropDatabase(OperationContext* opCtx, const std::string& dbName) { +void AuthOpObserver::onDropDatabase(OperationContext* opCtx, const DatabaseName& dbName) { const NamespaceString cmdNss{dbName, "$cmd"}; const auto cmdObj = BSON("dropDatabase" << 1); @@ -206,7 +206,7 @@ void AuthOpObserver::onImportCollection(OperationContext* opCtx, } void AuthOpObserver::onApplyOps(OperationContext* opCtx, - const std::string& dbName, + const DatabaseName& dbName, const BSONObj& applyOpCmd) { const NamespaceString cmdNss{dbName, "$cmd"}; diff --git a/src/mongo/db/auth/auth_op_observer.h b/src/mongo/db/auth/auth_op_observer.h index 4b2cfffae2b..480ee25ec79 100644 --- a/src/mongo/db/auth/auth_op_observer.h +++ b/src/mongo/db/auth/auth_op_observer.h @@ -122,7 +122,7 @@ public: const CollectionOptions& oldCollOptions, boost::optional<IndexCollModInfo> indexInfo) final; - void onDropDatabase(OperationContext* opCtx, const std::string& dbName) final; + void onDropDatabase(OperationContext* opCtx, const DatabaseName& dbName) final; using OpObserver::onDropCollection; repl::OpTime onDropCollection(OperationContext* opCtx, @@ -172,7 +172,7 @@ public: const boost::optional<UUID>& dropTargetUUID, bool stayTemp) final; void onApplyOps(OperationContext* opCtx, - const std::string& dbName, + const DatabaseName& dbName, const BSONObj& applyOpCmd) final; void onEmptyCapped(OperationContext* opCtx, diff --git a/src/mongo/db/catalog/drop_database.cpp b/src/mongo/db/catalog/drop_database.cpp index 634ecdec80b..929ac9fac96 100644 --- a/src/mongo/db/catalog/drop_database.cpp +++ b/src/mongo/db/catalog/drop_database.cpp @@ -104,7 +104,8 @@ void _finishDropDatabase(OperationContext* opCtx, writeConflictRetry(opCtx, "dropDatabase_database", dbName, [&] { WriteUnitOfWork wunit(opCtx); - opCtx->getServiceContext()->getOpObserver()->onDropDatabase(opCtx, dbName); + // TODO: SERVER-67549 pass the dbName directly + opCtx->getServiceContext()->getOpObserver()->onDropDatabase(opCtx, DatabaseName(dbName)); wunit.commit(); }); diff --git a/src/mongo/db/catalog/drop_database_test.cpp b/src/mongo/db/catalog/drop_database_test.cpp index 8ded03ceb48..0c9f6746fb1 100644 --- a/src/mongo/db/catalog/drop_database_test.cpp +++ b/src/mongo/db/catalog/drop_database_test.cpp @@ -66,7 +66,7 @@ using namespace mongo; */ class OpObserverMock : public OpObserverNoop { public: - void onDropDatabase(OperationContext* opCtx, const std::string& dbName) override; + void onDropDatabase(OperationContext* opCtx, const DatabaseName& dbName) override; using OpObserver::onDropCollection; repl::OpTime onDropCollection(OperationContext* opCtx, @@ -82,11 +82,12 @@ public: const repl::OpTime dropOpTime = {Timestamp(Seconds(100), 1U), 1LL}; }; -void OpObserverMock::onDropDatabase(OperationContext* opCtx, const std::string& dbName) { +void OpObserverMock::onDropDatabase(OperationContext* opCtx, const DatabaseName& dbName) { ASSERT_TRUE(opCtx->lockState()->inAWriteUnitOfWork()); OpObserverNoop::onDropDatabase(opCtx, dbName); // Do not update 'droppedDatabaseNames' if OpObserverNoop::onDropDatabase() throws. - droppedDatabaseNames.insert(dbName); + // TODO: SERVER-67549 to change droppedDatabaseNames to use DatabaseName + droppedDatabaseNames.insert(dbName.toStringWithTenantId()); } repl::OpTime OpObserverMock::onDropCollection(OperationContext* opCtx, diff --git a/src/mongo/db/free_mon/free_mon_op_observer.h b/src/mongo/db/free_mon/free_mon_op_observer.h index 4dce6801926..34a3312016a 100644 --- a/src/mongo/db/free_mon/free_mon_op_observer.h +++ b/src/mongo/db/free_mon/free_mon_op_observer.h @@ -122,7 +122,7 @@ public: const CollectionOptions& oldCollOptions, boost::optional<IndexCollModInfo> indexInfo) final {} - void onDropDatabase(OperationContext* opCtx, const std::string& dbName) final {} + void onDropDatabase(OperationContext* opCtx, const DatabaseName& dbName) final {} using OpObserver::onDropCollection; repl::OpTime onDropCollection(OperationContext* opCtx, @@ -172,7 +172,7 @@ public: const boost::optional<UUID>& dropTargetUUID, bool stayTemp) final {} void onApplyOps(OperationContext* opCtx, - const std::string& dbName, + const DatabaseName& dbName, const BSONObj& applyOpCmd) final {} void onEmptyCapped(OperationContext* opCtx, diff --git a/src/mongo/db/namespace_string.h b/src/mongo/db/namespace_string.h index efc7edc372c..3a1d3485de1 100644 --- a/src/mongo/db/namespace_string.h +++ b/src/mongo/db/namespace_string.h @@ -588,7 +588,7 @@ public: std::string getSisterNS(StringData local) const; NamespaceString getCommandNS() const { - return {db(), "$cmd"}; + return {dbName(), "$cmd"}; } void serializeCollectionName(BSONObjBuilder* builder, StringData fieldName) const; diff --git a/src/mongo/db/op_observer/fcv_op_observer.h b/src/mongo/db/op_observer/fcv_op_observer.h index 9db3f370d32..97f78535e8b 100644 --- a/src/mongo/db/op_observer/fcv_op_observer.h +++ b/src/mongo/db/op_observer/fcv_op_observer.h @@ -124,7 +124,7 @@ public: const BSONObj& collModCmd, const CollectionOptions& oldCollOptions, boost::optional<IndexCollModInfo> indexInfo) final {} - void onDropDatabase(OperationContext* opCtx, const std::string& dbName) final {} + void onDropDatabase(OperationContext* opCtx, const DatabaseName& dbName) final {} using OpObserver::onDropCollection; repl::OpTime onDropCollection(OperationContext* opCtx, const NamespaceString& collectionName, @@ -171,7 +171,7 @@ public: const boost::optional<UUID>& dropTargetUUID, bool stayTemp) final {} void onApplyOps(OperationContext* opCtx, - const std::string& dbName, + const DatabaseName& dbName, const BSONObj& applyOpCmd) final {} void onEmptyCapped(OperationContext* opCtx, const NamespaceString& collectionName, diff --git a/src/mongo/db/op_observer/op_observer.h b/src/mongo/db/op_observer/op_observer.h index ac8b04fb2f6..ae3b9bed594 100644 --- a/src/mongo/db/op_observer/op_observer.h +++ b/src/mongo/db/op_observer/op_observer.h @@ -267,7 +267,7 @@ public: const BSONObj& collModCmd, const CollectionOptions& oldCollOptions, boost::optional<IndexCollModInfo> indexInfo) = 0; - virtual void onDropDatabase(OperationContext* opCtx, const std::string& dbName) = 0; + virtual void onDropDatabase(OperationContext* opCtx, const DatabaseName& dbName) = 0; /** * This function logs an oplog entry when a 'drop' command on a collection is executed. @@ -378,7 +378,7 @@ public: bool isDryRun) = 0; virtual void onApplyOps(OperationContext* opCtx, - const std::string& dbName, + const DatabaseName& dbName, const BSONObj& applyOpCmd) = 0; virtual void onEmptyCapped(OperationContext* opCtx, const NamespaceString& collectionName, diff --git a/src/mongo/db/op_observer/op_observer_impl.cpp b/src/mongo/db/op_observer/op_observer_impl.cpp index e89853e92b6..7fda3408f05 100644 --- a/src/mongo/db/op_observer/op_observer_impl.cpp +++ b/src/mongo/db/op_observer/op_observer_impl.cpp @@ -52,6 +52,7 @@ #include "mongo/db/internal_transactions_feature_flag_gen.h" #include "mongo/db/keys_collection_document_gen.h" #include "mongo/db/logical_time_validator.h" +#include "mongo/db/multitenancy_gen.h" #include "mongo/db/namespace_string.h" #include "mongo/db/op_observer/op_observer_util.h" #include "mongo/db/operation_context.h" @@ -191,9 +192,7 @@ struct ImageBundle { OpTimeBundle replLogUpdate(OperationContext* opCtx, const OplogUpdateEntryArgs& args, MutableOplogEntry* oplogEntry) { - // TODO SERVER-62114 Change to check for upgraded FCV rather than feature flag - if (gFeatureFlagRequireTenantID.isEnabled(serverGlobalParams.featureCompatibility)) - oplogEntry->setTid(args.nss.tenantId()); + oplogEntry->setTid(args.nss.tenantId()); oplogEntry->setNss(args.nss); oplogEntry->setUuid(args.uuid); @@ -269,9 +268,7 @@ OpTimeBundle replLogDelete(OperationContext* opCtx, StmtId stmtId, bool fromMigrate, const boost::optional<BSONObj>& deletedDoc) { - // TODO SERVER-62114 Change to check for upgraded FCV rather than feature flag - if (gFeatureFlagRequireTenantID.isEnabled(serverGlobalParams.featureCompatibility)) - oplogEntry->setTid(nss.tenantId()); + oplogEntry->setTid(nss.tenantId()); oplogEntry->setNss(nss); oplogEntry->setUuid(uuid); oplogEntry->setDestinedRecipient(destinedRecipientDecoration(opCtx)); @@ -381,6 +378,8 @@ void OpObserverImpl::onCreateIndex(OperationContext* opCtx, MutableOplogEntry oplogEntry; oplogEntry.setOpType(repl::OpTypeEnum::kCommand); + + oplogEntry.setTid(nss.tenantId()); oplogEntry.setNss(nss.getCommandNS()); oplogEntry.setUuid(uuid); oplogEntry.setObject(builder.done()); @@ -408,6 +407,8 @@ void OpObserverImpl::onStartIndexBuild(OperationContext* opCtx, MutableOplogEntry oplogEntry; oplogEntry.setOpType(repl::OpTypeEnum::kCommand); + + oplogEntry.setTid(nss.tenantId()); oplogEntry.setNss(nss.getCommandNS()); oplogEntry.setUuid(collUUID); oplogEntry.setObject(oplogEntryBuilder.done()); @@ -471,6 +472,8 @@ void OpObserverImpl::onCommitIndexBuild(OperationContext* opCtx, MutableOplogEntry oplogEntry; oplogEntry.setOpType(repl::OpTypeEnum::kCommand); + + oplogEntry.setTid(nss.tenantId()); oplogEntry.setNss(nss.getCommandNS()); oplogEntry.setUuid(collUUID); oplogEntry.setObject(oplogEntryBuilder.done()); @@ -505,6 +508,8 @@ void OpObserverImpl::onAbortIndexBuild(OperationContext* opCtx, MutableOplogEntry oplogEntry; oplogEntry.setOpType(repl::OpTypeEnum::kCommand); + + oplogEntry.setTid(nss.tenantId()); oplogEntry.setNss(nss.getCommandNS()); oplogEntry.setUuid(collUUID); oplogEntry.setObject(oplogEntryBuilder.done()); @@ -604,9 +609,7 @@ void OpObserverImpl::onInserts(OperationContext* opCtx, }; MutableOplogEntry oplogEntryTemplate; - // TODO SERVER-62114 Change to check for upgraded FCV rather than feature flag - if (gFeatureFlagRequireTenantID.isEnabled(serverGlobalParams.featureCompatibility)) - oplogEntryTemplate.setTid(nss.tenantId()); + oplogEntryTemplate.setTid(nss.tenantId()); oplogEntryTemplate.setNss(nss); oplogEntryTemplate.setUuid(uuid); oplogEntryTemplate.setFromMigrateIfTrue(fromMigrate); @@ -1087,6 +1090,8 @@ void OpObserverImpl::onInternalOpMessage( const boost::optional<OplogSlot> slot) { MutableOplogEntry oplogEntry; oplogEntry.setOpType(repl::OpTypeEnum::kNoop); + + oplogEntry.setTid(nss.tenantId()); oplogEntry.setNss(nss); oplogEntry.setUuid(uuid); oplogEntry.setObject(msgObj); @@ -1122,6 +1127,8 @@ void OpObserverImpl::onCreateCollection(OperationContext* opCtx, } else { MutableOplogEntry oplogEntry; oplogEntry.setOpType(repl::OpTypeEnum::kCommand); + + oplogEntry.setTid(collectionName.tenantId()); oplogEntry.setNss(collectionName.getCommandNS()); oplogEntry.setUuid(options.uuid); oplogEntry.setObject( @@ -1165,6 +1172,8 @@ void OpObserverImpl::onCollMod(OperationContext* opCtx, MutableOplogEntry oplogEntry; oplogEntry.setOpType(repl::OpTypeEnum::kCommand); + + oplogEntry.setTid(nss.tenantId()); oplogEntry.setNss(nss.getCommandNS()); oplogEntry.setUuid(uuid); oplogEntry.setObject(repl::makeCollModCmdObj(collModCmd, oldCollOptions, indexInfo)); @@ -1187,21 +1196,24 @@ void OpObserverImpl::onCollMod(OperationContext* opCtx, invariant(coll->uuid() == uuid); } -void OpObserverImpl::onDropDatabase(OperationContext* opCtx, const std::string& dbName) { +void OpObserverImpl::onDropDatabase(OperationContext* opCtx, const DatabaseName& dbName) { MutableOplogEntry oplogEntry; oplogEntry.setOpType(repl::OpTypeEnum::kCommand); + + oplogEntry.setTid(dbName.tenantId()); oplogEntry.setNss({dbName, "$cmd"}); oplogEntry.setObject(BSON("dropDatabase" << 1)); logOperation(opCtx, &oplogEntry); - uassert( - 50714, "dropping the admin database is not allowed.", dbName != NamespaceString::kAdminDb); + uassert(50714, + "dropping the admin database is not allowed.", + dbName.db() != NamespaceString::kAdminDb); - if (dbName == NamespaceString::kSessionTransactionsTableNamespace.db()) { + if (dbName.db() == NamespaceString::kSessionTransactionsTableNamespace.db()) { MongoDSessionCatalog::invalidateAllSessions(opCtx); } - BucketCatalog::get(opCtx).clear(dbName); + BucketCatalog::get(opCtx).clear(dbName.db()); } repl::OpTime OpObserverImpl::onDropCollection(OperationContext* opCtx, @@ -1223,6 +1235,8 @@ repl::OpTime OpObserverImpl::onDropCollection(OperationContext* opCtx, // Do not replicate system.profile modifications. MutableOplogEntry oplogEntry; oplogEntry.setOpType(repl::OpTypeEnum::kCommand); + + oplogEntry.setTid(collectionName.tenantId()); oplogEntry.setNss(collectionName.getCommandNS()); oplogEntry.setUuid(uuid); oplogEntry.setFromMigrateIfTrue(markFromMigrate); @@ -1271,6 +1285,8 @@ void OpObserverImpl::onDropIndex(OperationContext* opCtx, const BSONObj& indexInfo) { MutableOplogEntry oplogEntry; oplogEntry.setOpType(repl::OpTypeEnum::kCommand); + + oplogEntry.setTid(nss.tenantId()); oplogEntry.setNss(nss.getCommandNS()); oplogEntry.setUuid(uuid); oplogEntry.setObject(BSON("dropIndexes" << nss.coll() << "index" << indexName)); @@ -1304,8 +1320,16 @@ repl::OpTime OpObserverImpl::preRenameCollection(OperationContext* const opCtx, bool stayTemp, bool markFromMigrate) { BSONObjBuilder builder; - builder.append("renameCollection", fromCollection.ns()); - builder.append("to", toCollection.ns()); + // TODO SERVER-62114 Change to check for upgraded FCV rather than feature flag + if (gFeatureFlagRequireTenantID.isEnabled(serverGlobalParams.featureCompatibility) || + !gMultitenancySupport) { + builder.append("renameCollection", fromCollection.ns()); + builder.append("to", toCollection.ns()); + } else { + builder.append("renameCollection", fromCollection.toStringWithTenantId()); + builder.append("to", toCollection.toStringWithTenantId()); + } + builder.append("stayTemp", stayTemp); if (dropTargetUUID) { dropTargetUUID->appendToBuilder(&builder, "dropTarget"); @@ -1313,6 +1337,8 @@ repl::OpTime OpObserverImpl::preRenameCollection(OperationContext* const opCtx, MutableOplogEntry oplogEntry; oplogEntry.setOpType(repl::OpTypeEnum::kCommand); + + oplogEntry.setTid(fromCollection.tenantId()); oplogEntry.setNss(fromCollection.getCommandNS()); oplogEntry.setUuid(uuid); oplogEntry.setFromMigrateIfTrue(markFromMigrate); @@ -1385,16 +1411,20 @@ void OpObserverImpl::onImportCollection(OperationContext* opCtx, MutableOplogEntry oplogEntry; oplogEntry.setOpType(repl::OpTypeEnum::kCommand); + + oplogEntry.setTid(nss.tenantId()); oplogEntry.setNss(nss.getCommandNS()); oplogEntry.setObject(importCollection.toBSON()); logOperation(opCtx, &oplogEntry); } void OpObserverImpl::onApplyOps(OperationContext* opCtx, - const std::string& dbName, + const DatabaseName& dbName, const BSONObj& applyOpCmd) { MutableOplogEntry oplogEntry; oplogEntry.setOpType(repl::OpTypeEnum::kCommand); + + oplogEntry.setTid(dbName.tenantId()); oplogEntry.setNss({dbName, "$cmd"}); oplogEntry.setObject(applyOpCmd); logOperation(opCtx, &oplogEntry); @@ -1407,6 +1437,8 @@ void OpObserverImpl::onEmptyCapped(OperationContext* opCtx, // Do not replicate system.profile modifications MutableOplogEntry oplogEntry; oplogEntry.setOpType(repl::OpTypeEnum::kCommand); + + oplogEntry.setTid(collectionName.tenantId()); oplogEntry.setNss(collectionName.getCommandNS()); oplogEntry.setUuid(uuid); oplogEntry.setObject(BSON("emptycapped" << collectionName.coll())); @@ -1718,6 +1750,7 @@ OpTimeBundle logApplyOps(OperationContext* opCtx, invariant(bool(txnRetryCounter) == bool(TransactionParticipant::get(opCtx))); oplogEntry->setOpType(repl::OpTypeEnum::kCommand); + oplogEntry->setTid(TenantId::kSystemTenantId); oplogEntry->setNss({"admin", "$cmd"}); // Batched writes (that is, WUOWs with 'groupOplogEntries') are not associated with a txnNumber, // so do not emit an lsid either. @@ -1822,6 +1855,7 @@ int logOplogEntries( imageEntry.setStatementIds(statement.getStatementIds()); imageEntry.setOpType(repl::OpTypeEnum::kNoop); imageEntry.setObject(imageDoc); + imageEntry.setTid(statement.getTid()); imageEntry.setNss(statement.getNss()); imageEntry.setUuid(statement.getUuid()); imageEntry.setOpTime(slot); @@ -1974,6 +2008,7 @@ void logCommitOrAbortForPreparedTransaction(OperationContext* opCtx, const auto txnRetryCounter = *opCtx->getTxnRetryCounter(); oplogEntry->setOpType(repl::OpTypeEnum::kCommand); + oplogEntry->setTid(TenantId::kSystemTenantId); oplogEntry->setNss({"admin", "$cmd"}); oplogEntry->setSessionId(opCtx->getLogicalSessionId()); oplogEntry->setTxnNumber(opCtx->getTxnNumber()); diff --git a/src/mongo/db/op_observer/op_observer_impl.h b/src/mongo/db/op_observer/op_observer_impl.h index 84e2fee3e59..7790fbf0161 100644 --- a/src/mongo/db/op_observer/op_observer_impl.h +++ b/src/mongo/db/op_observer/op_observer_impl.h @@ -118,7 +118,7 @@ public: const BSONObj& collModCmd, const CollectionOptions& oldCollOptions, boost::optional<IndexCollModInfo> indexInfo) final; - void onDropDatabase(OperationContext* opCtx, const std::string& dbName) final; + void onDropDatabase(OperationContext* opCtx, const DatabaseName& dbName) final; repl::OpTime onDropCollection(OperationContext* opCtx, const NamespaceString& collectionName, const UUID& uuid, @@ -180,7 +180,7 @@ public: const BSONObj& storageMetadata, bool isDryRun) final; void onApplyOps(OperationContext* opCtx, - const std::string& dbName, + const DatabaseName& dbName, const BSONObj& applyOpCmd) final; void onEmptyCapped(OperationContext* opCtx, const NamespaceString& collectionName, diff --git a/src/mongo/db/op_observer/op_observer_impl_test.cpp b/src/mongo/db/op_observer/op_observer_impl_test.cpp index f769118faed..6ac20cbdfda 100644 --- a/src/mongo/db/op_observer/op_observer_impl_test.cpp +++ b/src/mongo/db/op_observer/op_observer_impl_test.cpp @@ -600,6 +600,32 @@ TEST_F(OpObserverTest, OnDropCollectionReturnsDropOpTime) { ASSERT_EQUALS(repl::ReplClientInfo::forClient(&cc()).getLastOp(), dropOpTime); } +TEST_F(OpObserverTest, OnDropCollectionInlcudesTenantId) { + RAIIServerParameterControllerForTest featureFlagController("featureFlagRequireTenantID", true); + OpObserverImpl opObserver; + auto opCtx = cc().makeOperationContext(); + auto uuid = UUID::gen(); + + // Create 'drop' command. + TenantId tid{TenantId(OID::gen())}; + NamespaceString nss(tid, "test.coll"); + auto dropCmd = BSON("drop" << nss.coll()); + + // Write to the oplog. + { + AutoGetDb autoDb(opCtx.get(), nss.db(), MODE_X); + WriteUnitOfWork wunit(opCtx.get()); + opObserver.onDropCollection( + opCtx.get(), nss, uuid, 0U, OpObserver::CollectionDropType::kTwoPhase); + wunit.commit(); + } + + OplogEntry oplogEntry = assertGet(OplogEntry::parse(getSingleOplogEntry(opCtx.get()))); + ASSERT_EQUALS(tid, *oplogEntry.getTid()); + // TODO: SERVER-67155 perform check against getCommandNS after oplogEntry.getNss() contains tid + ASSERT_EQUALS(NamespaceString(boost::none, nss.dbName().db(), "$cmd"), oplogEntry.getNss()); +} + TEST_F(OpObserverTest, OnRenameCollectionReturnsRenameOpTime) { OpObserverImpl opObserver; auto opCtx = cc().makeOperationContext(); @@ -635,6 +661,79 @@ TEST_F(OpObserverTest, OnRenameCollectionReturnsRenameOpTime) { ASSERT_EQUALS(repl::ReplClientInfo::forClient(&cc()).getLastOp(), renameOpTime); } +TEST_F(OpObserverTest, OnRenameCollectionIncludesTenantIdFeatureFlagOff) { + RAIIServerParameterControllerForTest featureFlagController("featureFlagRequireTenantID", false); + OpObserverImpl opObserver; + auto opCtx = cc().makeOperationContext(); + + auto uuid = UUID::gen(); + auto dropTargetUuid = UUID::gen(); + auto stayTemp = false; + auto tid{TenantId(OID::gen())}; // rename should not occur across tenants + NamespaceString sourceNss(tid, "test.foo"); + NamespaceString targetNss(tid, "test.bar"); + + // Write to the oplog. + { + AutoGetDb autoDb(opCtx.get(), sourceNss.db(), MODE_X); + WriteUnitOfWork wunit(opCtx.get()); + opObserver.onRenameCollection( + opCtx.get(), sourceNss, targetNss, uuid, dropTargetUuid, 0U, stayTemp); + wunit.commit(); + } + + auto oplogEntryObj = getSingleOplogEntry(opCtx.get()); + OplogEntry oplogEntry = assertGet(OplogEntry::parse(oplogEntryObj)); + + // Ensure that renameCollection fields were properly added to oplog entry. + ASSERT_EQUALS(uuid, unittest::assertGet(UUID::parse(oplogEntryObj["ui"]))); + ASSERT_FALSE(oplogEntry.getTid()); + // TODO: SERVER-67155 perform check against getCommandNS after oplogEntry.getNss() contains tid + ASSERT_EQUALS(NamespaceString(boost::none, sourceNss.dbName().db(), "$cmd"), + oplogEntry.getNss()); + auto oExpected = BSON("renameCollection" << sourceNss.toStringWithTenantId() << "to" + << targetNss.toStringWithTenantId() << "stayTemp" + << stayTemp << "dropTarget" << dropTargetUuid); + ASSERT_BSONOBJ_EQ(oExpected, oplogEntry.getObject()); +} + +TEST_F(OpObserverTest, OnRenameCollectionIncludesTenantIdFeatureFlagOn) { + RAIIServerParameterControllerForTest featureFlagController("featureFlagRequireTenantID", true); + OpObserverImpl opObserver; + auto opCtx = cc().makeOperationContext(); + + auto uuid = UUID::gen(); + auto dropTargetUuid = UUID::gen(); + auto stayTemp = false; + auto tid{TenantId(OID::gen())}; // rename should not occur across tenants + NamespaceString sourceNss(tid, "test.foo"); + NamespaceString targetNss(tid, "test.bar"); + + // Write to the oplog. + { + AutoGetDb autoDb(opCtx.get(), sourceNss.db(), MODE_X); + WriteUnitOfWork wunit(opCtx.get()); + opObserver.onRenameCollection( + opCtx.get(), sourceNss, targetNss, uuid, dropTargetUuid, 0U, stayTemp); + wunit.commit(); + } + + auto oplogEntryObj = getSingleOplogEntry(opCtx.get()); + OplogEntry oplogEntry = assertGet(OplogEntry::parse(oplogEntryObj)); + + // Ensure that renameCollection fields were properly added to oplog entry. + ASSERT_EQUALS(uuid, unittest::assertGet(UUID::parse(oplogEntryObj["ui"]))); + ASSERT_EQUALS(tid, *oplogEntry.getTid()); + // TODO: SERVER-67155 perform check against getCommandNS after oplogEntry.getNss() contains tid + ASSERT_EQUALS(NamespaceString(boost::none, sourceNss.dbName().db(), "$cmd"), + oplogEntry.getNss()); + + auto oExpected = + BSON("renameCollection" << sourceNss.toString() << "to" << targetNss.toString() + << "stayTemp" << stayTemp << "dropTarget" << dropTargetUuid); + ASSERT_BSONOBJ_EQ(oExpected, oplogEntry.getObject()); +} + TEST_F(OpObserverTest, OnRenameCollectionOmitsDropTargetFieldIfDropTargetUuidIsNull) { OpObserverImpl opObserver; auto opCtx = cc().makeOperationContext(); @@ -717,6 +816,50 @@ TEST_F(OpObserverTest, ImportCollectionOplogEntry) { ASSERT_BSONOBJ_EQ(importCollection.toBSON(), oplogEntry.getObject()); } +TEST_F(OpObserverTest, ImportCollectionOplogEntryIncludesTenantId) { + RAIIServerParameterControllerForTest featureFlagController("featureFlagRequireTenantID", true); + OpObserverImpl opObserver; + auto opCtx = cc().makeOperationContext(); + + auto importUUID = UUID::gen(); + TenantId tid{TenantId(OID::gen())}; + NamespaceString nss(tid, "test.coll"); + long long numRecords = 1; + long long dataSize = 2; + // A dummy invalid catalog entry. We do not need a valid catalog entry for this test. + auto catalogEntry = BSON("ns" << nss.ns() << "ident" + << "collection-7-1792004489479993697"); + auto storageMetadata = BSON("storage" + << "metadata"); + bool isDryRun = false; + + // Write to the oplog. + { + AutoGetDb autoDb(opCtx.get(), nss.db(), MODE_X); + WriteUnitOfWork wunit(opCtx.get()); + opObserver.onImportCollection(opCtx.get(), + importUUID, + nss, + numRecords, + dataSize, + catalogEntry, + storageMetadata, + isDryRun); + wunit.commit(); + } + + auto oplogEntryObj = getSingleOplogEntry(opCtx.get()); + OplogEntry oplogEntry = assertGet(OplogEntry::parse(oplogEntryObj)); + ASSERT_TRUE(repl::OpTypeEnum::kCommand == oplogEntry.getOpType()); + ASSERT_TRUE(OplogEntry::CommandType::kImportCollection == oplogEntry.getCommandType()); + + ASSERT_EQUALS(tid, *oplogEntry.getTid()); + + ImportCollectionOplogEntry importCollection( + nss, importUUID, numRecords, dataSize, catalogEntry, storageMetadata, isDryRun); + ASSERT_BSONOBJ_EQ(importCollection.toBSON(), oplogEntry.getObject()); +} + TEST_F(OpObserverTest, SingleStatementInsertTestIncludesTenantId) { RAIIServerParameterControllerForTest featureFlagController("featureFlagRequireTenantID", true); auto opCtx = cc().makeOperationContext(); diff --git a/src/mongo/db/op_observer/op_observer_noop.h b/src/mongo/db/op_observer/op_observer_noop.h index b2ef86e5a89..0833dae5c83 100644 --- a/src/mongo/db/op_observer/op_observer_noop.h +++ b/src/mongo/db/op_observer/op_observer_noop.h @@ -107,7 +107,7 @@ public: const BSONObj& collModCmd, const CollectionOptions& oldCollOptions, boost::optional<IndexCollModInfo> indexInfo) override {} - void onDropDatabase(OperationContext* opCtx, const std::string& dbName) override {} + void onDropDatabase(OperationContext* opCtx, const DatabaseName& dbName) override {} using OpObserver::onDropCollection; repl::OpTime onDropCollection(OperationContext* opCtx, const NamespaceString& collectionName, @@ -154,7 +154,7 @@ public: const boost::optional<UUID>& dropTargetUUID, bool stayTemp) override {} void onApplyOps(OperationContext* opCtx, - const std::string& dbName, + const DatabaseName& dbName, const BSONObj& applyOpCmd) override {} void onEmptyCapped(OperationContext* opCtx, const NamespaceString& collectionName, diff --git a/src/mongo/db/op_observer/op_observer_registry.h b/src/mongo/db/op_observer/op_observer_registry.h index 8df5611dadc..6bc80dda894 100644 --- a/src/mongo/db/op_observer/op_observer_registry.h +++ b/src/mongo/db/op_observer/op_observer_registry.h @@ -203,7 +203,7 @@ public: o->onCollMod(opCtx, nss, uuid, collModCmd, oldCollOptions, indexInfo); } - void onDropDatabase(OperationContext* const opCtx, const std::string& dbName) override { + void onDropDatabase(OperationContext* const opCtx, const DatabaseName& dbName) override { ReservedTimes times{opCtx}; for (auto& o : _observers) o->onDropDatabase(opCtx, dbName); @@ -352,7 +352,7 @@ public: opCtx, fromCollection, toCollection, uuid, dropTargetUUID, stayTemp); } void onApplyOps(OperationContext* const opCtx, - const std::string& dbName, + const DatabaseName& dbName, const BSONObj& applyOpCmd) override { ReservedTimes times{opCtx}; for (auto& o : _observers) diff --git a/src/mongo/db/op_observer/op_observer_registry_test.cpp b/src/mongo/db/op_observer/op_observer_registry_test.cpp index 6d7c9a8acb5..b7ac21be4f8 100644 --- a/src/mongo/db/op_observer/op_observer_registry_test.cpp +++ b/src/mongo/db/op_observer/op_observer_registry_test.cpp @@ -50,7 +50,7 @@ struct TestObserver : public OpObserverNoop { int drops = 0; repl::OpTime opTime; - void onDropDatabase(OperationContext* opCtx, const std::string& dbName) { + void onDropDatabase(OperationContext* opCtx, const DatabaseName& dbName) { drops++; } using OpObserver::onDropCollection; @@ -96,7 +96,7 @@ struct TestObserver : public OpObserverNoop { }; struct ThrowingObserver : public TestObserver { - void onDropDatabase(OperationContext* opCtx, const std::string& dbName) override { + void onDropDatabase(OperationContext* opCtx, const DatabaseName& dbName) override { drops++; uasserted(ErrorCodes::InternalError, "throwing observer"); } @@ -138,7 +138,7 @@ struct OpObserverRegistryTest : public unittest::Test { TEST_F(OpObserverRegistryTest, NoObservers) { OperationContextNoop opCtx; // Check that it's OK to call observer methods with no observers registered. - registry.onDropDatabase(&opCtx, "test"); + registry.onDropDatabase(&opCtx, DatabaseName(boost::none, "test")); } TEST_F(OpObserverRegistryTest, TwoObservers) { @@ -146,7 +146,7 @@ TEST_F(OpObserverRegistryTest, TwoObservers) { ASSERT_EQUALS(testObservers, 2); registry.addObserver(std::move(unique1)); registry.addObserver(std::move(unique2)); - registry.onDropDatabase(&opCtx, "test"); + registry.onDropDatabase(&opCtx, DatabaseName(boost::none, "test")); ASSERT_EQUALS(observer1->drops, 1); ASSERT_EQUALS(observer2->drops, 1); } @@ -157,7 +157,8 @@ TEST_F(OpObserverRegistryTest, ThrowingObserver1) { observer1 = unique1.get(); registry.addObserver(std::move(unique1)); registry.addObserver(std::move(unique2)); - ASSERT_THROWS(registry.onDropDatabase(&opCtx, "test"), AssertionException); + ASSERT_THROWS(registry.onDropDatabase(&opCtx, DatabaseName(boost::none, "test")), + AssertionException); ASSERT_EQUALS(observer1->drops, 1); ASSERT_EQUALS(observer2->drops, 0); } @@ -168,7 +169,8 @@ TEST_F(OpObserverRegistryTest, ThrowingObserver2) { observer2 = unique1.get(); registry.addObserver(std::move(unique1)); registry.addObserver(std::move(unique2)); - ASSERT_THROWS(registry.onDropDatabase(&opCtx, "test"), AssertionException); + ASSERT_THROWS(registry.onDropDatabase(&opCtx, DatabaseName(boost::none, "test")), + AssertionException); ASSERT_EQUALS(observer1->drops, 1); ASSERT_EQUALS(observer2->drops, 1); } diff --git a/src/mongo/db/op_observer/user_write_block_mode_op_observer.cpp b/src/mongo/db/op_observer/user_write_block_mode_op_observer.cpp index ca779532085..0a3b49055ea 100644 --- a/src/mongo/db/op_observer/user_write_block_mode_op_observer.cpp +++ b/src/mongo/db/op_observer/user_write_block_mode_op_observer.cpp @@ -217,8 +217,8 @@ void UserWriteBlockModeOpObserver::onCollMod(OperationContext* opCtx, } void UserWriteBlockModeOpObserver::onDropDatabase(OperationContext* opCtx, - const std::string& dbName) { - _checkWriteAllowed(opCtx, NamespaceString(dbName)); + const DatabaseName& dbName) { + _checkWriteAllowed(opCtx, NamespaceString(dbName, "")); } repl::OpTime UserWriteBlockModeOpObserver::onDropCollection(OperationContext* opCtx, diff --git a/src/mongo/db/op_observer/user_write_block_mode_op_observer.h b/src/mongo/db/op_observer/user_write_block_mode_op_observer.h index 2194d03c172..d6adc1f79ee 100644 --- a/src/mongo/db/op_observer/user_write_block_mode_op_observer.h +++ b/src/mongo/db/op_observer/user_write_block_mode_op_observer.h @@ -96,7 +96,7 @@ public: const CollectionOptions& oldCollOptions, boost::optional<IndexCollModInfo> indexInfo) final; - void onDropDatabase(OperationContext* opCtx, const std::string& dbName) final; + void onDropDatabase(OperationContext* opCtx, const DatabaseName& dbName) final; using OpObserver::onDropCollection; repl::OpTime onDropCollection(OperationContext* opCtx, @@ -193,7 +193,7 @@ public: // The transaction commit related hooks don't need to be checked, because all of the operations // inside the transaction are checked and they all execute in one WUOW. void onApplyOps(OperationContext* opCtx, - const std::string& dbName, + const DatabaseName& dbName, const BSONObj& applyOpCmd) final {} void onEmptyCapped(OperationContext* opCtx, diff --git a/src/mongo/db/op_observer/user_write_block_mode_op_observer_test.cpp b/src/mongo/db/op_observer/user_write_block_mode_op_observer_test.cpp index 39c6c3a3b90..ef82dda4aba 100644 --- a/src/mongo/db/op_observer/user_write_block_mode_op_observer_test.cpp +++ b/src/mongo/db/op_observer/user_write_block_mode_op_observer_test.cpp @@ -116,7 +116,7 @@ protected: opObserver.onCreateCollection( opCtx, nullptr, nss, {}, BSONObj(), OplogSlot(), false); opObserver.onCollMod(opCtx, nss, uuid, BSONObj(), {}, boost::none); - opObserver.onDropDatabase(opCtx, std::string(nss.db())); + opObserver.onDropDatabase(opCtx, DatabaseName(boost::none, nss.db())); opObserver.onDropCollection( opCtx, nss, @@ -145,7 +145,7 @@ protected: AssertionException); ASSERT_THROWS(opObserver.onCollMod(opCtx, nss, uuid, BSONObj(), {}, boost::none), AssertionException); - ASSERT_THROWS(opObserver.onDropDatabase(opCtx, std::string(nss.db())), + ASSERT_THROWS(opObserver.onDropDatabase(opCtx, DatabaseName(boost::none, nss.db())), AssertionException); ASSERT_THROWS(opObserver.onDropCollection( opCtx, diff --git a/src/mongo/db/repl/apply_ops_test.cpp b/src/mongo/db/repl/apply_ops_test.cpp index abbcdac1463..78e34981422 100644 --- a/src/mongo/db/repl/apply_ops_test.cpp +++ b/src/mongo/db/repl/apply_ops_test.cpp @@ -56,7 +56,7 @@ public: * Called by applyOps() when ops are applied atomically. */ void onApplyOps(OperationContext* opCtx, - const std::string& dbName, + const DatabaseName& dbName, const BSONObj& applyOpCmd) override; // If not empty, holds the command object passed to last invocation of onApplyOps(). @@ -64,7 +64,7 @@ public: }; void OpObserverMock::onApplyOps(OperationContext* opCtx, - const std::string& dbName, + const DatabaseName& dbName, const BSONObj& applyOpCmd) { ASSERT_FALSE(applyOpCmd.isEmpty()); // Get owned copy because 'applyOpCmd' may be a temporary BSONObj created by applyOps(). diff --git a/src/mongo/db/repl/oplog_entry.cpp b/src/mongo/db/repl/oplog_entry.cpp index 5916e388802..0d1561aa095 100644 --- a/src/mongo/db/repl/oplog_entry.cpp +++ b/src/mongo/db/repl/oplog_entry.cpp @@ -184,9 +184,7 @@ ReplOperation MutableOplogEntry::makeInsertOperation(const NamespaceString& nss, ReplOperation op; op.setOpType(OpTypeEnum::kInsert); - // TODO SERVER-62114 Change to check for upgraded FCV rather than feature flag - if (gFeatureFlagRequireTenantID.isEnabled(serverGlobalParams.featureCompatibility)) - op.setTid(nss.tenantId()); + op.setTid(nss.tenantId()); op.setNss(nss); op.setUuid(uuid); op.setObject(docToInsert.getOwned()); @@ -226,9 +224,7 @@ ReplOperation MutableOplogEntry::makeUpdateOperation(const NamespaceString nss, ReplOperation op; op.setOpType(OpTypeEnum::kUpdate); - // TODO SERVER-62114 Change to check for upgraded FCV rather than feature flag - if (gFeatureFlagRequireTenantID.isEnabled(serverGlobalParams.featureCompatibility)) - op.setTid(nss.tenantId()); + op.setTid(nss.tenantId()); op.setNss(nss); op.setUuid(uuid); op.setObject(update.getOwned()); @@ -242,6 +238,8 @@ ReplOperation MutableOplogEntry::makeCreateCommand(const NamespaceString nss, ReplOperation op; op.setOpType(OpTypeEnum::kCommand); + + op.setTid(nss.tenantId()); op.setNss(nss.getCommandNS()); op.setUuid(options.uuid); op.setObject(makeCreateCollCmdObj(nss, options, idIndex)); @@ -253,6 +251,8 @@ ReplOperation MutableOplogEntry::makeCreateIndexesCommand(const NamespaceString const BSONObj& indexDoc) { ReplOperation op; op.setOpType(OpTypeEnum::kCommand); + + op.setTid(nss.tenantId()); op.setNss(nss.getCommandNS()); op.setUuid(uuid); @@ -271,9 +271,7 @@ ReplOperation MutableOplogEntry::makeDeleteOperation(const NamespaceString& nss, ReplOperation op; op.setOpType(OpTypeEnum::kDelete); - // TODO SERVER-62114 Change to check for upgraded FCV rather than feature flag - if (gFeatureFlagRequireTenantID.isEnabled(serverGlobalParams.featureCompatibility)) - op.setTid(nss.tenantId()); + op.setTid(nss.tenantId()); op.setNss(nss); op.setUuid(uuid); op.setObject(docToDelete.getOwned()); diff --git a/src/mongo/db/repl/oplog_entry.h b/src/mongo/db/repl/oplog_entry.h index 506fe21e025..8f10e93f5e9 100644 --- a/src/mongo/db/repl/oplog_entry.h +++ b/src/mongo/db/repl/oplog_entry.h @@ -36,6 +36,7 @@ #include "mongo/db/repl/apply_ops_gen.h" #include "mongo/db/repl/oplog_entry_gen.h" #include "mongo/db/repl/optime.h" +#include "mongo/db/server_feature_flags_gen.h" #include "mongo/util/overloaded_visitor.h" namespace mongo { @@ -194,6 +195,17 @@ public: setFromMigrate(value); } + /** + * This function overrides the base class setTid() function for the sole purpose of satisfying + * the FCV checks. Once these are deprecated, we should remove this overridden function + * entirely. + */ + void setTid(boost::optional<mongo::TenantId> value) & { + // TODO SERVER-62114 Change to check for upgraded FCV rather than feature flag + if (gFeatureFlagRequireTenantID.isEnabled(serverGlobalParams.featureCompatibility)) + DurableReplOperation::setTid(value); + } + private: BSONObj _preImageDocumentKey; @@ -275,7 +287,9 @@ public: } void setTid(boost::optional<mongo::TenantId> value) & { - getDurableReplOperation().setTid(std::move(value)); + // TODO SERVER-62114 Change to check for upgraded FCV rather than feature flag + if (gFeatureFlagRequireTenantID.isEnabled(serverGlobalParams.featureCompatibility)) + getDurableReplOperation().setTid(std::move(value)); } void setNss(NamespaceString value) & { diff --git a/src/mongo/db/repl/primary_only_service_op_observer.h b/src/mongo/db/repl/primary_only_service_op_observer.h index d39df067da7..5031b1f8e28 100644 --- a/src/mongo/db/repl/primary_only_service_op_observer.h +++ b/src/mongo/db/repl/primary_only_service_op_observer.h @@ -124,7 +124,7 @@ public: const CollectionOptions& oldCollOptions, boost::optional<IndexCollModInfo> indexInfo) final {} - void onDropDatabase(OperationContext* opCtx, const std::string& dbName) final {} + void onDropDatabase(OperationContext* opCtx, const DatabaseName& dbName) final {} using OpObserver::onDropCollection; repl::OpTime onDropCollection(OperationContext* opCtx, @@ -174,7 +174,7 @@ public: const boost::optional<UUID>& dropTargetUUID, bool stayTemp) final {} void onApplyOps(OperationContext* opCtx, - const std::string& dbName, + const DatabaseName& dbName, const BSONObj& applyOpCmd) final {} void onEmptyCapped(OperationContext* opCtx, diff --git a/src/mongo/db/repl/tenant_migration_donor_op_observer.h b/src/mongo/db/repl/tenant_migration_donor_op_observer.h index 2046c2b954d..f019e2eb2df 100644 --- a/src/mongo/db/repl/tenant_migration_donor_op_observer.h +++ b/src/mongo/db/repl/tenant_migration_donor_op_observer.h @@ -122,7 +122,7 @@ public: const CollectionOptions& oldCollOptions, boost::optional<IndexCollModInfo> indexInfo) final {} - void onDropDatabase(OperationContext* opCtx, const std::string& dbName) final {} + void onDropDatabase(OperationContext* opCtx, const DatabaseName& dbName) final {} using OpObserver::onDropCollection; repl::OpTime onDropCollection(OperationContext* opCtx, const NamespaceString& collectionName, @@ -171,7 +171,7 @@ public: const boost::optional<UUID>& dropTargetUUID, bool stayTemp) final {} void onApplyOps(OperationContext* opCtx, - const std::string& dbName, + const DatabaseName& dbName, const BSONObj& applyOpCmd) final {} void onEmptyCapped(OperationContext* opCtx, diff --git a/src/mongo/db/repl/tenant_migration_recipient_op_observer.h b/src/mongo/db/repl/tenant_migration_recipient_op_observer.h index 0177bbd5771..2f068be8cfd 100644 --- a/src/mongo/db/repl/tenant_migration_recipient_op_observer.h +++ b/src/mongo/db/repl/tenant_migration_recipient_op_observer.h @@ -123,7 +123,7 @@ public: const CollectionOptions& oldCollOptions, boost::optional<IndexCollModInfo> indexInfo) final {} - void onDropDatabase(OperationContext* opCtx, const std::string& dbName) final {} + void onDropDatabase(OperationContext* opCtx, const DatabaseName& dbName) final {} using OpObserver::onDropCollection; repl::OpTime onDropCollection(OperationContext* opCtx, @@ -173,7 +173,7 @@ public: const boost::optional<UUID>& dropTargetUUID, bool stayTemp) final {} void onApplyOps(OperationContext* opCtx, - const std::string& dbName, + const DatabaseName& dbName, const BSONObj& applyOpCmd) final {} void onEmptyCapped(OperationContext* opCtx, diff --git a/src/mongo/db/s/config_server_op_observer.h b/src/mongo/db/s/config_server_op_observer.h index 1f6f97c5aae..dc6a1a8429f 100644 --- a/src/mongo/db/s/config_server_op_observer.h +++ b/src/mongo/db/s/config_server_op_observer.h @@ -125,7 +125,7 @@ public: const CollectionOptions& oldCollOptions, boost::optional<IndexCollModInfo> indexInfo) override {} - void onDropDatabase(OperationContext* opCtx, const std::string& dbName) override {} + void onDropDatabase(OperationContext* opCtx, const DatabaseName& dbName) override {} using OpObserver::onDropCollection; repl::OpTime onDropCollection(OperationContext* opCtx, @@ -174,7 +174,7 @@ public: bool stayTemp) override {} void onApplyOps(OperationContext* opCtx, - const std::string& dbName, + const DatabaseName& dbName, const BSONObj& applyOpCmd) override {} void onEmptyCapped(OperationContext* opCtx, diff --git a/src/mongo/db/s/resharding/resharding_op_observer.h b/src/mongo/db/s/resharding/resharding_op_observer.h index c3821e4f446..7efbbdb1f91 100644 --- a/src/mongo/db/s/resharding/resharding_op_observer.h +++ b/src/mongo/db/s/resharding/resharding_op_observer.h @@ -140,7 +140,7 @@ public: const CollectionOptions& oldCollOptions, boost::optional<IndexCollModInfo> indexInfo) override {} - void onDropDatabase(OperationContext* opCtx, const std::string& dbName) override {} + void onDropDatabase(OperationContext* opCtx, const DatabaseName& dbName) override {} using OpObserver::onDropCollection; repl::OpTime onDropCollection(OperationContext* opCtx, @@ -194,7 +194,7 @@ public: bool stayTemp) override {} void onApplyOps(OperationContext* opCtx, - const std::string& dbName, + const DatabaseName& dbName, const BSONObj& applyOpCmd) override {} void onEmptyCapped(OperationContext* opCtx, diff --git a/src/mongo/db/s/shard_server_op_observer.h b/src/mongo/db/s/shard_server_op_observer.h index 88faf326640..75457cce95c 100644 --- a/src/mongo/db/s/shard_server_op_observer.h +++ b/src/mongo/db/s/shard_server_op_observer.h @@ -122,7 +122,7 @@ public: const CollectionOptions& oldCollOptions, boost::optional<IndexCollModInfo> indexInfo) override; - void onDropDatabase(OperationContext* opCtx, const std::string& dbName) override {} + void onDropDatabase(OperationContext* opCtx, const DatabaseName& dbName) override {} using OpObserver::onDropCollection; repl::OpTime onDropCollection(OperationContext* opCtx, @@ -173,7 +173,7 @@ public: bool stayTemp) override {} void onApplyOps(OperationContext* opCtx, - const std::string& dbName, + const DatabaseName& dbName, const BSONObj& applyOpCmd) override {} void onEmptyCapped(OperationContext* opCtx, diff --git a/src/mongo/db/serverless/shard_split_donor_op_observer.h b/src/mongo/db/serverless/shard_split_donor_op_observer.h index 6cd7f62f292..1cf7c338cc0 100644 --- a/src/mongo/db/serverless/shard_split_donor_op_observer.h +++ b/src/mongo/db/serverless/shard_split_donor_op_observer.h @@ -121,7 +121,7 @@ public: const CollectionOptions& oldCollOptions, boost::optional<IndexCollModInfo> indexInfo) final {} - void onDropDatabase(OperationContext* opCtx, const std::string& dbName) final {} + void onDropDatabase(OperationContext* opCtx, const DatabaseName& dbName) final {} using OpObserver::onDropCollection; repl::OpTime onDropCollection(OperationContext* opCtx, const NamespaceString& collectionName, @@ -170,7 +170,7 @@ public: const boost::optional<UUID>& dropTargetUUID, bool stayTemp) final {} void onApplyOps(OperationContext* opCtx, - const std::string& dbName, + const DatabaseName& dbName, const BSONObj& applyOpCmd) final {} void onEmptyCapped(OperationContext* opCtx, diff --git a/src/mongo/idl/cluster_server_parameter_op_observer.cpp b/src/mongo/idl/cluster_server_parameter_op_observer.cpp index d8eefdfe777..5fd94031c29 100644 --- a/src/mongo/idl/cluster_server_parameter_op_observer.cpp +++ b/src/mongo/idl/cluster_server_parameter_op_observer.cpp @@ -122,8 +122,8 @@ void ClusterServerParameterOpObserver::onDelete(OperationContext* opCtx, } void ClusterServerParameterOpObserver::onDropDatabase(OperationContext* opCtx, - const std::string& dbName) { - if (dbName == NamespaceString::kConfigDb) { + const DatabaseName& dbName) { + if (dbName.db() == NamespaceString::kConfigDb) { // Entire config DB deleted, reset to default state. ClusterServerParameterInitializer::get(opCtx)->clearAllParameters(opCtx); } diff --git a/src/mongo/idl/cluster_server_parameter_op_observer.h b/src/mongo/idl/cluster_server_parameter_op_observer.h index 655689e09f6..fef725041bb 100644 --- a/src/mongo/idl/cluster_server_parameter_op_observer.h +++ b/src/mongo/idl/cluster_server_parameter_op_observer.h @@ -65,7 +65,7 @@ public: const UUID& uuid, StmtId stmtId, const OplogDeleteEntryArgs& args) final; - void onDropDatabase(OperationContext* opCtx, const std::string& dbName) final; + void onDropDatabase(OperationContext* opCtx, const DatabaseName& dbName) final; using OpObserver::onDropCollection; repl::OpTime onDropCollection(OperationContext* opCtx, const NamespaceString& collectionName, @@ -176,7 +176,7 @@ public: bool stayTemp) final {} void onApplyOps(OperationContext* opCtx, - const std::string& dbName, + const DatabaseName& dbName, const BSONObj& applyOpCmd) final {} void onEmptyCapped(OperationContext* opCtx, diff --git a/src/mongo/idl/cluster_server_parameter_op_observer_test.cpp b/src/mongo/idl/cluster_server_parameter_op_observer_test.cpp index 8f00f680bc5..f748f4f345b 100644 --- a/src/mongo/idl/cluster_server_parameter_op_observer_test.cpp +++ b/src/mongo/idl/cluster_server_parameter_op_observer_test.cpp @@ -80,7 +80,7 @@ public: void doDropDatabase(StringData dbname) { auto opCtx = cc().makeOperationContext(); - observer.onDropDatabase(opCtx.get(), dbname.toString()); + observer.onDropDatabase(opCtx.get(), DatabaseName(boost::none, dbname)); } void doRenameCollection(const NamespaceString& fromColl, const NamespaceString& toColl) { |