diff --git a/BedrockServer.cpp b/BedrockServer.cpp index efa822598..84bdc2624 100644 --- a/BedrockServer.cpp +++ b/BedrockServer.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -1338,6 +1339,20 @@ BedrockServer::BedrockServer(const SData& args_) ref(_leaderVersion), ref(_syncNodeQueuedCommands), ref(*this)); + + // Add syncType arg. If no -syncType specified, default to QUORUM + _isSyncSet = args.isSet("-syncType"); + _syncType = -1; + if (_isSyncSet) { + string cmd = args["-syncType"]; + if ( strcasecmp(cmd.c_str(),SC_ONE) == 0) { + _syncType = SQLiteNode::ONE; + } else if (strcasecmp(cmd.c_str(),SC_ASYNC) == 0) { + _syncType = SQLiteNode::ASYNC; + } else if (strcasecmp(cmd.c_str(),SC_QUORUM) == 0) { + _syncType = SQLiteNode::QUORUM; + } + } } BedrockServer::~BedrockServer() { @@ -1606,6 +1621,15 @@ void BedrockServer::postPoll(fd_map& fdm, uint64_t& nextActivity) { // Create a command. unique_ptr command = getCommandFromPlugins(move(request)); + // Check if -syncType is set and query starts with INSERT/DELETE/UPDATE + if (_isSyncSet && command->request.methodLine.compare("QUERY")) { + string query = STrim(SToUpper(command->request["query"])); + if (SStartsWith(SToUpper(query),"INSERT") || SStartsWith(SToUpper(query),"DELETE") || SStartsWith(SToUpper(query),"UPDATE")) { + command->writeConsistency = (SQLiteNode::ConsistencyLevel)_syncType; + SINFO("Forcing " << _syncType << " consistency for command " << command->request.methodLine); + } + } + if (command->writeConsistency != SQLiteNode::QUORUM && _syncCommands.find(command->request.methodLine) != _syncCommands.end()) { diff --git a/BedrockServer.h b/BedrockServer.h index e6886a184..45c628c0b 100644 --- a/BedrockServer.h +++ b/BedrockServer.h @@ -6,6 +6,10 @@ #include "BedrockCommandQueue.h" #include "BedrockTimeoutCommandQueue.h" +#define SC_ONE "ONE" +#define SC_QUORUM "QUORUM" +#define SC_ASYNC "ASYNC" + class BedrockServer : public SQLiteServer { public: @@ -483,4 +487,8 @@ class BedrockServer : public SQLiteServer { // This is a snapshot of the state of the node taken at the beginning of any call to peekCommand or processCommand // so that the state can't change for the lifetime of that call, from the view of that function. static thread_local atomic _nodeStateSnapshot; + + // These allow for the ability to startup with -syncType while specifying ONE/ASYNC/QUORUM + bool _isSyncSet; + int _syncType; }; diff --git a/docs/cli.md b/docs/cli.md index 1c46383d6..e43257efe 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -30,6 +30,8 @@ To see a full list of Bedrock's configuration options, just run `bedrock -?` on -readThreads <#> Number of read threads to start (min 1, defaults to 1) -queryLog Set the query log filename (default 'queryLog.csv', SIGUSR2/SIGQUIT to enable/disable) -maxJournalSize <#commits> Number of commits to retainin the historical journal (default 1000000) + -syncType Selective synchronization (QUORUM, ONE, ASYNC) and (defaults to QUORUM) + -synchronous Set the PRAGMA schema.synchronous Quick Start Tips: ----------------- diff --git a/main.cpp b/main.cpp index 09167af58..3240f2cfb 100644 --- a/main.cpp +++ b/main.cpp @@ -239,6 +239,7 @@ int main(int argc, char* argv[]) { << endl; cout << "-maxJournalSize <#commits> Number of commits to retain in the historical journal (default 1000000)" << endl; + cout << "-syncType Selective synchronization (QUORUM, ONE, ASYNC) and (defaults to QUORUM) " << endl; cout << "-synchronous Set the PRAGMA schema.synchronous " "(defaults see https://sqlite.org/pragma.html#pragma_synchronous)" << endl;