From 2495b6e720ce08fd07d3f1f04b90c980d2093143 Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Wed, 15 Jan 2014 09:52:47 +0100 Subject: [PATCH 1/4] removed unused variables --- arangod/V8Server/v8-vocbase.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/arangod/V8Server/v8-vocbase.cpp b/arangod/V8Server/v8-vocbase.cpp index 3a40e6811e..d80153c96e 100644 --- a/arangod/V8Server/v8-vocbase.cpp +++ b/arangod/V8Server/v8-vocbase.cpp @@ -8344,10 +8344,6 @@ static v8::Handle JS_CreateDatabase_Coordinator (v8::Arguments const& const string name = TRI_ObjectToString(argv[0]); - //ClusterInfo* ci = ClusterInfo::instance(); - ClusterComm* cc = ClusterComm::instance(); - AgencyComm ac; - int ourerrno = TRI_ERROR_NO_ERROR; ourerrno = CreateDatabaseInAgency("Plan",name); From e094cc534268f915f3ea73e2fa5b810efec97bcc Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Wed, 15 Jan 2014 10:17:27 +0100 Subject: [PATCH 2/4] less redundancy of URLs --- arangod/Cluster/ClusterInfo.cpp | 40 ++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/arangod/Cluster/ClusterInfo.cpp b/arangod/Cluster/ClusterInfo.cpp index e3ba56489f..7e69c52fc3 100644 --- a/arangod/Cluster/ClusterInfo.cpp +++ b/arangod/Cluster/ClusterInfo.cpp @@ -443,20 +443,22 @@ vector ClusterInfo::listDatabases () { //////////////////////////////////////////////////////////////////////////////// void ClusterInfo::loadCollections () { + static const std::string prefix = "Current/Collections"; + AgencyCommResult result; { AgencyCommLocker locker("Current", "READ"); if (locker.successful()) { - result = _agency.getValues("Current/Collections", true); + result = _agency.getValues(prefix, true); } } if (result.successful()) { std::map collections; - if (result.flattenJson(collections, "Current/Collections/", false)) { + if (result.flattenJson(collections, prefix + "/", false)) { LOG_TRACE("Current/Collections loaded successfully"); WRITE_LOCKER(_lock); @@ -516,7 +518,7 @@ void ClusterInfo::loadCollections () { } } - LOG_TRACE("Error while loading Current/Collections"); + LOG_TRACE("Error while loading %s", prefix.c_str()); _collectionsValid = false; } @@ -635,21 +637,23 @@ const std::vector ClusterInfo::getCollections (DatabaseID const& //////////////////////////////////////////////////////////////////////////////// void ClusterInfo::loadServers () { + static const std::string prefix = "Current/ServersRegistered"; + AgencyCommResult result; { AgencyCommLocker locker("Current", "READ"); if (locker.successful()) { - result = _agency.getValues("Current/ServersRegistered", true); + result = _agency.getValues(prefix, true); } } if (result.successful()) { std::map servers; - if (result.flattenJson(servers, "Current/ServersRegistered/", false)) { - LOG_TRACE("Current/ServersRegistered loaded successfully"); + if (result.flattenJson(servers, prefix + "/", false)) { + LOG_TRACE("%s loaded successfully", prefix.c_str()); WRITE_LOCKER(_lock); _servers.clear(); @@ -665,7 +669,7 @@ void ClusterInfo::loadServers () { } } - LOG_TRACE("Error while loading Current/ServersRegistered"); + LOG_TRACE("Error while loading %s", prefix.c_str()); _serversValid = false; @@ -679,13 +683,13 @@ void ClusterInfo::loadServers () { //////////////////////////////////////////////////////////////////////////////// std::string ClusterInfo::getServerEndpoint (ServerID const& serverID) { + int tries = 0; if (! _serversValid) { loadServers(); + tries++; } - int tries = 0; - while (++tries <= 2) { { READ_LOCKER(_lock); @@ -709,21 +713,23 @@ std::string ClusterInfo::getServerEndpoint (ServerID const& serverID) { //////////////////////////////////////////////////////////////////////////////// void ClusterInfo::loadDBServers () { + static const std::string prefix = "Current/DBServers"; + AgencyCommResult result; { AgencyCommLocker locker("Current", "READ"); if (locker.successful()) { - result = _agency.getValues("Current/DBServers", true); + result = _agency.getValues(prefix, true); } } if (result.successful()) { std::map servers; - if (result.flattenJson(servers, "Current/DBServers/", false)) { - LOG_TRACE("Current/DBServers loaded successfully"); + if (result.flattenJson(servers, prefix + "/", false)) { + LOG_TRACE("%s loaded successfully", prefix.c_str()); WRITE_LOCKER(_lock); _DBServers.clear(); @@ -739,7 +745,7 @@ void ClusterInfo::loadDBServers () { } } - LOG_TRACE("Error while loading Current/DBServers"); + LOG_TRACE("Error while loading %s", prefix.c_str()); _DBServersValid = false; @@ -771,6 +777,8 @@ std::vector ClusterInfo::getDBServers () { //////////////////////////////////////////////////////////////////////////////// std::string ClusterInfo::getTargetServerEndpoint (ServerID const& serverID) { + static const std::string prefix = "Target/MapIDToEndpoint/"; + AgencyCommResult result; // fetch value at Target/MapIDToEndpoint @@ -778,15 +786,15 @@ std::string ClusterInfo::getTargetServerEndpoint (ServerID const& serverID) { AgencyCommLocker locker("Target", "READ"); if (locker.successful()) { - result = _agency.getValues("Target/MapIDToEndpoint/" + serverID, false); + result = _agency.getValues(prefix + serverID, false); } } if (result.successful()) { std::map out; - if (! result.flattenJson(out, "Target/MapIDToEndpoint/", false)) { - LOG_FATAL_AND_EXIT("Got an invalid JSON response for Target/MapIDToEndpoint"); + if (! result.flattenJson(out, prefix, false)) { + LOG_FATAL_AND_EXIT("Got an invalid JSON response for %s", prefix.c_str()); } // check if we can find ourselves in the list returned by the agency From e02b0b52e1f829a295d1f270ca24f74f8745a381 Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Wed, 15 Jan 2014 10:52:56 +0100 Subject: [PATCH 3/4] renamed methods --- arangod/Cluster/ClusterInfo.cpp | 43 +++++++++++++++------------------ arangod/Cluster/ClusterInfo.h | 6 ++--- arangod/Cluster/v8-cluster.cpp | 4 +-- arangod/V8Server/v8-vocbase.cpp | 8 +++--- js/server/tests/cluster.js | 2 -- 5 files changed, 29 insertions(+), 34 deletions(-) diff --git a/arangod/Cluster/ClusterInfo.cpp b/arangod/Cluster/ClusterInfo.cpp index 7e69c52fc3..357d9c3565 100644 --- a/arangod/Cluster/ClusterInfo.cpp +++ b/arangod/Cluster/ClusterInfo.cpp @@ -329,10 +329,7 @@ ClusterInfo::ClusterInfo () _DBServersValid(false) { _uniqid._currentValue = _uniqid._upperValue = 0ULL; - // Actual loading is postponed until necessary: - // loadServers(); - // loadDBServers(); - // loadCollections(); + // Actual loading into caches is postponed until necessary } //////////////////////////////////////////////////////////////////////////////// @@ -397,7 +394,7 @@ bool ClusterInfo::doesDatabaseExist (DatabaseID const& databaseID) { int tries = 0; if (! _collectionsValid) { - loadCollections(); + loadCurrentCollections(); ++tries; } @@ -412,8 +409,8 @@ bool ClusterInfo::doesDatabaseExist (DatabaseID const& databaseID) { } } - // must call loadCollections outside the lock - loadCollections(); + // must load collections outside the lock + loadCurrentCollections(); } return false; @@ -427,7 +424,7 @@ vector ClusterInfo::listDatabases () { vector res; if (! _collectionsValid) { - loadCollections(); + loadCurrentCollections(); } AllCollections::const_iterator it; @@ -442,7 +439,7 @@ vector ClusterInfo::listDatabases () { /// Usually one does not have to call this directly. //////////////////////////////////////////////////////////////////////////////// -void ClusterInfo::loadCollections () { +void ClusterInfo::loadCurrentCollections () { static const std::string prefix = "Current/Collections"; AgencyCommResult result; @@ -529,12 +526,13 @@ void ClusterInfo::loadCollections () { CollectionInfo ClusterInfo::getCollection (DatabaseID const& databaseID, CollectionID const& collectionID) { - if (! _collectionsValid) { - loadCollections(); - } - int tries = 0; + if (! _collectionsValid) { + loadCurrentCollections(); + ++tries; + } + while (++tries <= 2) { { READ_LOCKER(_lock); @@ -551,8 +549,8 @@ CollectionInfo ClusterInfo::getCollection (DatabaseID const& databaseID, } } - // must call loadCollections outside the lock - loadCollections(); + // must load collections outside the lock + loadCurrentCollections(); } return CollectionInfo(); @@ -605,7 +603,7 @@ const std::vector ClusterInfo::getCollections (DatabaseID const& std::vector result; // always reload - loadCollections(); + loadCurrentCollections(); READ_LOCKER(_lock); // look up database by id @@ -712,7 +710,7 @@ std::string ClusterInfo::getServerEndpoint (ServerID const& serverID) { /// Usually one does not have to call this directly. //////////////////////////////////////////////////////////////////////////////// -void ClusterInfo::loadDBServers () { +void ClusterInfo::loadCurrentDBServers () { static const std::string prefix = "Current/DBServers"; AgencyCommResult result; @@ -757,9 +755,9 @@ void ClusterInfo::loadDBServers () { /// currently registered //////////////////////////////////////////////////////////////////////////////// -std::vector ClusterInfo::getDBServers () { +std::vector ClusterInfo::getCurrentDBServers () { if (! _DBServersValid) { - loadDBServers(); + loadCurrentDBServers(); } std::vector res; @@ -770,7 +768,6 @@ std::vector ClusterInfo::getDBServers () { return res; } - //////////////////////////////////////////////////////////////////////////////// /// @brief lookup the server's endpoint by scanning Target/MapIDToEnpdoint for /// our id @@ -819,7 +816,7 @@ ServerID ClusterInfo::getResponsibleServer (ShardID const& shardID) { int tries = 0; if (! _collectionsValid) { - loadCollections(); + loadCurrentCollections(); tries++; } @@ -833,8 +830,8 @@ ServerID ClusterInfo::getResponsibleServer (ShardID const& shardID) { } } - // must call loadCollections outside the lock - loadCollections(); + // must load collections outside the lock + loadCurrentCollections(); } return ServerID(""); diff --git a/arangod/Cluster/ClusterInfo.h b/arangod/Cluster/ClusterInfo.h index ffbf799faf..20b60c0c29 100644 --- a/arangod/Cluster/ClusterInfo.h +++ b/arangod/Cluster/ClusterInfo.h @@ -298,7 +298,7 @@ namespace triagens { /// Usually one does not have to call this directly. //////////////////////////////////////////////////////////////////////////////// - void loadCollections (); + void loadCurrentCollections (); //////////////////////////////////////////////////////////////////////////////// /// @brief ask about a collection @@ -332,14 +332,14 @@ namespace triagens { /// Usually one does not have to call this directly. //////////////////////////////////////////////////////////////////////////////// - void loadDBServers (); + void loadCurrentDBServers (); //////////////////////////////////////////////////////////////////////////////// /// @brief return a list of all DBServers in the cluster that have /// currently registered //////////////////////////////////////////////////////////////////////////////// - std::vector getDBServers (); + std::vector getCurrentDBServers (); //////////////////////////////////////////////////////////////////////////////// /// @brief (re-)load the information about servers from the agency diff --git a/arangod/Cluster/v8-cluster.cpp b/arangod/Cluster/v8-cluster.cpp index 8ac2518aad..0854d24931 100644 --- a/arangod/Cluster/v8-cluster.cpp +++ b/arangod/Cluster/v8-cluster.cpp @@ -795,7 +795,7 @@ static v8::Handle JS_GetDBServers (v8::Arguments const& argv) { TRI_V8_EXCEPTION_USAGE(scope, "DBServers()"); } - std::vector DBServers = ClusterInfo::instance()->getDBServers(); + std::vector DBServers = ClusterInfo::instance()->getCurrentDBServers(); v8::Handle l = v8::Array::New(); @@ -819,7 +819,7 @@ static v8::Handle JS_ReloadDBServers (v8::Arguments const& argv) { TRI_V8_EXCEPTION_USAGE(scope, "reloadDBServers()"); } - ClusterInfo::instance()->loadDBServers(); + ClusterInfo::instance()->loadCurrentDBServers(); return scope.Close(v8::Undefined()); } diff --git a/arangod/V8Server/v8-vocbase.cpp b/arangod/V8Server/v8-vocbase.cpp index d80153c96e..77bbdaec0f 100644 --- a/arangod/V8Server/v8-vocbase.cpp +++ b/arangod/V8Server/v8-vocbase.cpp @@ -1850,7 +1850,7 @@ static v8::Handle CreateCollectionCoordinator (v8::Arguments const& a const std::string cid = StringUtils::itoa(id); // fetch list of available servers in cluster, and shuffle them randomly - std::vector dbServers = ClusterInfo::instance()->getDBServers(); + std::vector dbServers = ClusterInfo::instance()->getCurrentDBServers(); if (dbServers.empty()) { TRI_V8_EXCEPTION_MESSAGE(scope, TRI_ERROR_INTERNAL, "no database servers found in cluster"); @@ -8179,7 +8179,7 @@ static v8::Handle JS_ListDatabases_Coordinator ClusterInfo* ci = ClusterInfo::instance(); if (argv.Length() == 0) { - ci->loadCollections(); + ci->loadCurrentCollections(); vector list = ci->listDatabases(); v8::Handle result = v8::Array::New(); for (size_t i = 0; i < list.size(); ++i) { @@ -8193,7 +8193,7 @@ static v8::Handle JS_ListDatabases_Coordinator int tries = 0; vector DBServers; while (++tries <= 2) { - DBServers = ci->getDBServers(); + DBServers = ci->getCurrentDBServers(); if (DBServers.size() != 0) { ServerID sid = DBServers[0]; ClusterComm* cc = ClusterComm::instance(); @@ -8227,7 +8227,7 @@ static v8::Handle JS_ListDatabases_Coordinator delete res; } } - ci->loadDBServers(); // just in case some new have arrived + ci->loadCurrentDBServers(); // just in case some new have arrived } // Give up: return scope.Close(v8::Undefined()); diff --git a/js/server/tests/cluster.js b/js/server/tests/cluster.js index 54ffe3577d..85cb04b733 100644 --- a/js/server/tests/cluster.js +++ b/js/server/tests/cluster.js @@ -92,8 +92,6 @@ function ClusterEnabledSuite () { catch (err) { } }); - - agency.set("Sync/LatestID", "0"); }; return { From b5a448ffdbaef80a8630a1b27e8fdef94b71aa45 Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Wed, 15 Jan 2014 11:03:01 +0100 Subject: [PATCH 4/4] added loadPlannedDatabases method --- arangod/Cluster/ClusterInfo.cpp | 44 ++++++++++++++++++++++++++++++++- arangod/Cluster/ClusterInfo.h | 8 ++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/arangod/Cluster/ClusterInfo.cpp b/arangod/Cluster/ClusterInfo.cpp index 357d9c3565..25f98bca96 100644 --- a/arangod/Cluster/ClusterInfo.cpp +++ b/arangod/Cluster/ClusterInfo.cpp @@ -434,6 +434,48 @@ vector ClusterInfo::listDatabases () { return res; } +//////////////////////////////////////////////////////////////////////////////// +/// @brief (re-)load the information about planned databases +/// Usually one does not have to call this directly. +//////////////////////////////////////////////////////////////////////////////// + +void ClusterInfo::loadPlannedDatabases () { + static const std::string prefix = "Plan/Databases"; + + AgencyCommResult result; + + { + AgencyCommLocker locker("Plan", "READ"); + + if (locker.successful()) { + result = _agency.getValues(prefix, true); + } + } + + if (result.successful()) { + std::map databases; + + if (result.flattenJson(databases, prefix + "/", false)) { + LOG_TRACE("%s loaded successfully", prefix.c_str()); + + WRITE_LOCKER(_lock); + _plannedDatabases.clear(); + + std::map::const_iterator it; + for (it = databases.begin(); it != databases.end(); ++it) { + const std::string& name = (*it).first; + TRI_json_t* options = JsonHelper::fromString((*it).second); + + _plannedDatabases.insert(std::make_pair(name, options)); + } + + return; + } + } + + LOG_TRACE("Error while loading %s", prefix.c_str()); +} + //////////////////////////////////////////////////////////////////////////////// /// @brief (re-)load the information about collections from the agency /// Usually one does not have to call this directly. @@ -456,7 +498,7 @@ void ClusterInfo::loadCurrentCollections () { std::map collections; if (result.flattenJson(collections, prefix + "/", false)) { - LOG_TRACE("Current/Collections loaded successfully"); + LOG_TRACE("%s loaded successfully", prefix.c_str()); WRITE_LOCKER(_lock); _collections.clear(); diff --git a/arangod/Cluster/ClusterInfo.h b/arangod/Cluster/ClusterInfo.h index 20b60c0c29..2fa93c5a28 100644 --- a/arangod/Cluster/ClusterInfo.h +++ b/arangod/Cluster/ClusterInfo.h @@ -300,6 +300,13 @@ namespace triagens { void loadCurrentCollections (); +//////////////////////////////////////////////////////////////////////////////// +/// @brief (re-)load the information about planned databases +/// Usually one does not have to call this directly. +//////////////////////////////////////////////////////////////////////////////// + + void loadPlannedDatabases (); + //////////////////////////////////////////////////////////////////////////////// /// @brief ask about a collection /// If it is not found in the cache, the cache is reloaded once. @@ -391,6 +398,7 @@ namespace triagens { _uniqid; // Cached data from the agency, we reload whenever necessary: + std::map _plannedDatabases; // from Plan/Databases AllCollections _collections; // from Current/Collections/ bool _collectionsValid; std::map _servers; // from Current/ServersRegistered