1
0
Fork 0

fixed arangom script

This commit is contained in:
Jan Steemann 2014-01-15 15:13:26 +01:00
parent 85c75926e3
commit f66c4400b4
3 changed files with 134 additions and 7 deletions

View File

@ -353,6 +353,8 @@ ClusterInfo::ClusterInfo ()
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
ClusterInfo::~ClusterInfo () { ClusterInfo::~ClusterInfo () {
clearPlannedDatabases();
clearCurrentDatabases();
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -400,6 +402,9 @@ void ClusterInfo::flush () {
_collections.clear(); _collections.clear();
_servers.clear(); _servers.clear();
_shardIds.clear(); _shardIds.clear();
clearPlannedDatabases();
clearCurrentDatabases();
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -450,6 +455,50 @@ vector<DatabaseID> ClusterInfo::listDatabases () {
return res; return res;
} }
////////////////////////////////////////////////////////////////////////////////
/// @brief flushes the list of planned databases
////////////////////////////////////////////////////////////////////////////////
void ClusterInfo::clearPlannedDatabases () {
std::map<DatabaseID, TRI_json_t*>::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<DatabaseID, std::map<ServerID, TRI_json_t*> >::iterator it = _currentDatabases.begin();
while (it != _currentDatabases.end()) {
std::map<ServerID, TRI_json_t*>::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 /// @brief (re-)load the information about planned databases
/// Usually one does not have to call this directly. /// Usually one does not have to call this directly.
@ -472,7 +521,7 @@ void ClusterInfo::loadPlannedDatabases () {
result.parse(prefix + "/", false); result.parse(prefix + "/", false);
WRITE_LOCKER(_lock); WRITE_LOCKER(_lock);
_plannedDatabases.clear(); clearPlannedDatabases();
std::map<std::string, AgencyCommResultEntry>::iterator it = result._values.begin(); std::map<std::string, AgencyCommResultEntry>::iterator it = result._values.begin();
@ -491,6 +540,63 @@ void ClusterInfo::loadPlannedDatabases () {
LOG_TRACE("Error while loading %s", prefix.c_str()); 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<std::string, AgencyCommResultEntry>::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<std::string> parts = triagens::basics::StringUtils::split(key, '/');
const std::string& database = parts[0];
std::map<std::string, std::map<ServerID, TRI_json_t*> >::iterator it2 = _currentDatabases.find(database);
if (it2 == _currentDatabases.end()) {
// insert an empty list for this database
std::map<ServerID, TRI_json_t*> empty;
it2 = _currentDatabases.insert(std::make_pair<DatabaseID, std::map<ServerID, TRI_json_t*> >(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<ServerID, TRI_json_t*>(parts[1], json));
}
}
return;
}
LOG_TRACE("Error while loading %s", prefix.c_str());
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief (re-)load the information about collections from the agency /// @brief (re-)load the information about collections from the agency
/// Usually one does not have to call this directly. /// Usually one does not have to call this directly.

View File

@ -302,6 +302,18 @@ namespace triagens {
void loadCurrentCollections (); 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 /// @brief (re-)load the information about planned databases
/// Usually one does not have to call this directly. /// Usually one does not have to call this directly.
@ -309,6 +321,13 @@ namespace triagens {
void loadPlannedDatabases (); 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 /// @brief ask about a collection
/// If it is not found in the cache, the cache is reloaded once. /// 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: // Cached data from the agency, we reload whenever necessary:
std::map<DatabaseID, struct TRI_json_s*> _plannedDatabases; // from Plan/Databases std::map<DatabaseID, struct TRI_json_s*> _plannedDatabases; // from Plan/Databases
std::map<DatabaseID, std::map<ServerID, struct TRI_json_s*> > _currentDatabases; // from Current/Databases
AllCollections _collections; // from Current/Collections/ AllCollections _collections; // from Current/Collections/
bool _collectionsValid; bool _collectionsValid;
std::map<ServerID, std::string> _servers; // from Current/ServersRegistered std::map<ServerID, std::string> _servers; // from Current/ServersRegistered

12
arangom
View File

@ -29,34 +29,34 @@ function set() {
value=$2 value=$2
if [ "x$value" == "x" ] ; then if [ "x$value" == "x" ] ; then
echo "Creating directory $PREFIX$key" 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 else
echo "Setting key $PREFIX$key to value $value" 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 fi
} }
if [ "$1" == "init" ] ; then 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/MapLocalToID
set Target/MapIDToEndpoint set Target/MapIDToEndpoint
set Target/Version 1 set Target/Version "\"1\""
set Target/Lock "\"UNLOCKED\"" set Target/Lock "\"UNLOCKED\""
set Target/DBServers set Target/DBServers
set Target/Coordinators set Target/Coordinators
set Target/Databases/@Usystem "{}" set Target/Databases/@Usystem "{}"
set Target/Collections/@Usystem set Target/Collections/@Usystem
set Plan/Version 1 set Plan/Version "\"1\""
set Plan/Lock "\"UNLOCKED\"" set Plan/Lock "\"UNLOCKED\""
set Plan/DBServers set Plan/DBServers
set Plan/Coordinators set Plan/Coordinators
set Plan/Databases/@Usystem "{}" set Plan/Databases/@Usystem "{}"
set Plan/Collections/@Usystem set Plan/Collections/@Usystem
set Current/Version 1 set Current/Version "\"1\""
set Current/Lock "\"UNLOCKED\"" set Current/Lock "\"UNLOCKED\""
set Current/DBServers set Current/DBServers
set Current/Coordinators set Current/Coordinators