From 343c9b4bea2e7f72b277b6b5f765cfefcaec342e Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Wed, 20 May 2015 13:51:02 +0200 Subject: [PATCH] added static helper methods for cluster state --- arangod/Aql/Collection.cpp | 6 ++++-- arangod/Aql/ExecutionEngine.cpp | 5 +++-- arangod/Cluster/HeartbeatThread.cpp | 3 +++ arangod/Cluster/ServerState.cpp | 24 +++++++++++++++++++++--- arangod/Cluster/ServerState.h | 15 ++++++++++++++- arangod/RestServer/ArangoServer.cpp | 4 +++- 6 files changed, 48 insertions(+), 9 deletions(-) diff --git a/arangod/Aql/Collection.cpp b/arangod/Aql/Collection.cpp index 59e453a8e0..6447769c62 100644 --- a/arangod/Aql/Collection.cpp +++ b/arangod/Aql/Collection.cpp @@ -227,8 +227,10 @@ void Collection::fillIndexes () const { if (! indexes.empty()) { return; } + + auto const role = triagens::arango::ServerState::instance()->getRole(); - if (triagens::arango::ServerState::instance()->isCoordinator()) { + if (triagens::arango::ServerState::instance()->isCoordinator(role)) { fillIndexesCoordinator(); return; } @@ -236,7 +238,7 @@ void Collection::fillIndexes () const { // must have a collection TRI_ASSERT(collection != nullptr); - if (triagens::arango::ServerState::instance()->isDBServer() && + if (triagens::arango::ServerState::instance()->isDBServer(role) && documentCollection()->_info._planId > 0) { fillIndexesDBServer(); return; diff --git a/arangod/Aql/ExecutionEngine.cpp b/arangod/Aql/ExecutionEngine.cpp index 1570e1382d..91df57c9f5 100644 --- a/arangod/Aql/ExecutionEngine.cpp +++ b/arangod/Aql/ExecutionEngine.cpp @@ -901,8 +901,9 @@ ExecutionEngine* ExecutionEngine::instanciateFromPlan (QueryRegistry* queryRegis Query* query, ExecutionPlan* plan, bool planRegisters) { - bool const isCoordinator = triagens::arango::ServerState::instance()->isCoordinator(); - bool const isDBServer = triagens::arango::ServerState::instance()->isDBServer(); + auto role = triagens::arango::ServerState::instance()->getRole(); + bool const isCoordinator = triagens::arango::ServerState::instance()->isCoordinator(role); + bool const isDBServer = triagens::arango::ServerState::instance()->isDBServer(role); ExecutionEngine* engine = nullptr; diff --git a/arangod/Cluster/HeartbeatThread.cpp b/arangod/Cluster/HeartbeatThread.cpp index 8c6ae73937..2c48ce5275 100644 --- a/arangod/Cluster/HeartbeatThread.cpp +++ b/arangod/Cluster/HeartbeatThread.cpp @@ -491,15 +491,18 @@ bool HeartbeatThread::handlePlanChangeCoordinator (uint64_t currentPlanVersion, ++it; } + // get the list of databases that we know about locally TRI_voc_tick_t* localIds = TRI_GetIdsCoordinatorDatabaseServer(_server); if (localIds != nullptr) { TRI_voc_tick_t* p = localIds; + // now check which of the local databases are also in the plan while (*p != 0) { std::vector::const_iterator r = std::find(ids.begin(), ids.end(), *p); if (r == ids.end()) { + // local database not found in the plan... TRI_DropByIdCoordinatorDatabaseServer(_server, *p, false); } diff --git a/arangod/Cluster/ServerState.cpp b/arangod/Cluster/ServerState.cpp index 5a054c059d..bf5224f30b 100644 --- a/arangod/Cluster/ServerState.cpp +++ b/arangod/Cluster/ServerState.cpp @@ -102,7 +102,7 @@ ServerState* ServerState::instance () { /// @brief get the string representation of a role //////////////////////////////////////////////////////////////////////////////// -std::string ServerState::roleToString (RoleEnum role) { +std::string ServerState::roleToString (ServerState::RoleEnum role) { switch (role) { case ROLE_UNDEFINED: return "UNDEFINED"; @@ -238,7 +238,15 @@ bool ServerState::isCoordinator () { } //////////////////////////////////////////////////////////////////////////////// -/// @brief check whether the server is a DB server (primary or secondory) +/// @brief check whether the server is a coordinator +//////////////////////////////////////////////////////////////////////////////// + +bool ServerState::isCoordinator (ServerState::RoleEnum role) { + return (role == ServerState::ROLE_COORDINATOR); +} + +//////////////////////////////////////////////////////////////////////////////// +/// @brief check whether the server is a DB server (primary or secondary) /// running in cluster mode. //////////////////////////////////////////////////////////////////////////////// @@ -249,6 +257,16 @@ bool ServerState::isDBServer () { role == ServerState::ROLE_SECONDARY); } +//////////////////////////////////////////////////////////////////////////////// +/// @brief check whether the server is a DB server (primary or secondary) +/// running in cluster mode. +//////////////////////////////////////////////////////////////////////////////// + +bool ServerState::isDBServer (ServerState::RoleEnum role) { + return (role == ServerState::ROLE_PRIMARY || + role == ServerState::ROLE_SECONDARY); +} + //////////////////////////////////////////////////////////////////////////////// /// @brief check whether the server is running in a cluster //////////////////////////////////////////////////////////////////////////////// @@ -316,7 +334,7 @@ ServerState::RoleEnum ServerState::getRole () { /// @brief set the server role //////////////////////////////////////////////////////////////////////////////// -void ServerState::setRole (RoleEnum role) { +void ServerState::setRole (ServerState::RoleEnum role) { storeRole(role); } diff --git a/arangod/Cluster/ServerState.h b/arangod/Cluster/ServerState.h index bd88f2763e..b339c7a57d 100644 --- a/arangod/Cluster/ServerState.h +++ b/arangod/Cluster/ServerState.h @@ -188,12 +188,25 @@ namespace triagens { bool isCoordinator (); //////////////////////////////////////////////////////////////////////////////// -/// @brief check whether the server is a DB server (primary or secondory) +/// @brief check whether the server is a coordinator +//////////////////////////////////////////////////////////////////////////////// + + static bool isCoordinator (RoleEnum); + +//////////////////////////////////////////////////////////////////////////////// +/// @brief check whether the server is a DB server (primary or secondary) /// running in cluster mode. //////////////////////////////////////////////////////////////////////////////// bool isDBServer (); +//////////////////////////////////////////////////////////////////////////////// +/// @brief check whether the server is a DB server (primary or secondary) +/// running in cluster mode. +//////////////////////////////////////////////////////////////////////////////// + + static bool isDBServer (RoleEnum); + //////////////////////////////////////////////////////////////////////////////// /// @brief check whether the server is running in a cluster //////////////////////////////////////////////////////////////////////////////// diff --git a/arangod/RestServer/ArangoServer.cpp b/arangod/RestServer/ArangoServer.cpp index 3f1a3cfb6a..e6e0589214 100644 --- a/arangod/RestServer/ArangoServer.cpp +++ b/arangod/RestServer/ArangoServer.cpp @@ -986,7 +986,9 @@ int ArangoServer::startupServer () { // for a cluster coordinator, the users are loaded at a later stage; // the kickstarter will trigger a bootstrap process // - if (role != ServerState::ROLE_COORDINATOR && role != ServerState::ROLE_PRIMARY && role != ServerState::ROLE_SECONDARY) { + if (role != ServerState::ROLE_COORDINATOR && + role != ServerState::ROLE_PRIMARY && + role != ServerState::ROLE_SECONDARY) { // if the authentication info could not be loaded, but authentication is turned on, // then we refuse to start