From 185facf0acf9c22e09893051a28040e8ee39292b Mon Sep 17 00:00:00 2001 From: Eric Milkie Date: Fri, 27 Dec 2019 15:21:17 +0000 Subject: SERVER-45288 switch Idempotency tests to use WiredTiger instead of ephemeralForTest This commit cleans up a bit of WiredTiger storage initialization so that it can happen multiple times during the same process, as required by unit tests. --- src/mongo/db/repl/SConscript | 1 + src/mongo/db/repl/idempotency_test_fixture.h | 3 +++ src/mongo/db/repl/oplog_applier_impl_test.cpp | 29 ---------------------- .../db/repl/oplog_applier_impl_test_fixture.cpp | 5 ++++ .../db/repl/oplog_applier_impl_test_fixture.h | 5 ++++ .../db/storage/wiredtiger/wiredtiger_init.cpp | 12 --------- .../db/storage/wiredtiger/wiredtiger_kv_engine.cpp | 16 +++++++++--- .../db/storage/wiredtiger/wiredtiger_kv_engine.h | 5 ++++ src/mongo/idl/server_parameter.cpp | 4 +++ src/mongo/idl/server_parameter.h | 1 + 10 files changed, 37 insertions(+), 44 deletions(-) diff --git a/src/mongo/db/repl/SConscript b/src/mongo/db/repl/SConscript index 7794870345c..6ae0868a017 100644 --- a/src/mongo/db/repl/SConscript +++ b/src/mongo/db/repl/SConscript @@ -581,6 +581,7 @@ env.Library( '$BUILD_DIR/mongo/db/catalog/document_validation', '$BUILD_DIR/mongo/db/s/op_observer_sharding_impl', '$BUILD_DIR/mongo/db/service_context_d_test_fixture', + '$BUILD_DIR/mongo/db/storage/wiredtiger/storage_wiredtiger', ], ) diff --git a/src/mongo/db/repl/idempotency_test_fixture.h b/src/mongo/db/repl/idempotency_test_fixture.h index f3f990cb8da..6b188a0e9ba 100644 --- a/src/mongo/db/repl/idempotency_test_fixture.h +++ b/src/mongo/db/repl/idempotency_test_fixture.h @@ -88,6 +88,9 @@ StringBuilderImpl& operator<<(StringBuilderImplsetFollowerMode(MemberState::RS_RECOVERING)); - CollectionUUID uuid = kUuid; - - auto options1 = BSON("idIndex" << BSON("key" << fromjson("{_id: 1}") << "name" - << "_id_" - << "v" << 2) - << "uuid" << uuid); - auto createColl1 = makeCreateCollectionOplogEntry(nextOpTime(), nss, options1); - ASSERT_OK(runOpInitialSync(createColl1)); - - auto runOpsAndValidate = [this, uuid]() { - auto insertOp = insert(BSON("_id" << Decimal128(1))); - auto dropColl = makeCommandOplogEntry(nextOpTime(), nss, BSON("drop" << nss.coll())); - auto createColl2 = createCollection(uuid); - - auto ops = {insertOp, dropColl, createColl2}; - ASSERT_OK(runOpsInitialSync(ops)); - auto state = validate(); - - return state; - }; - - auto state1 = runOpsAndValidate(); - auto state2 = runOpsAndValidate(); - ASSERT_EQUALS(state1, state2); -} - TEST_F(IdempotencyTest, CreateCollectionWithView) { ASSERT_OK(ReplicationCoordinator::get(getGlobalServiceContext()) ->setFollowerMode(MemberState::RS_RECOVERING)); diff --git a/src/mongo/db/repl/oplog_applier_impl_test_fixture.cpp b/src/mongo/db/repl/oplog_applier_impl_test_fixture.cpp index 523bb93f1a1..7e3f8d89040 100644 --- a/src/mongo/db/repl/oplog_applier_impl_test_fixture.cpp +++ b/src/mongo/db/repl/oplog_applier_impl_test_fixture.cpp @@ -35,6 +35,7 @@ #include "mongo/db/curop.h" #include "mongo/db/db_raii.h" #include "mongo/db/dbdirectclient.h" +#include "mongo/db/logical_clock.h" #include "mongo/db/op_observer_registry.h" #include "mongo/db/query/internal_plans.h" #include "mongo/db/repl/drop_pending_collection_reaper.h" @@ -119,6 +120,10 @@ void OplogApplierImplTest::setUp() { // the server parameter. serverGlobalParams.featureCompatibility.setVersion( ServerGlobalParams::FeatureCompatibility::Version::kFullyUpgradedTo44); + + // This is necessary to generate ghost timestamps for index builds that are not 0, since 0 is an + // invalid timestamp. + ASSERT_OK(LogicalClock::get(_opCtx.get())->advanceClusterTime(LogicalTime(Timestamp(1, 0)))); } void OplogApplierImplTest::tearDown() { diff --git a/src/mongo/db/repl/oplog_applier_impl_test_fixture.h b/src/mongo/db/repl/oplog_applier_impl_test_fixture.h index 204fa7b3a08..10aa03fea65 100644 --- a/src/mongo/db/repl/oplog_applier_impl_test_fixture.h +++ b/src/mongo/db/repl/oplog_applier_impl_test_fixture.h @@ -122,6 +122,11 @@ public: }; class OplogApplierImplTest : public ServiceContextMongoDTest { +public: + OplogApplierImplTest(){}; + OplogApplierImplTest(std::string storageEngine) + : ServiceContextMongoDTest(std::move(storageEngine)){}; + protected: void _testApplyOplogEntryOrGroupedInsertsCrudOperation(ErrorCodes::Error expectedError, const OplogEntry& op, diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_init.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_init.cpp index ee9c8ea6027..ec034eccc34 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_init.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_init.cpp @@ -130,21 +130,9 @@ public: MONGO_COMPILER_VARIABLE_UNUSED auto leakedSection = new WiredTigerServerStatusSection(kv); - auto* param = new WiredTigerEngineRuntimeConfigParameter( - "wiredTigerEngineRuntimeConfig", ServerParameterType::kRuntimeOnly); - param->_data.second = kv; - - auto* maxCacheOverflowParam = new WiredTigerMaxCacheOverflowSizeGBParameter( - "wiredTigerMaxCacheOverflowSizeGB", ServerParameterType::kRuntimeOnly); - maxCacheOverflowParam->_data = {wiredTigerGlobalOptions.maxCacheOverflowFileSizeGB, kv}; - // This allows unit tests to run this code without encountering memory leaks - // TODO (SERVER-43063): to fix the global server parameter registry memory leak. The - // server status section leak will still exist after SERVER-43063. #if __has_feature(address_sanitizer) __lsan_ignore_object(leakedSection); - __lsan_ignore_object(param); - __lsan_ignore_object(maxCacheOverflowParam); #endif } diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp index 2013e2fed91..dd63aad920a 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp @@ -797,12 +797,22 @@ WiredTigerKVEngine::WiredTigerKVEngine(const std::string& canonicalName, _sizeStorer = std::make_unique(_conn, _sizeStorerUri, _readOnly); Locker::setGlobalThrottling(&openReadTransaction, &openWriteTransaction); + + _runTimeConfigParam.reset(new WiredTigerEngineRuntimeConfigParameter( + "wiredTigerEngineRuntimeConfig", ServerParameterType::kRuntimeOnly)); + _runTimeConfigParam->_data.second = this; + _maxCacheOverflowParam.reset(new WiredTigerMaxCacheOverflowSizeGBParameter( + "wiredTigerMaxCacheOverflowSizeGB", ServerParameterType::kRuntimeOnly)); + _maxCacheOverflowParam->_data = {maxCacheOverflowFileSizeMB / 1024, this}; } WiredTigerKVEngine::~WiredTigerKVEngine() { - if (_conn) { - cleanShutdown(); - } + // Remove server parameters that we added in the constructor, to enable unit tests to reload the + // storage engine again in this same process. + ServerParameterSet::getGlobal()->remove("wiredTigerEngineRuntimeConfig"); + ServerParameterSet::getGlobal()->remove("wiredTigerMaxCacheOverflowSizeGB"); + + cleanShutdown(); _sessionCache.reset(nullptr); } diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h index 8c0eb10d8f8..ca4c51c1ccd 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h @@ -55,6 +55,8 @@ class JournalListener; class WiredTigerRecordStore; class WiredTigerSessionCache; class WiredTigerSizeStorer; +class WiredTigerEngineRuntimeConfigParameter; +class WiredTigerMaxCacheOverflowSizeGBParameter; struct WiredTigerFileVersion { enum class StartupVersion { IS_34, IS_36, IS_40, IS_42, IS_44 }; @@ -490,5 +492,8 @@ private: // // Access must be protected by the CheckpointLock. std::list _checkpointedIndexes; + + std::unique_ptr _runTimeConfigParam; + std::unique_ptr _maxCacheOverflowParam; }; } // namespace mongo diff --git a/src/mongo/idl/server_parameter.cpp b/src/mongo/idl/server_parameter.cpp index 975f2b515e6..3f9d2c50d3c 100644 --- a/src/mongo/idl/server_parameter.cpp +++ b/src/mongo/idl/server_parameter.cpp @@ -113,6 +113,10 @@ StatusWith ServerParameter::coerceToString(const BSONElement& eleme } } +void ServerParameterSet::remove(const std::string& name) { + invariant(1 == _map.erase(name)); +} + IDLServerParameterDeprecatedAlias::IDLServerParameterDeprecatedAlias(StringData name, ServerParameter* sp) : ServerParameter(ServerParameterSet::getGlobal(), diff --git a/src/mongo/idl/server_parameter.h b/src/mongo/idl/server_parameter.h index 4fa5ba6b6f7..74a1971053c 100644 --- a/src/mongo/idl/server_parameter.h +++ b/src/mongo/idl/server_parameter.h @@ -138,6 +138,7 @@ public: using Map = ServerParameter::Map; void add(ServerParameter* sp); + void remove(const std::string& name); const Map& getMap() const { return _map; -- cgit v1.2.1