From f54d4c0e40f701fb7212e8468e933cca658b0285 Mon Sep 17 00:00:00 2001 From: Stephanie <53684987+seristof@users.noreply.github.com> Date: Tue, 26 May 2026 11:21:18 -0400 Subject: [PATCH] SERVER-126510 Uncaught WriteConflictException in setFCVOnCleanStartup (#54036) GitOrigin-RevId: 1481c94ad5596ac45755cfd3318d3dca79591cbd --- src/mongo/db/commands/BUILD.bazel | 1 + .../feature_compatibility_version.cpp | 36 ++++++++++--------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/mongo/db/commands/BUILD.bazel b/src/mongo/db/commands/BUILD.bazel index 39137b614d5..33fc36e1d40 100644 --- a/src/mongo/db/commands/BUILD.bazel +++ b/src/mongo/db/commands/BUILD.bazel @@ -544,6 +544,7 @@ mongo_cc_library( "//src/mongo/db/repl:repl_server_parameters", "//src/mongo/db/repl:repl_settings", "//src/mongo/db/shard_role", + "//src/mongo/db/shard_role/lock_manager:exception_util", "//src/mongo/db/shard_role/shard_catalog:collection_options", "//src/mongo/db/storage:storage_options", ], diff --git a/src/mongo/db/commands/feature_compatibility_version.cpp b/src/mongo/db/commands/feature_compatibility_version.cpp index d4d11d8388b..0625a2e08c9 100644 --- a/src/mongo/db/commands/feature_compatibility_version.cpp +++ b/src/mongo/db/commands/feature_compatibility_version.cpp @@ -56,6 +56,7 @@ #include "mongo/db/server_options.h" #include "mongo/db/server_parameter.h" #include "mongo/db/service_context.h" +#include "mongo/db/shard_role/lock_manager/exception_util.h" #include "mongo/db/shard_role/lock_manager/lock_manager_defs.h" #include "mongo/db/shard_role/shard_catalog/catalog_raii.h" #include "mongo/db/shard_role/shard_catalog/collection_catalog.h" @@ -654,24 +655,27 @@ Timestamp FeatureCompatibilityVersion::setIfCleanStartup( CollectionOptions options; options.uuid = UUID::gen(); uassertStatusOK(storageInterface->createCollection(opCtx, nss, options)); - WriteUnitOfWork wuow(opCtx); - // Register a callback to update the timestamp on committing the FCV document. - if (term != repl::OpTime::kUninitializedTerm) { - shard_role_details::getRecoveryUnit(opCtx)->onCommit( - [×tamp](OperationContext*, boost::optional commitTime) { - if (commitTime) { - timestamp = *commitTime; - } - }); - } + writeConflictRetry(opCtx, "setFCVOnCleanStartup", nss, [&] { + WriteUnitOfWork wuow(opCtx); - // We then insert the featureCompatibilityVersion document into the server configuration - // collection. The server parameter will be updated on commit by the op observer. - // Leave the timestamp empty to be populated by the OpObserver. - uassertStatusOK(storageInterface->insertDocument( - opCtx, nss, repl::TimestampedBSONObj{fcvDoc.toBSON(), Timestamp()}, term)); - wuow.commit(); + // Register a callback to update the timestamp on committing the FCV document. + if (term != repl::OpTime::kUninitializedTerm) { + shard_role_details::getRecoveryUnit(opCtx)->onCommit( + [×tamp](OperationContext*, boost::optional commitTime) { + if (commitTime) { + timestamp = *commitTime; + } + }); + } + + // We then insert the featureCompatibilityVersion document into the server configuration + // collection. The server parameter will be updated on commit by the op observer. + // Leave the timestamp empty to be populated by the OpObserver. + uassertStatusOK(storageInterface->insertDocument( + opCtx, nss, repl::TimestampedBSONObj{fcvDoc.toBSON(), Timestamp()}, term)); + wuow.commit(); + }); return timestamp; };