From 80e7828a971bdc0c5a1ad392ea3ec55c664a4f6d Mon Sep 17 00:00:00 2001 From: Kaveh Vahedipour Date: Wed, 23 Mar 2016 19:05:34 +0100 Subject: [PATCH] need to log all changes of term in agency --- arangod/Agency/Constituent.cpp | 23 +++++++++++++++-------- arangod/Agency/Constituent.h | 5 +++++ arangod/Agency/Store.cpp | 2 +- arangod/RestHandler/RestAgencyHandler.cpp | 1 - 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/arangod/Agency/Constituent.cpp b/arangod/Agency/Constituent.cpp index d65fcfcd86..5e45f92442 100644 --- a/arangod/Agency/Constituent.cpp +++ b/arangod/Agency/Constituent.cpp @@ -56,8 +56,8 @@ void Constituent::configure(Agent* agent) { } Constituent::Constituent() : - Thread("Constituent"), _term(0), _id(0), _gen(std::random_device()()), - _role(FOLLOWER), _leader_id(0), _agent(0) {} + Thread("Constituent"), _term(0), _leader_id(0), _id(0), _gen(std::random_device()()), + _role(FOLLOWER), _agent(0) {} Constituent::~Constituent() { shutdown(); @@ -77,22 +77,29 @@ term_t Constituent::term() const { return _term; } +void Constituent::term(term_t t) { + if (t != _term) { + LOG(INFO) << "Updating term to " << t; + } + _term = t; +} + role_t Constituent::role () const { return _role; } -void Constituent::follow (term_t term) { +void Constituent::follow (term_t t) { if (_role != FOLLOWER) { - LOG(WARN) << "Role change: Converted to follower in term " << _term ; + LOG(INFO) << "Role change: Converted to follower in term " << t; } - _term = term; + this->term(t); _votes.assign(_votes.size(),false); // void all votes _role = FOLLOWER; } void Constituent::lead () { if (_role != LEADER) { - LOG(WARN) << "Role change: Converted to leader in term " << _term ; + LOG(INFO) << "Role change: Converted to leader in term " << _term ; _agent->lead(); // We need to rebuild spear_head and read_db; } _role = LEADER; @@ -101,7 +108,7 @@ void Constituent::lead () { void Constituent::candidate () { if (_role != CANDIDATE) - LOG(WARN) << "Role change: Converted to candidate in term " << _term ; + LOG(INFO) << "Role change: Converted to candidate in term " << _term ; _role = CANDIDATE; } @@ -171,7 +178,7 @@ bool Constituent::vote ( return false; // TODO: Assertion? } else { if (term > _term || (_term==term&&_leader_id==leaderId)) { - _term = term; + this->term(term); _cast = true; // Note that I voted this time around. _leader_id = leaderId; // The guy I voted for I assume leader. if (_role>FOLLOWER) diff --git a/arangod/Agency/Constituent.h b/arangod/Agency/Constituent.h index ac86e697eb..a07477c905 100644 --- a/arangod/Agency/Constituent.h +++ b/arangod/Agency/Constituent.h @@ -104,6 +104,9 @@ public: void beginShutdown () override; private: + + /// @brief set term to new term + void term (term_t); std::vector const& end_points() const; std::string const& end_point(id_t) const; @@ -141,6 +144,8 @@ private: duration_t sleepFor(double, double); double sleepFord(double, double); + + // mission critical term_t _term; /**< @brief term number */ std::atomic _cast; /**< @brief cast a vote this term */ diff --git a/arangod/Agency/Store.cpp b/arangod/Agency/Store.cpp index e766062e2b..8cbc55f945 100644 --- a/arangod/Agency/Store.cpp +++ b/arangod/Agency/Store.cpp @@ -174,7 +174,7 @@ std::ostream& operator<< (std::ostream& o, std::map const& d) { } Node& Node::root() { - Node *par = _parent, *tmp; + Node *par = _parent, *tmp = 0; while (par != 0) { tmp = par; par = par->_parent; diff --git a/arangod/RestHandler/RestAgencyHandler.cpp b/arangod/RestHandler/RestAgencyHandler.cpp index e4e67d8ddf..97a4789cfb 100644 --- a/arangod/RestHandler/RestAgencyHandler.cpp +++ b/arangod/RestHandler/RestAgencyHandler.cpp @@ -145,7 +145,6 @@ inline HttpHandler::status_t RestAgencyHandler::handleRead () { HttpHandler::status_t RestAgencyHandler::handleTest() { Builder body; body.add(VPackValue(VPackValueType::Object)); - body.add("id", Value(_agent->id())); body.add("term", Value(_agent->term())); body.add("leaderId", Value(_agent->leaderID())); body.add("configuration", _agent->config().toBuilder()->slice());