From 7254ad4c9e67b436b16ab809f69c99cea8d98348 Mon Sep 17 00:00:00 2001 From: Kaveh Vahedipour Date: Wed, 23 Mar 2016 15:16:47 +0100 Subject: [PATCH] Fixing issues --- CMakeLists.txt | 2 +- arangod/Agency/AgencyCommon.h | 36 ++++++++++++++++------- arangod/Agency/Agent.h | 2 +- arangod/Agency/ApplicationAgency.cpp | 3 +- arangod/Agency/ApplicationAgency.h | 10 +++---- arangod/Agency/Constituent.cpp | 16 +++++++--- arangod/Agency/Constituent.h | 2 +- arangod/Agency/Store.h | 2 +- arangod/RestHandler/RestAgencyHandler.cpp | 2 +- arangod/RestServer/ArangoServer.h | 7 ----- js/client/tests/agency/agency-test.js | 4 +-- lib/Basics/Exceptions.h | 2 +- 12 files changed, 51 insertions(+), 37 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4f53907e74..10d973979e 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ if (POLICY CMP0037) endif () 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) diff --git a/arangod/Agency/AgencyCommon.h b/arangod/Agency/AgencyCommon.h index 89e25c4e94..41e0b5c40a 100644 --- a/arangod/Agency/AgencyCommon.h +++ b/arangod/Agency/AgencyCommon.h @@ -82,6 +82,18 @@ inline std::ostream& operator<< (std::ostream& os, std::list const& l) { return os; } + +struct constituent_t { // Constituent type + id_t id; + std::string endpoint; +}; + +typedef std::vector constituency_t; // Constituency type +typedef uint32_t state_t; // State type +typedef std::chrono::duration duration_t; // Duration type + +using query_t = std::shared_ptr; + struct AgentConfiguration { id_t id; float min_ping; @@ -109,20 +121,22 @@ struct AgentConfiguration { s << *this; return s.str(); } + query_t toBuilder () { + query_t ret = std::make_shared(); + 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; -struct constituent_t { // Constituent type - id_t id; - std::string endpoint; -}; - -typedef std::vector constituency_t; // Constituency type -typedef uint32_t state_t; // State type -typedef std::chrono::duration duration_t; // Duration type - -using query_t = std::shared_ptr; - struct vote_ret_t { query_t result; vote_ret_t (query_t res) : result(res) {} diff --git a/arangod/Agency/Agent.h b/arangod/Agency/Agent.h index 5c3649a131..41a0e21b33 100644 --- a/arangod/Agency/Agent.h +++ b/arangod/Agency/Agent.h @@ -129,7 +129,7 @@ public: * @brief 1. Deal with appendEntries to slaves. * 2. Report success of write processes. */ - void run (); + void run () override final; void beginShutdown () override; /** diff --git a/arangod/Agency/ApplicationAgency.cpp b/arangod/Agency/ApplicationAgency.cpp index 367eddf888..95953578a3 100644 --- a/arangod/Agency/ApplicationAgency.cpp +++ b/arangod/Agency/ApplicationAgency.cpp @@ -71,8 +71,7 @@ void ApplicationAgency::setupOptions( bool ApplicationAgency::prepare() { - _disabled = _agency_endpoints.empty() || - _agent_id == std::numeric_limits::max(); + _disabled = (_agent_id == std::numeric_limits::max()); if (_disabled) { return true; diff --git a/arangod/Agency/ApplicationAgency.h b/arangod/Agency/ApplicationAgency.h index 1f158b110d..c2f9462744 100644 --- a/arangod/Agency/ApplicationAgency.h +++ b/arangod/Agency/ApplicationAgency.h @@ -93,12 +93,12 @@ class ApplicationAgency : virtual public arangodb::rest::ApplicationFeature { public: void setupOptions(std::map&); + arangodb::basics::ProgramOptionsDescription>&) override final; - bool prepare(); - bool start(); - bool open(); - void close(); + bool prepare() override final; + bool start() override final; + bool open() override final; + void close() override final; agent_t* agent() const; diff --git a/arangod/Agency/Constituent.cpp b/arangod/Agency/Constituent.cpp index 7a87df3cd7..f44c2248b2 100644 --- a/arangod/Agency/Constituent.cpp +++ b/arangod/Agency/Constituent.cpp @@ -42,8 +42,12 @@ void Constituent::configure(Agent* agent) { _agent = agent; if (size() == 1) { _role = LEADER; - } else { - _votes.resize(size()); + } else { + try { + _votes.resize(size()); + } catch (std::exception const& e) { + LOG(FATAL) << "Cannot resize votes vector to " << size(); + } _id = _agent->config().id; if (_agent->config().notify) {// (notify everyone) notifyAll(); @@ -190,8 +194,12 @@ const constituency_t& Constituent::gossip () { } 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; if(_role == CANDIDATE) _term++; // raise my term diff --git a/arangod/Agency/Constituent.h b/arangod/Agency/Constituent.h index 768cb544db..ac86e697eb 100644 --- a/arangod/Agency/Constituent.h +++ b/arangod/Agency/Constituent.h @@ -84,7 +84,7 @@ public: /** * @brief My daily business */ - void run(); + void run() override final; /** * @brief Who is leading diff --git a/arangod/Agency/Store.h b/arangod/Agency/Store.h index c5192e95f7..3baf9ec1a8 100644 --- a/arangod/Agency/Store.h +++ b/arangod/Agency/Store.h @@ -54,7 +54,7 @@ using namespace arangodb::velocypack; class StoreException : public std::exception { public: 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: std::string _message; }; diff --git a/arangod/RestHandler/RestAgencyHandler.cpp b/arangod/RestHandler/RestAgencyHandler.cpp index 8ae42474f0..358e280add 100644 --- a/arangod/RestHandler/RestAgencyHandler.cpp +++ b/arangod/RestHandler/RestAgencyHandler.cpp @@ -148,7 +148,7 @@ HttpHandler::status_t RestAgencyHandler::handleTest() { body.add("id", Value(_agent->id())); body.add("term", Value(_agent->term())); body.add("leaderId", Value(_agent->leaderID())); - body.add("configuration", Value(_agent->config().toString())); + body.add("configuration", _agent->config().toBuilder()); body.close(); generateResult(body.slice()); return HttpHandler::status_t(HANDLER_DONE); diff --git a/arangod/RestServer/ArangoServer.h b/arangod/RestServer/ArangoServer.h index 0619b6a8fc..4572583f67 100644 --- a/arangod/RestServer/ArangoServer.h +++ b/arangod/RestServer/ArangoServer.h @@ -466,13 +466,6 @@ class ArangoServer { aql::QueryRegistry* _queryRegistry; - ////////////////////////////////////////////////////////////////////////////// - /// @brief the agent - ////////////////////////////////////////////////////////////////////////////// - - consensus::Agent* _agent; - - ////////////////////////////////////////////////////////////////////////////// /// @brief ptr to pair of _applicationV8 and _queryRegistry for _api/aql /// handler diff --git a/js/client/tests/agency/agency-test.js b/js/client/tests/agency/agency-test.js index a562205aa6..cb5ff7059d 100644 --- a/js/client/tests/agency/agency-test.js +++ b/js/client/tests/agency/agency-test.js @@ -66,13 +66,13 @@ function agencyTestSuite () { return res; } - function writeAgencyRaw(list) { +/* function writeAgencyRaw(list) { var res = request({url: agencyServers[whoseTurn] + "/_api/agency/write", method: "POST", followRedirects: true, body: list, headers: {"Content-Type": "application/json"}}); res.bodyParsed = JSON.parse(res.body); return res; - } + }*/ function readAndCheck(list) { var res = readAgency(list); diff --git a/lib/Basics/Exceptions.h b/lib/Basics/Exceptions.h index c8eac8cb3d..6dde6cd0ac 100644 --- a/lib/Basics/Exceptions.h +++ b/lib/Basics/Exceptions.h @@ -96,7 +96,7 @@ class Exception : public virtual std::exception { ~Exception() throw(); public: - char const* what() const throw(); + char const* what() const throw() override; std::string message() const throw(); int code() const throw(); void addToMessage(std::string const&);