From 87a96ece672be026bb8e720f62777f6bb94e47af Mon Sep 17 00:00:00 2001 From: jsteemann Date: Fri, 15 Jul 2016 12:40:29 +0200 Subject: [PATCH] engine selection --- arangod/StorageEngine/EngineSelectorFeature.cpp | 14 +++++++++++++- arangod/StorageEngine/EngineSelectorFeature.h | 9 +++++++++ arangod/StorageEngine/MMFilesEngine.cpp | 4 ++++ arangod/StorageEngine/OtherEngine.cpp | 4 ++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/arangod/StorageEngine/EngineSelectorFeature.cpp b/arangod/StorageEngine/EngineSelectorFeature.cpp index 15a97b7680..d706c187ea 100644 --- a/arangod/StorageEngine/EngineSelectorFeature.cpp +++ b/arangod/StorageEngine/EngineSelectorFeature.cpp @@ -31,6 +31,8 @@ using namespace arangodb; using namespace arangodb::options; +StorageEngine* EngineSelectorFeature::ENGINE = nullptr; + EngineSelectorFeature::EngineSelectorFeature( application_features::ApplicationServer* server) : ApplicationFeature(server, "EngineSelector"), _engine(MMFilesEngine::EngineName) { @@ -54,15 +56,25 @@ void EngineSelectorFeature::prepare() { // this is the selected engine LOG(TRACE) << "enabling storage engine " << engine; e->enable(); + + // register storage engine + ENGINE = e; } else { // turn off all other storage engines LOG(TRACE) << "disabling storage engine " << engine; e->disable(); } } + + TRI_ASSERT(ENGINE != nullptr); } -// all available storage engines +void EngineSelectorFeature::unprepare() { + // unregister storage engine + ENGINE = nullptr; +} + +// return all available storage engines std::unordered_set EngineSelectorFeature::availableEngines() { return std::unordered_set{ MMFilesEngine::EngineName, diff --git a/arangod/StorageEngine/EngineSelectorFeature.h b/arangod/StorageEngine/EngineSelectorFeature.h index 8e3c690c47..70fd5eacf8 100644 --- a/arangod/StorageEngine/EngineSelectorFeature.h +++ b/arangod/StorageEngine/EngineSelectorFeature.h @@ -27,6 +27,8 @@ #include "ProgramOptions/ProgramOptions.h" namespace arangodb { +class StorageEngine; + class EngineSelectorFeature final : public application_features::ApplicationFeature { public: explicit EngineSelectorFeature(application_features::ApplicationServer* server); @@ -34,8 +36,15 @@ class EngineSelectorFeature final : public application_features::ApplicationFeat public: void collectOptions(std::shared_ptr) override final; void prepare() override final; + void unprepare() override final; + // return the names of all available storage engines static std::unordered_set availableEngines(); + + public: + // selected storage engine. this will contain a pointer to the storage engine after + // prepare() and before unprepare() + static StorageEngine* ENGINE; private: std::string _engine; diff --git a/arangod/StorageEngine/MMFilesEngine.cpp b/arangod/StorageEngine/MMFilesEngine.cpp index 9f139323bd..8c620886a8 100644 --- a/arangod/StorageEngine/MMFilesEngine.cpp +++ b/arangod/StorageEngine/MMFilesEngine.cpp @@ -22,6 +22,7 @@ //////////////////////////////////////////////////////////////////////////////// #include "MMFilesEngine.h" +#include "StorageEngine/EngineSelectorFeature.h" using namespace arangodb; @@ -46,17 +47,20 @@ void MMFilesEngine::validateOptions(std::shared_ptr) { // preparation phase for storage engine. can be used for internal setup. // the storage engine must not start any threads here or write any files void MMFilesEngine::prepare() { + TRI_ASSERT(EngineSelectorFeature::ENGINE = this); } // start the engine. now it's allowed to start engine-specific threads, // write files etc. void MMFilesEngine::start() { + TRI_ASSERT(EngineSelectorFeature::ENGINE = this); } // stop the storage engine. this can be used to flush all data to disk, // shutdown threads etc. it is guaranteed that there will be no read and // write requests to the storage engine after this call void MMFilesEngine::stop() { + TRI_ASSERT(EngineSelectorFeature::ENGINE = this); } // fill the Builder object with an array of databases that were detected diff --git a/arangod/StorageEngine/OtherEngine.cpp b/arangod/StorageEngine/OtherEngine.cpp index 5dee8a2100..5e4fdd1c5c 100644 --- a/arangod/StorageEngine/OtherEngine.cpp +++ b/arangod/StorageEngine/OtherEngine.cpp @@ -22,6 +22,7 @@ //////////////////////////////////////////////////////////////////////////////// #include "OtherEngine.h" +#include "StorageEngine/EngineSelectorFeature.h" using namespace arangodb; @@ -46,17 +47,20 @@ void OtherEngine::validateOptions(std::shared_ptr) { // preparation phase for storage engine. can be used for internal setup. // the storage engine must not start any threads here or write any files void OtherEngine::prepare() { + TRI_ASSERT(EngineSelectorFeature::ENGINE = this); } // start the engine. now it's allowed to start engine-specific threads, // write files etc. void OtherEngine::start() { + TRI_ASSERT(EngineSelectorFeature::ENGINE = this); } // stop the storage engine. this can be used to flush all data to disk, // shutdown threads etc. it is guaranteed that there will be no read and // write requests to the storage engine after this call void OtherEngine::stop() { + TRI_ASSERT(EngineSelectorFeature::ENGINE = this); } // fill the Builder object with an array of databases that were detected