1
0
Fork 0

Fixing issues

This commit is contained in:
Kaveh Vahedipour 2016-03-23 15:16:47 +01:00
parent f8cbfa9d3b
commit 7254ad4c9e
12 changed files with 51 additions and 37 deletions

View File

@ -11,7 +11,7 @@ if (POLICY CMP0037)
endif () endif ()
option(VERBOSE OFF) option(VERBOSE OFF)
#set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9" CACHE STRING "deployment target for MacOSX") set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9" CACHE STRING "deployment target for MacOSX")
project(ArangoDB) project(ArangoDB)

View File

@ -82,6 +82,18 @@ inline std::ostream& operator<< (std::ostream& os, std::list<T> const& l) {
return os; return os;
} }
struct constituent_t { // Constituent type
id_t id;
std::string endpoint;
};
typedef std::vector<constituent_t> constituency_t; // Constituency type
typedef uint32_t state_t; // State type
typedef std::chrono::duration<double> duration_t; // Duration type
using query_t = std::shared_ptr<arangodb::velocypack::Builder>;
struct AgentConfiguration { struct AgentConfiguration {
id_t id; id_t id;
float min_ping; float min_ping;
@ -109,20 +121,22 @@ struct AgentConfiguration {
s << *this; s << *this;
return s.str(); return s.str();
} }
query_t toBuilder () {
query_t ret = std::make_shared<arangodb::velocypack::Builder>();
ret->openObject();
ret->add("endpoints", VPackValue(VPackValueType::Array));
for (auto const& i : end_points)
ret->add(VPackValue(i));
ret->close();
ret->add("id",VPackValue(id));
ret->add("min_ping",VPackValue(min_ping));
ret->add("max_ping",VPackValue(max_ping));
ret->close();
return ret;
}
}; };
typedef AgentConfiguration config_t; typedef AgentConfiguration config_t;
struct constituent_t { // Constituent type
id_t id;
std::string endpoint;
};
typedef std::vector<constituent_t> constituency_t; // Constituency type
typedef uint32_t state_t; // State type
typedef std::chrono::duration<double> duration_t; // Duration type
using query_t = std::shared_ptr<arangodb::velocypack::Builder>;
struct vote_ret_t { struct vote_ret_t {
query_t result; query_t result;
vote_ret_t (query_t res) : result(res) {} vote_ret_t (query_t res) : result(res) {}

View File

@ -129,7 +129,7 @@ public:
* @brief 1. Deal with appendEntries to slaves. * @brief 1. Deal with appendEntries to slaves.
* 2. Report success of write processes. * 2. Report success of write processes.
*/ */
void run (); void run () override final;
void beginShutdown () override; void beginShutdown () override;
/** /**

View File

@ -71,8 +71,7 @@ void ApplicationAgency::setupOptions(
bool ApplicationAgency::prepare() { bool ApplicationAgency::prepare() {
_disabled = _agency_endpoints.empty() || _disabled = (_agent_id == std::numeric_limits<uint32_t>::max());
_agent_id == std::numeric_limits<uint32_t>::max();
if (_disabled) { if (_disabled) {
return true; return true;

View File

@ -93,12 +93,12 @@ class ApplicationAgency : virtual public arangodb::rest::ApplicationFeature {
public: public:
void setupOptions(std::map<std::string, void setupOptions(std::map<std::string,
arangodb::basics::ProgramOptionsDescription>&); arangodb::basics::ProgramOptionsDescription>&) override final;
bool prepare(); bool prepare() override final;
bool start(); bool start() override final;
bool open(); bool open() override final;
void close(); void close() override final;
agent_t* agent() const; agent_t* agent() const;

View File

@ -43,7 +43,11 @@ void Constituent::configure(Agent* agent) {
if (size() == 1) { if (size() == 1) {
_role = LEADER; _role = LEADER;
} else { } else {
try {
_votes.resize(size()); _votes.resize(size());
} catch (std::exception const& e) {
LOG(FATAL) << "Cannot resize votes vector to " << size();
}
_id = _agent->config().id; _id = _agent->config().id;
if (_agent->config().notify) {// (notify everyone) if (_agent->config().notify) {// (notify everyone)
notifyAll(); notifyAll();
@ -191,7 +195,11 @@ const constituency_t& Constituent::gossip () {
void Constituent::callElection() { void Constituent::callElection() {
_votes[_id] = true; // vote for myself try {
_votes.at(_id) = true; // vote for myself
} catch (std::out_of_range const& oor) {
LOG(FATAL) << "_votes vector is not properly sized!";
}
_cast = true; _cast = true;
if(_role == CANDIDATE) if(_role == CANDIDATE)
_term++; // raise my term _term++; // raise my term

View File

@ -84,7 +84,7 @@ public:
/** /**
* @brief My daily business * @brief My daily business
*/ */
void run(); void run() override final;
/** /**
* @brief Who is leading * @brief Who is leading

View File

@ -54,7 +54,7 @@ using namespace arangodb::velocypack;
class StoreException : public std::exception { class StoreException : public std::exception {
public: public:
StoreException(std::string const& message) : _message(message) {} StoreException(std::string const& message) : _message(message) {}
virtual char const* what() const noexcept { return _message.c_str(); } virtual char const* what() const noexcept override final { return _message.c_str(); }
private: private:
std::string _message; std::string _message;
}; };

View File

@ -148,7 +148,7 @@ HttpHandler::status_t RestAgencyHandler::handleTest() {
body.add("id", Value(_agent->id())); body.add("id", Value(_agent->id()));
body.add("term", Value(_agent->term())); body.add("term", Value(_agent->term()));
body.add("leaderId", Value(_agent->leaderID())); body.add("leaderId", Value(_agent->leaderID()));
body.add("configuration", Value(_agent->config().toString())); body.add("configuration", _agent->config().toBuilder());
body.close(); body.close();
generateResult(body.slice()); generateResult(body.slice());
return HttpHandler::status_t(HANDLER_DONE); return HttpHandler::status_t(HANDLER_DONE);

View File

@ -466,13 +466,6 @@ class ArangoServer {
aql::QueryRegistry* _queryRegistry; aql::QueryRegistry* _queryRegistry;
//////////////////////////////////////////////////////////////////////////////
/// @brief the agent
//////////////////////////////////////////////////////////////////////////////
consensus::Agent* _agent;
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
/// @brief ptr to pair of _applicationV8 and _queryRegistry for _api/aql /// @brief ptr to pair of _applicationV8 and _queryRegistry for _api/aql
/// handler /// handler

View File

@ -66,13 +66,13 @@ function agencyTestSuite () {
return res; return res;
} }
function writeAgencyRaw(list) { /* function writeAgencyRaw(list) {
var res = request({url: agencyServers[whoseTurn] + "/_api/agency/write", method: "POST", var res = request({url: agencyServers[whoseTurn] + "/_api/agency/write", method: "POST",
followRedirects: true, body: list, followRedirects: true, body: list,
headers: {"Content-Type": "application/json"}}); headers: {"Content-Type": "application/json"}});
res.bodyParsed = JSON.parse(res.body); res.bodyParsed = JSON.parse(res.body);
return res; return res;
} }*/
function readAndCheck(list) { function readAndCheck(list) {
var res = readAgency(list); var res = readAgency(list);

View File

@ -96,7 +96,7 @@ class Exception : public virtual std::exception {
~Exception() throw(); ~Exception() throw();
public: public:
char const* what() const throw(); char const* what() const throw() override;
std::string message() const throw(); std::string message() const throw();
int code() const throw(); int code() const throw();
void addToMessage(std::string const&); void addToMessage(std::string const&);