From dab81ced807fb71bfe5afc9d3281b9946c6f027b Mon Sep 17 00:00:00 2001 From: Benety Goh Date: Mon, 13 Feb 2023 16:11:20 +0000 Subject: SERVER-71018 remove dbhelper dependency from StorageRepairObserver --- src/mongo/db/storage/SConscript | 2 +- src/mongo/db/storage/storage_engine_test_fixture.h | 7 ++++++- src/mongo/db/storage/storage_repair_observer.cpp | 10 ++++++---- src/mongo/db/storage/storage_repair_observer_test.cpp | 4 ++++ 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/mongo/db/storage/SConscript b/src/mongo/db/storage/SConscript index 8fdcafbcb9b..a776d99a50c 100644 --- a/src/mongo/db/storage/SConscript +++ b/src/mongo/db/storage/SConscript @@ -453,8 +453,8 @@ env.Library( ], LIBDEPS_PRIVATE=[ '$BUILD_DIR/mongo/base', - '$BUILD_DIR/mongo/db/dbhelpers', '$BUILD_DIR/mongo/db/repl/replica_set_messages', + '$BUILD_DIR/mongo/db/repl/storage_interface', '$BUILD_DIR/mongo/db/service_context', '$BUILD_DIR/mongo/db/storage/journal_flusher', 'storage_file_util', diff --git a/src/mongo/db/storage/storage_engine_test_fixture.h b/src/mongo/db/storage/storage_engine_test_fixture.h index c573ba3fa99..89d8425fb3f 100644 --- a/src/mongo/db/storage/storage_engine_test_fixture.h +++ b/src/mongo/db/storage/storage_engine_test_fixture.h @@ -34,6 +34,8 @@ #include "mongo/db/catalog_raii.h" #include "mongo/db/multitenancy.h" #include "mongo/db/repl/replication_coordinator_mock.h" +#include "mongo/db/repl/storage_interface.h" +#include "mongo/db/repl/storage_interface_impl.h" #include "mongo/db/service_context_d_test_fixture.h" #include "mongo/db/storage/durable_catalog.h" #include "mongo/db/storage/durable_catalog_impl.h" @@ -206,7 +208,10 @@ public: class StorageEngineRepairTest : public StorageEngineTest { public: StorageEngineRepairTest() - : StorageEngineTest(Options{}.repair(RepairAction::kRepair).ephemeral(false)) {} + : StorageEngineTest(Options{}.repair(RepairAction::kRepair).ephemeral(false)) { + repl::StorageInterface::set(getServiceContext(), + std::make_unique()); + } void tearDown() { auto repairObserver = StorageRepairObserver::get(getGlobalServiceContext()); diff --git a/src/mongo/db/storage/storage_repair_observer.cpp b/src/mongo/db/storage/storage_repair_observer.cpp index 1921b0ee42e..0a92cf5eff4 100644 --- a/src/mongo/db/storage/storage_repair_observer.cpp +++ b/src/mongo/db/storage/storage_repair_observer.cpp @@ -43,9 +43,9 @@ #include #include -#include "mongo/db/dbhelpers.h" #include "mongo/db/operation_context.h" #include "mongo/db/repl/repl_set_config.h" +#include "mongo/db/repl/storage_interface.h" #include "mongo/db/service_context.h" #include "mongo/db/storage/control/journal_flusher.h" #include "mongo/db/storage/storage_file_util.h" @@ -157,16 +157,18 @@ void StorageRepairObserver::_invalidateReplConfigIfNeeded(OperationContext* opCt // a replica set but lost its config due to a repair, it would automatically perform a resync. // If this node is a standalone, this would lead to a confusing error message if it were // added to a replica set later on. - BSONObj config; - if (!Helpers::getSingleton(opCtx, kConfigNss, config)) { + auto storage = repl::StorageInterface::get(opCtx); + auto swConfig = storage->findSingleton(opCtx, kConfigNss); + if (!swConfig.isOK()) { return; } + auto config = swConfig.getValue(); if (config.hasField(repl::ReplSetConfig::kRepairedFieldName)) { return; } BSONObjBuilder configBuilder(config); configBuilder.append(repl::ReplSetConfig::kRepairedFieldName, true); - Helpers::putSingleton(opCtx, kConfigNss, configBuilder.obj()); + fassert(7101800, storage->putSingleton(opCtx, kConfigNss, {configBuilder.obj(), Timestamp{}})); JournalFlusher::get(opCtx)->waitForJournalFlush(); } diff --git a/src/mongo/db/storage/storage_repair_observer_test.cpp b/src/mongo/db/storage/storage_repair_observer_test.cpp index 614d7ee2e87..780a3518b9a 100644 --- a/src/mongo/db/storage/storage_repair_observer_test.cpp +++ b/src/mongo/db/storage/storage_repair_observer_test.cpp @@ -36,6 +36,8 @@ #include "mongo/db/dbhelpers.h" #include "mongo/db/operation_context_noop.h" #include "mongo/db/repl/replication_coordinator_mock.h" +#include "mongo/db/repl/storage_interface.h" +#include "mongo/db/repl/storage_interface_impl.h" #include "mongo/db/service_context_d_test_fixture.h" #include "mongo/db/storage/storage_repair_observer.h" #include "mongo/logv2/log.h" @@ -60,6 +62,8 @@ public: repl::ReplicationCoordinator::set( getServiceContext(), std::make_unique(getServiceContext())); + repl::StorageInterface::set(getServiceContext(), + std::make_unique()); } void assertRepairIncompleteOnTearDown() { -- cgit v1.2.1