From 8bb52ae9bf060e8a18baabd5016aba700ac25dfa Mon Sep 17 00:00:00 2001 From: Ernesto Rodriguez Reina Date: Fri, 6 Mar 2026 17:58:09 -0500 Subject: [PATCH] SERVER-120979 Assume false if recordIdsReplicated is not present in create oplog entry (#49108) GitOrigin-RevId: 15cacf1986c961337c91106400240b817089368e --- src/mongo/db/repl/apply_ops_test.cpp | 87 +++++++++++++++++++++++++++- src/mongo/db/repl/oplog.cpp | 7 ++- 2 files changed, 92 insertions(+), 2 deletions(-) diff --git a/src/mongo/db/repl/apply_ops_test.cpp b/src/mongo/db/repl/apply_ops_test.cpp index b246a46ba19..f54228891a8 100644 --- a/src/mongo/db/repl/apply_ops_test.cpp +++ b/src/mongo/db/repl/apply_ops_test.cpp @@ -632,7 +632,6 @@ TEST_F(ApplyOpsTest, ApplyOpsCreateWithRecordIdsReplicatedRridDisabled) { NamespaceString nss = NamespaceString::createNamespaceString_forTest( "test.ApplyOpsCreateWithRecordIdsReplicatedRridDisabled"); - ASSERT_OK(_storage->createCollection(opCtx.get(), nss, {})); auto createOpWithRecordIdsReplicated = BSON("op" << "c" @@ -647,6 +646,92 @@ TEST_F(ApplyOpsTest, ApplyOpsCreateWithRecordIdsReplicatedRridDisabled) { applyOps(opCtx.get(), nss.dbName(), applyOpsCmdObj, mode, &resultBuilder)); } +TEST_F(ApplyOpsTest, ApplyOpsCreateWithoutRecordIdsReplicatedRridEnabled) { + auto opCtx = cc().makeOperationContext(); + auto mode = OplogApplication::Mode::kApplyOpsCmd; + + NamespaceString nss = NamespaceString::createNamespaceString_forTest( + "test.ApplyOpsCreateWithoutRecordIdsReplicatedRridEnabled"); + + auto createOpWithoutRecordIdsReplicated = BSON("op" << "c" + << "ns" << nss.getCommandNS().ns_forTest() + << "o" << BSON("create" << nss.coll())); + + auto applyOpsCmdObj = BSON("applyOps" << BSON_ARRAY(createOpWithoutRecordIdsReplicated)); + BSONObjBuilder resultBuilder; + RAIIServerParameterControllerForTest _featureFlagReplRidController{ + "featureFlagRecordIdsReplicated", true}; + ASSERT_OK(applyOps(opCtx.get(), nss.dbName(), applyOpsCmdObj, mode, &resultBuilder)); + + // validating that the collection has recordIdsReplicated even when it was not present. + auto coll = acquireCollection( + opCtx.get(), + CollectionAcquisitionRequest(nss, + PlacementConcern(boost::none, ShardVersion::UNTRACKED()), + repl::ReadConcernArgs::get(opCtx.get()), + AcquisitionPrerequisites::kRead), + MODE_IS); + ASSERT_TRUE(coll.getCollectionPtr()->areRecordIdsReplicated()); +} + +TEST_F(ApplyOpsTest, ApplyOpsCreateWithRecordIdsTrueReplicatedRridEnabled) { + auto opCtx = cc().makeOperationContext(); + auto mode = OplogApplication::Mode::kApplyOpsCmd; + + NamespaceString nss = NamespaceString::createNamespaceString_forTest( + "test.ApplyOpsCreateWithRecordIdsTrueReplicatedRridEnabled"); + + auto createOpWithRecordIdsReplicatedTrue = + BSON("op" << "c" + << "ns" << nss.getCommandNS().ns_forTest() << "o" + << BSON("create" << nss.coll() << "recordIdsReplicated" << true)); + + auto applyOpsCmdObj = BSON("applyOps" << BSON_ARRAY(createOpWithRecordIdsReplicatedTrue)); + BSONObjBuilder resultBuilder; + RAIIServerParameterControllerForTest _featureFlagReplRidController{ + "featureFlagRecordIdsReplicated", true}; + ASSERT_OK(applyOps(opCtx.get(), nss.dbName(), applyOpsCmdObj, mode, &resultBuilder)); + + // validating that the collection has recordIdsReplicated. + auto coll = acquireCollection( + opCtx.get(), + CollectionAcquisitionRequest(nss, + PlacementConcern(boost::none, ShardVersion::UNTRACKED()), + repl::ReadConcernArgs::get(opCtx.get()), + AcquisitionPrerequisites::kRead), + MODE_IS); + ASSERT_TRUE(coll.getCollectionPtr()->areRecordIdsReplicated()); +} + +TEST_F(ApplyOpsTest, ApplyOpsCreateWithRecordIdsFalseReplicatedRridEnabled) { + auto opCtx = cc().makeOperationContext(); + auto mode = OplogApplication::Mode::kApplyOpsCmd; + + NamespaceString nss = NamespaceString::createNamespaceString_forTest( + "test.ApplyOpsCreateWithRecordIdsFalseReplicatedRridEnabled"); + + auto createOpWithRecordIdsReplicatedFalse = + BSON("op" << "c" + << "ns" << nss.getCommandNS().ns_forTest() << "o" + << BSON("create" << nss.coll() << "recordIdsReplicated" << false)); + + auto applyOpsCmdObj = BSON("applyOps" << BSON_ARRAY(createOpWithRecordIdsReplicatedFalse)); + BSONObjBuilder resultBuilder; + RAIIServerParameterControllerForTest _featureFlagReplRidController{ + "featureFlagRecordIdsReplicated", true}; + ASSERT_OK(applyOps(opCtx.get(), nss.dbName(), applyOpsCmdObj, mode, &resultBuilder)); + + // validating that the collection does not have recordIdsReplicated. + auto coll = acquireCollection( + opCtx.get(), + CollectionAcquisitionRequest(nss, + PlacementConcern(boost::none, ShardVersion::UNTRACKED()), + repl::ReadConcernArgs::get(opCtx.get()), + AcquisitionPrerequisites::kRead), + MODE_IS); + ASSERT_FALSE(coll.getCollectionPtr()->areRecordIdsReplicated()); +} + using ApplyOpsDeathTest = ApplyOpsTest; DEATH_TEST_F(ApplyOpsDeathTest, ApplyOpsRidOnNonRridCollectionRridEnabled, "11454700") { auto opCtx = cc().makeOperationContext(); diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp index de9328009e7..d0b7e784522 100644 --- a/src/mongo/db/repl/oplog.cpp +++ b/src/mongo/db/repl/oplog.cpp @@ -916,7 +916,12 @@ const StringMap kOpsMap = { Lock::DBLock dbLock(opCtx, nss.dbName(), MODE_IX, Date_t::max(), boost::none); - boost::optional recordIdsReplicated = boost::none; + // For applyOps commands if we don't see a recordIdReplicated field we let the node decide + // the option depending if the fature flag is On. For all other create oplogs, the absence + // of the field indicate it is a collection without recordIdsReplicated. + boost::optional recordIdsReplicated = + repl::OplogApplication::Mode::kApplyOpsCmd == mode ? boost::none + : boost::optional(false); if (auto value = cmd["recordIdsReplicated"]; value.isBoolean()) { recordIdsReplicated = value.boolean(); }