SERVER-120979 Assume false if recordIdsReplicated is not present in create oplog entry (#49108)

GitOrigin-RevId: 15cacf1986c961337c91106400240b817089368e
This commit is contained in:
Ernesto Rodriguez Reina 2026-03-06 17:58:09 -05:00 committed by MongoDB Bot
parent a3df8bd142
commit 8bb52ae9bf
2 changed files with 92 additions and 2 deletions

View File

@ -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();

View File

@ -916,7 +916,12 @@ const StringMap<ApplyOpMetadata> kOpsMap = {
Lock::DBLock dbLock(opCtx, nss.dbName(), MODE_IX, Date_t::max(), boost::none);
boost::optional<bool> 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<bool> recordIdsReplicated =
repl::OplogApplication::Mode::kApplyOpsCmd == mode ? boost::none
: boost::optional<bool>(false);
if (auto value = cmd["recordIdsReplicated"]; value.isBoolean()) {
recordIdsReplicated = value.boolean();
}