diff --git a/arangod/Cluster/ClusterInfo.cpp b/arangod/Cluster/ClusterInfo.cpp index cb7f394867..6361ec2ed0 100644 --- a/arangod/Cluster/ClusterInfo.cpp +++ b/arangod/Cluster/ClusterInfo.cpp @@ -353,6 +353,8 @@ ClusterInfo::ClusterInfo () //////////////////////////////////////////////////////////////////////////////// ClusterInfo::~ClusterInfo () { + clearPlannedDatabases(); + clearCurrentDatabases(); } // ----------------------------------------------------------------------------- @@ -400,6 +402,9 @@ void ClusterInfo::flush () { _collections.clear(); _servers.clear(); _shardIds.clear(); + + clearPlannedDatabases(); + clearCurrentDatabases(); } //////////////////////////////////////////////////////////////////////////////// @@ -450,6 +455,50 @@ vector ClusterInfo::listDatabases () { return res; } +//////////////////////////////////////////////////////////////////////////////// +/// @brief flushes the list of planned databases +//////////////////////////////////////////////////////////////////////////////// + +void ClusterInfo::clearPlannedDatabases () { + std::map::iterator it = _plannedDatabases.begin(); + + while (it != _plannedDatabases.end()) { + TRI_json_t* json = (*it).second; + + if (json != 0) { + TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json); + } + ++it; + } + + _plannedDatabases.clear(); +} + +//////////////////////////////////////////////////////////////////////////////// +/// @brief flushes the list of current databases +//////////////////////////////////////////////////////////////////////////////// + +void ClusterInfo::clearCurrentDatabases () { + std::map >::iterator it = _currentDatabases.begin(); + + while (it != _currentDatabases.end()) { + std::map::iterator it2 = (*it).second.begin(); + + while (it2 != (*it).second.end()) { + TRI_json_t* json = (*it2).second; + + if (json != 0) { + TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json); + } + + ++it2; + } + ++it; + } + + _currentDatabases.clear(); +} + //////////////////////////////////////////////////////////////////////////////// /// @brief (re-)load the information about planned databases /// Usually one does not have to call this directly. @@ -472,7 +521,7 @@ void ClusterInfo::loadPlannedDatabases () { result.parse(prefix + "/", false); WRITE_LOCKER(_lock); - _plannedDatabases.clear(); + clearPlannedDatabases(); std::map::iterator it = result._values.begin(); @@ -491,6 +540,63 @@ void ClusterInfo::loadPlannedDatabases () { LOG_TRACE("Error while loading %s", prefix.c_str()); } +//////////////////////////////////////////////////////////////////////////////// +/// @brief (re-)load the information about current databases +/// Usually one does not have to call this directly. +//////////////////////////////////////////////////////////////////////////////// + +void ClusterInfo::loadCurrentDatabases () { + static const std::string prefix = "Current/Databases"; + + AgencyCommResult result; + + { + AgencyCommLocker locker("Plan", "READ"); + + if (locker.successful()) { + result = _agency.getValues(prefix, true); + } + } + + if (result.successful()) { + result.parse(prefix + "/", true); + + WRITE_LOCKER(_lock); + clearCurrentDatabases(); + + std::map::iterator it = result._values.begin(); + + while (it != result._values.end()) { + const std::string& key = (*it).first; + + // each entry consists of a database id and a collection id, separated by '/' + std::vector parts = triagens::basics::StringUtils::split(key, '/'); + + const std::string& database = parts[0]; + + std::map >::iterator it2 = _currentDatabases.find(database); + + if (it2 == _currentDatabases.end()) { + // insert an empty list for this database + std::map empty; + it2 = _currentDatabases.insert(std::make_pair >(database, empty)).first; + } + + if (parts.size() == 2) { + // got a server name + TRI_json_t* json = (*it).second._json; + // steal the JSON + (*it).second._json = 0; + (*it2).second.insert(std::make_pair(parts[1], json)); + } + } + + 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. diff --git a/arangod/Cluster/ClusterInfo.h b/arangod/Cluster/ClusterInfo.h index c4054e572b..7a7b252211 100644 --- a/arangod/Cluster/ClusterInfo.h +++ b/arangod/Cluster/ClusterInfo.h @@ -302,6 +302,18 @@ namespace triagens { void loadCurrentCollections (); +//////////////////////////////////////////////////////////////////////////////// +/// @brief flushes the list of planned databases +//////////////////////////////////////////////////////////////////////////////// + + void clearPlannedDatabases (); + +//////////////////////////////////////////////////////////////////////////////// +/// @brief flushes the list of current databases +//////////////////////////////////////////////////////////////////////////////// + + void clearCurrentDatabases (); + //////////////////////////////////////////////////////////////////////////////// /// @brief (re-)load the information about planned databases /// Usually one does not have to call this directly. @@ -309,6 +321,13 @@ namespace triagens { void loadPlannedDatabases (); +//////////////////////////////////////////////////////////////////////////////// +/// @brief (re-)load the information about current databases +/// Usually one does not have to call this directly. +//////////////////////////////////////////////////////////////////////////////// + + void loadCurrentDatabases (); + //////////////////////////////////////////////////////////////////////////////// /// @brief ask about a collection /// If it is not found in the cache, the cache is reloaded once. @@ -401,6 +420,8 @@ namespace triagens { // Cached data from the agency, we reload whenever necessary: std::map _plannedDatabases; // from Plan/Databases + std::map > _currentDatabases; // from Current/Databases + AllCollections _collections; // from Current/Collections/ bool _collectionsValid; std::map _servers; // from Current/ServersRegistered diff --git a/arangom b/arangom index 632d425604..ed38154ee3 100755 --- a/arangom +++ b/arangom @@ -29,34 +29,34 @@ function set() { value=$2 if [ "x$value" == "x" ] ; then echo "Creating directory $PREFIX$key" - $CURL -X PUT "$URL$PREFIX$key?dir=true" > /dev/null || exit 1 + $CURL -X PUT -L "$URL$PREFIX$key?dir=true" > /dev/null || exit 1 else echo "Setting key $PREFIX$key to value $value" - $CURL -X PUT "$URL$PREFIX$key" -d "value=$value" > /dev/null || exit 1 + $CURL -X PUT -L "$URL$PREFIX$key" -d "value=$value" > /dev/null || exit 1 fi } if [ "$1" == "init" ] ; then - $CURL -X DELETE "$URL$PREFIX?recursive=true" > /dev/null + $CURL -X DELETE -L "$URL$PREFIX?recursive=true" > /dev/null set Target/MapLocalToID set Target/MapIDToEndpoint - set Target/Version 1 + set Target/Version "\"1\"" set Target/Lock "\"UNLOCKED\"" set Target/DBServers set Target/Coordinators set Target/Databases/@Usystem "{}" set Target/Collections/@Usystem - set Plan/Version 1 + set Plan/Version "\"1\"" set Plan/Lock "\"UNLOCKED\"" set Plan/DBServers set Plan/Coordinators set Plan/Databases/@Usystem "{}" set Plan/Collections/@Usystem - set Current/Version 1 + set Current/Version "\"1\"" set Current/Lock "\"UNLOCKED\"" set Current/DBServers set Current/Coordinators