1
0
Fork 0

less redundancy of URLs

This commit is contained in:
Jan Steemann 2014-01-15 10:17:27 +01:00
parent 2495b6e720
commit e094cc5342
1 changed files with 24 additions and 16 deletions

View File

@ -443,20 +443,22 @@ vector<DatabaseID> ClusterInfo::listDatabases () {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void ClusterInfo::loadCollections () { void ClusterInfo::loadCollections () {
static const std::string prefix = "Current/Collections";
AgencyCommResult result; AgencyCommResult result;
{ {
AgencyCommLocker locker("Current", "READ"); AgencyCommLocker locker("Current", "READ");
if (locker.successful()) { if (locker.successful()) {
result = _agency.getValues("Current/Collections", true); result = _agency.getValues(prefix, true);
} }
} }
if (result.successful()) { if (result.successful()) {
std::map<std::string, std::string> collections; std::map<std::string, std::string> collections;
if (result.flattenJson(collections, "Current/Collections/", false)) { if (result.flattenJson(collections, prefix + "/", false)) {
LOG_TRACE("Current/Collections loaded successfully"); LOG_TRACE("Current/Collections loaded successfully");
WRITE_LOCKER(_lock); 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; _collectionsValid = false;
} }
@ -635,21 +637,23 @@ const std::vector<CollectionInfo> ClusterInfo::getCollections (DatabaseID const&
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void ClusterInfo::loadServers () { void ClusterInfo::loadServers () {
static const std::string prefix = "Current/ServersRegistered";
AgencyCommResult result; AgencyCommResult result;
{ {
AgencyCommLocker locker("Current", "READ"); AgencyCommLocker locker("Current", "READ");
if (locker.successful()) { if (locker.successful()) {
result = _agency.getValues("Current/ServersRegistered", true); result = _agency.getValues(prefix, true);
} }
} }
if (result.successful()) { if (result.successful()) {
std::map<std::string, std::string> servers; std::map<std::string, std::string> servers;
if (result.flattenJson(servers, "Current/ServersRegistered/", false)) { if (result.flattenJson(servers, prefix + "/", false)) {
LOG_TRACE("Current/ServersRegistered loaded successfully"); LOG_TRACE("%s loaded successfully", prefix.c_str());
WRITE_LOCKER(_lock); WRITE_LOCKER(_lock);
_servers.clear(); _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; _serversValid = false;
@ -679,13 +683,13 @@ void ClusterInfo::loadServers () {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
std::string ClusterInfo::getServerEndpoint (ServerID const& serverID) { std::string ClusterInfo::getServerEndpoint (ServerID const& serverID) {
int tries = 0;
if (! _serversValid) { if (! _serversValid) {
loadServers(); loadServers();
tries++;
} }
int tries = 0;
while (++tries <= 2) { while (++tries <= 2) {
{ {
READ_LOCKER(_lock); READ_LOCKER(_lock);
@ -709,21 +713,23 @@ std::string ClusterInfo::getServerEndpoint (ServerID const& serverID) {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void ClusterInfo::loadDBServers () { void ClusterInfo::loadDBServers () {
static const std::string prefix = "Current/DBServers";
AgencyCommResult result; AgencyCommResult result;
{ {
AgencyCommLocker locker("Current", "READ"); AgencyCommLocker locker("Current", "READ");
if (locker.successful()) { if (locker.successful()) {
result = _agency.getValues("Current/DBServers", true); result = _agency.getValues(prefix, true);
} }
} }
if (result.successful()) { if (result.successful()) {
std::map<std::string, std::string> servers; std::map<std::string, std::string> servers;
if (result.flattenJson(servers, "Current/DBServers/", false)) { if (result.flattenJson(servers, prefix + "/", false)) {
LOG_TRACE("Current/DBServers loaded successfully"); LOG_TRACE("%s loaded successfully", prefix.c_str());
WRITE_LOCKER(_lock); WRITE_LOCKER(_lock);
_DBServers.clear(); _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; _DBServersValid = false;
@ -771,6 +777,8 @@ std::vector<ServerID> ClusterInfo::getDBServers () {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
std::string ClusterInfo::getTargetServerEndpoint (ServerID const& serverID) { std::string ClusterInfo::getTargetServerEndpoint (ServerID const& serverID) {
static const std::string prefix = "Target/MapIDToEndpoint/";
AgencyCommResult result; AgencyCommResult result;
// fetch value at Target/MapIDToEndpoint // fetch value at Target/MapIDToEndpoint
@ -778,15 +786,15 @@ std::string ClusterInfo::getTargetServerEndpoint (ServerID const& serverID) {
AgencyCommLocker locker("Target", "READ"); AgencyCommLocker locker("Target", "READ");
if (locker.successful()) { if (locker.successful()) {
result = _agency.getValues("Target/MapIDToEndpoint/" + serverID, false); result = _agency.getValues(prefix + serverID, false);
} }
} }
if (result.successful()) { if (result.successful()) {
std::map<std::string, std::string> out; std::map<std::string, std::string> out;
if (! result.flattenJson(out, "Target/MapIDToEndpoint/", false)) { if (! result.flattenJson(out, prefix, false)) {
LOG_FATAL_AND_EXIT("Got an invalid JSON response for Target/MapIDToEndpoint"); 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 // check if we can find ourselves in the list returned by the agency