mirror of https://gitee.com/bigwinds/arangodb
engine selection
This commit is contained in:
parent
7742e709a3
commit
87a96ece67
|
@ -31,6 +31,8 @@
|
||||||
using namespace arangodb;
|
using namespace arangodb;
|
||||||
using namespace arangodb::options;
|
using namespace arangodb::options;
|
||||||
|
|
||||||
|
StorageEngine* EngineSelectorFeature::ENGINE = nullptr;
|
||||||
|
|
||||||
EngineSelectorFeature::EngineSelectorFeature(
|
EngineSelectorFeature::EngineSelectorFeature(
|
||||||
application_features::ApplicationServer* server)
|
application_features::ApplicationServer* server)
|
||||||
: ApplicationFeature(server, "EngineSelector"), _engine(MMFilesEngine::EngineName) {
|
: ApplicationFeature(server, "EngineSelector"), _engine(MMFilesEngine::EngineName) {
|
||||||
|
@ -54,15 +56,25 @@ void EngineSelectorFeature::prepare() {
|
||||||
// this is the selected engine
|
// this is the selected engine
|
||||||
LOG(TRACE) << "enabling storage engine " << engine;
|
LOG(TRACE) << "enabling storage engine " << engine;
|
||||||
e->enable();
|
e->enable();
|
||||||
|
|
||||||
|
// register storage engine
|
||||||
|
ENGINE = e;
|
||||||
} else {
|
} else {
|
||||||
// turn off all other storage engines
|
// turn off all other storage engines
|
||||||
LOG(TRACE) << "disabling storage engine " << engine;
|
LOG(TRACE) << "disabling storage engine " << engine;
|
||||||
e->disable();
|
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<std::string> EngineSelectorFeature::availableEngines() {
|
std::unordered_set<std::string> EngineSelectorFeature::availableEngines() {
|
||||||
return std::unordered_set<std::string>{
|
return std::unordered_set<std::string>{
|
||||||
MMFilesEngine::EngineName,
|
MMFilesEngine::EngineName,
|
||||||
|
|
|
@ -27,6 +27,8 @@
|
||||||
#include "ProgramOptions/ProgramOptions.h"
|
#include "ProgramOptions/ProgramOptions.h"
|
||||||
|
|
||||||
namespace arangodb {
|
namespace arangodb {
|
||||||
|
class StorageEngine;
|
||||||
|
|
||||||
class EngineSelectorFeature final : public application_features::ApplicationFeature {
|
class EngineSelectorFeature final : public application_features::ApplicationFeature {
|
||||||
public:
|
public:
|
||||||
explicit EngineSelectorFeature(application_features::ApplicationServer* server);
|
explicit EngineSelectorFeature(application_features::ApplicationServer* server);
|
||||||
|
@ -34,9 +36,16 @@ class EngineSelectorFeature final : public application_features::ApplicationFeat
|
||||||
public:
|
public:
|
||||||
void collectOptions(std::shared_ptr<options::ProgramOptions>) override final;
|
void collectOptions(std::shared_ptr<options::ProgramOptions>) override final;
|
||||||
void prepare() override final;
|
void prepare() override final;
|
||||||
|
void unprepare() override final;
|
||||||
|
|
||||||
|
// return the names of all available storage engines
|
||||||
static std::unordered_set<std::string> availableEngines();
|
static std::unordered_set<std::string> availableEngines();
|
||||||
|
|
||||||
|
public:
|
||||||
|
// selected storage engine. this will contain a pointer to the storage engine after
|
||||||
|
// prepare() and before unprepare()
|
||||||
|
static StorageEngine* ENGINE;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string _engine;
|
std::string _engine;
|
||||||
};
|
};
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include "MMFilesEngine.h"
|
#include "MMFilesEngine.h"
|
||||||
|
#include "StorageEngine/EngineSelectorFeature.h"
|
||||||
|
|
||||||
using namespace arangodb;
|
using namespace arangodb;
|
||||||
|
|
||||||
|
@ -46,17 +47,20 @@ void MMFilesEngine::validateOptions(std::shared_ptr<options::ProgramOptions>) {
|
||||||
// preparation phase for storage engine. can be used for internal setup.
|
// preparation phase for storage engine. can be used for internal setup.
|
||||||
// the storage engine must not start any threads here or write any files
|
// the storage engine must not start any threads here or write any files
|
||||||
void MMFilesEngine::prepare() {
|
void MMFilesEngine::prepare() {
|
||||||
|
TRI_ASSERT(EngineSelectorFeature::ENGINE = this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// start the engine. now it's allowed to start engine-specific threads,
|
// start the engine. now it's allowed to start engine-specific threads,
|
||||||
// write files etc.
|
// write files etc.
|
||||||
void MMFilesEngine::start() {
|
void MMFilesEngine::start() {
|
||||||
|
TRI_ASSERT(EngineSelectorFeature::ENGINE = this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// stop the storage engine. this can be used to flush all data to disk,
|
// 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
|
// shutdown threads etc. it is guaranteed that there will be no read and
|
||||||
// write requests to the storage engine after this call
|
// write requests to the storage engine after this call
|
||||||
void MMFilesEngine::stop() {
|
void MMFilesEngine::stop() {
|
||||||
|
TRI_ASSERT(EngineSelectorFeature::ENGINE = this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// fill the Builder object with an array of databases that were detected
|
// fill the Builder object with an array of databases that were detected
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include "OtherEngine.h"
|
#include "OtherEngine.h"
|
||||||
|
#include "StorageEngine/EngineSelectorFeature.h"
|
||||||
|
|
||||||
using namespace arangodb;
|
using namespace arangodb;
|
||||||
|
|
||||||
|
@ -46,17 +47,20 @@ void OtherEngine::validateOptions(std::shared_ptr<options::ProgramOptions>) {
|
||||||
// preparation phase for storage engine. can be used for internal setup.
|
// preparation phase for storage engine. can be used for internal setup.
|
||||||
// the storage engine must not start any threads here or write any files
|
// the storage engine must not start any threads here or write any files
|
||||||
void OtherEngine::prepare() {
|
void OtherEngine::prepare() {
|
||||||
|
TRI_ASSERT(EngineSelectorFeature::ENGINE = this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// start the engine. now it's allowed to start engine-specific threads,
|
// start the engine. now it's allowed to start engine-specific threads,
|
||||||
// write files etc.
|
// write files etc.
|
||||||
void OtherEngine::start() {
|
void OtherEngine::start() {
|
||||||
|
TRI_ASSERT(EngineSelectorFeature::ENGINE = this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// stop the storage engine. this can be used to flush all data to disk,
|
// 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
|
// shutdown threads etc. it is guaranteed that there will be no read and
|
||||||
// write requests to the storage engine after this call
|
// write requests to the storage engine after this call
|
||||||
void OtherEngine::stop() {
|
void OtherEngine::stop() {
|
||||||
|
TRI_ASSERT(EngineSelectorFeature::ENGINE = this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// fill the Builder object with an array of databases that were detected
|
// fill the Builder object with an array of databases that were detected
|
||||||
|
|
Loading…
Reference in New Issue