diff --git a/src/inmemory/inmemory_global_options.h b/src/inmemory/inmemory_global_options.h index 253f916..a62c07a 100644 --- a/src/inmemory/inmemory_global_options.h +++ b/src/inmemory/inmemory_global_options.h @@ -28,6 +28,10 @@ #pragma once +#include +#include "mongo/base/disallow_copying.h" +#include "mongo/db/namespace_string.h" +#include "mongo/db/storage/wiredtiger/wiredtiger_customization_hooks.h" #include "mongo/util/options_parser/startup_option_init.h" #include "mongo/util/options_parser/startup_options.h" @@ -50,5 +54,32 @@ public: std::string indexConfig; }; +/** + * The InMemoryConfigManager manages configuration options particular to the + * in-memory storage engine. + * Use the empty configuration object, rather than the default since we + * don't need to override many options. + */ +class InMemoryConfigManager : public EmptyWiredTigerCustomizationHooks { + MONGO_DISALLOW_COPYING(InMemoryConfigManager); + +public: + /** + * Initialize the InMemoryConfigManager. + */ + InMemoryConfigManager(const std::string& dbPath); + + ~InMemoryConfigManager() override; + + /** + * Get the WT table encryption config for a specific namespace + * or internal WT table. + */ + std::string getOpenConfig(StringData ns) override; + +private: + boost::filesystem::path _dbPath; +}; + extern InMemoryGlobalOptions inMemoryGlobalOptions; } diff --git a/src/inmemory/inmemory_init.cpp b/src/inmemory/inmemory_init.cpp index 19006b7..8aeb11e 100644 --- a/src/inmemory/inmemory_init.cpp +++ b/src/inmemory/inmemory_init.cpp @@ -118,9 +118,17 @@ public: } // namespace -MONGO_INITIALIZER_WITH_PREREQUISITES(InMemoryEngineInit, ("SetGlobalEnvironment")) +MONGO_INITIALIZER_WITH_PREREQUISITES(InMemoryEngineInit, + ("SetGlobalEnvironment", + "SetWiredTigerCustomizationHooks")) (InitializerContext* context) { getGlobalServiceContext()->registerStorageEngine("inMemory", new InMemoryFactory()); + // TODO: Only do this when started with the in-memory storage engine? + if (storageGlobalParams.engine == "inMemory") { + auto optionManager = stdx::make_unique( + storageGlobalParams.dbpath); + WiredTigerCustomizationHooks::set(getGlobalServiceContext(), std::move(optionManager)); + } return Status::OK(); } diff --git a/src/inmemory/inmemory_options_init.cpp b/src/inmemory/inmemory_options_init.cpp index b1adc34..fbcf2a0 100644 --- a/src/inmemory/inmemory_options_init.cpp +++ b/src/inmemory/inmemory_options_init.cpp @@ -30,6 +30,7 @@ #include "mongo/util/options_parser/startup_option_init.h" +#include #include #include "inmemory_global_options.h" @@ -56,4 +57,27 @@ MONGO_STARTUP_OPTIONS_STORE(InMemoryOptions)(InitializerContext* context) { } return Status::OK(); } + +InMemoryConfigManager::InMemoryConfigManager(const std::string& dbPath) + : _dbPath(boost::filesystem::path(dbPath)) {} + +InMemoryConfigManager::~InMemoryConfigManager() {} + +// Add a special configuration option for MongoDB metadata tables, so the +// in-memory storage engine doesn't need to handle WT_CACHE_FULL error returns +// from those tables. +std::string InMemoryConfigManager::getOpenConfig(StringData ns) { + std::string config; + + // Internal metadata WT tables such as sizeStorer and _mdb_catalog are identified by not having + // a '.' separated name that distinguishes a "normal namespace during collection or index + // creation. + std::size_t dotIndex = ns.find("."); + if (dotIndex == std::string::npos) { + config += "ignore_in_memory_cache_size=true"; + } + + return config; +} + }