mirror of https://gitee.com/bigwinds/arangodb
Merge branch 'devel' of ssh://github.com/arangodb/arangodb into devel
This commit is contained in:
commit
4e2a9be028
|
@ -87,6 +87,10 @@ const std::vector<std::string> ServerState::RoleStr ({
|
|||
"NONE", "SNGL", "PRMR", "SCND", "CRDN", "AGNT"
|
||||
});
|
||||
|
||||
const std::vector<std::string> ServerState::RoleStrReadable ({
|
||||
"none", "single", "dbserver", "secondary", "coordinator", "agent"
|
||||
});
|
||||
|
||||
std::string ServerState::roleToString(ServerState::RoleEnum role) {
|
||||
switch (role) {
|
||||
case ROLE_UNDEFINED:
|
||||
|
@ -247,8 +251,6 @@ bool ServerState::unregister() {
|
|||
bool ServerState::registerWithRole(ServerState::RoleEnum role,
|
||||
std::string const& myAddress) {
|
||||
|
||||
setLocalInfo(RoleStr.at(role) + ":" + myAddress);
|
||||
|
||||
if (!getId().empty()) {
|
||||
LOG_TOPIC(INFO, Logger::CLUSTER)
|
||||
<< "Registering with role and localinfo. Supplied id is being ignored";
|
||||
|
@ -257,29 +259,35 @@ bool ServerState::registerWithRole(ServerState::RoleEnum role,
|
|||
|
||||
AgencyComm comm;
|
||||
AgencyCommResult result;
|
||||
std::string localInfoEncoded = StringUtils::urlEncode(getLocalInfo());
|
||||
std::string localInfoEncoded = StringUtils::replace(
|
||||
StringUtils::urlEncode(getLocalInfo()),"%2E",".");
|
||||
result = comm.getValues("Target/MapLocalToID/" + localInfoEncoded);
|
||||
|
||||
std::string id;
|
||||
bool found = true;
|
||||
|
||||
if (!result.successful()) {
|
||||
found = false;
|
||||
} else {
|
||||
VPackSlice idSlice = result.slice()[0].get(
|
||||
std::vector<std::string>({AgencyCommManager::path(), "Target",
|
||||
"MapLocalToID", localInfoEncoded}));
|
||||
std::vector<std::string>({AgencyCommManager::path(), "Target",
|
||||
"MapLocalToID", localInfoEncoded}));
|
||||
if (!idSlice.isString()) {
|
||||
found = false;
|
||||
} else {
|
||||
id = idSlice.copyString();
|
||||
LOG(WARN) << "Have ID: " + id;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
createIdForRole(comm, role, id);
|
||||
if (found) {
|
||||
|
||||
} else {
|
||||
LOG_TOPIC(DEBUG, Logger::CLUSTER)
|
||||
<< "Determining id from localinfo failed."
|
||||
<< "Continuing with registering ourselves for the first time";
|
||||
<< "Determining id from localinfo failed."
|
||||
<< "Continuing with registering ourselves for the first time";
|
||||
id = createIdForRole(comm, role);
|
||||
}
|
||||
}
|
||||
|
||||
const std::string agencyKey = roleToAgencyKey(role);
|
||||
const std::string planKey = "Plan/" + agencyKey + "/" + id;
|
||||
|
@ -364,11 +372,11 @@ void mkdir (std::string const& path) {
|
|||
/// @brief create an id for a specified role
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
std::string ServerState::createIdForRole(AgencyComm comm,
|
||||
ServerState::RoleEnum role) {
|
||||
ServerState::RoleEnum role,
|
||||
std::string id) {
|
||||
|
||||
typedef std::pair<AgencyOperation,AgencyPrecondition> operationType;
|
||||
std::string const agencyKey = roleToAgencyKey(role);
|
||||
|
||||
|
||||
VPackBuilder builder;
|
||||
builder.add(VPackValue("none"));
|
||||
|
@ -382,7 +390,6 @@ std::string ServerState::createIdForRole(AgencyComm comm,
|
|||
|
||||
auto filePath = dbpath->directory() + "/UUID";
|
||||
std::ifstream ifs(filePath);
|
||||
std::string id;
|
||||
|
||||
if (ifs.is_open()) {
|
||||
std::getline(ifs, id);
|
||||
|
@ -392,7 +399,10 @@ std::string ServerState::createIdForRole(AgencyComm comm,
|
|||
} else {
|
||||
mkdir (dbpath->directory());
|
||||
std::ofstream ofs(filePath);
|
||||
id = RoleStr.at(role) + "-" + to_string(boost::uuids::random_generator()());
|
||||
if (id.empty()) {
|
||||
id = RoleStr.at(role) + "-" +
|
||||
to_string(boost::uuids::random_generator()());
|
||||
}
|
||||
ofs << id << std::endl;
|
||||
ofs.close();
|
||||
LOG_TOPIC(INFO, Logger::CLUSTER)
|
||||
|
@ -405,6 +415,7 @@ std::string ServerState::createIdForRole(AgencyComm comm,
|
|||
<< " from agency. Agency is not initialized?";
|
||||
FATAL_ERROR_EXIT();
|
||||
}
|
||||
|
||||
VPackSlice servers = result.slice()[0].get(
|
||||
std::vector<std::string>({AgencyCommManager::path(), "Plan", agencyKey}));
|
||||
if (!servers.isObject()) {
|
||||
|
|
|
@ -43,6 +43,7 @@ class ServerState {
|
|||
};
|
||||
|
||||
static const std::vector<std::string> RoleStr;
|
||||
static const std::vector<std::string> RoleStrReadable;
|
||||
|
||||
/// @brief an enum describing the possible states a server can have
|
||||
enum StateEnum {
|
||||
|
@ -269,7 +270,7 @@ class ServerState {
|
|||
bool checkCoordinatorState(StateEnum);
|
||||
|
||||
/// @brief create an id for a specified role
|
||||
std::string createIdForRole(AgencyComm, RoleEnum);
|
||||
std::string createIdForRole(AgencyComm, RoleEnum, std::string = std::string());
|
||||
|
||||
/// @brief get the key for a role in the agency
|
||||
static std::string roleToAgencyKey(RoleEnum);
|
||||
|
|
Loading…
Reference in New Issue