1
0
Fork 0

Agency is attached to application. Vote reception runnin.g

This commit is contained in:
Kaveh Vahedipour 2016-01-27 18:35:41 +01:00
parent b89cf5a8e6
commit a8af99aca5
8 changed files with 54 additions and 10 deletions

View File

@ -37,6 +37,10 @@ Constituent::term_t Agent::term () const {
return _constituent.term();
}
bool Agent::vote(Constituent::id_t id, Constituent::term_t term) {
bool res = _constituent.vote(id, term);
}
Slice const& Agent::log (const Slice& slice) {
if (_constituent.leader())
return _log.log(slice);

View File

@ -83,9 +83,11 @@ namespace consensus {
*/
Slice const& log (Slice const&);
Slice const& redirect (Slice const&);
bool vote(Constituent::id_t, Constituent::term_t);
private:
Constituent _constituent; /**< @brief Leader election delegate */
Constituent _constituent; /**< @brief Leader election delegate */
Log _log; /**< @brief Log replica */
};

View File

@ -36,10 +36,12 @@ using namespace arangodb::basics;
using namespace arangodb::rest;
ApplicationAgency::ApplicationAgency()
: ApplicationFeature("agency"), _size(5) {}
: ApplicationFeature("agency"), _size(5), _min_election_timeout(.15),
_max_election_timeout(.3), _agent(new consensus::Agent()) {
}
ApplicationAgency::~ApplicationAgency() { /*delete _dispatcher;*/ }
ApplicationAgency::~ApplicationAgency() {}
////////////////////////////////////////////////////////////////////////////////
@ -49,10 +51,11 @@ ApplicationAgency::~ApplicationAgency() { /*delete _dispatcher;*/ }
void ApplicationAgency::setupOptions(
std::map<std::string, ProgramOptionsDescription>& options) {
options["Agency Options:help-agency"]("agency.size", &_size, "Agency size")
("agency.election-timeout-min", &_size, "Minimum timeout before an agent"
" calls for new election (default: 150ms)")
("agency.election-timeout-max", &_size, "Minimum timeout before an agent"
" calls for new election (default: 300ms)");
("agency.election-timeout-min", &_min_election_timeout, "Minimum "
"timeout before an agent calls for new election [s]")
("agency.election-timeout-max", &_max_election_timeout, "Minimum "
"timeout before an agent calls for new election [s]")
("agency.host", &_agency_endpoints, "Agency endpoints");
}
@ -90,5 +93,9 @@ void ApplicationAgency::stop() {
}
}
arangodb::consensus::Agent* ApplicationAgency::agent () const {
return _agent.get();
}

View File

@ -27,7 +27,7 @@
#include "Basics/Common.h"
#include "ApplicationServer/ApplicationFeature.h"
#include "ApplicationAgency.h"
#include "Agency/Agent.h"
namespace arangodb {
@ -105,10 +105,16 @@ class Task;
void stop();
consensus::Agent* agent() const;
private:
uint64_t _size; /**< @brief: agency size (default: 5)*/
double _min_election_timeout; /**< @brief: min election timeout */
double _max_election_timeout; /**< @brief: max election timeout */
std::vector<std::string> _agency_endpoints;
std::unique_ptr<consensus::Agent> _agent;
};
}

View File

@ -59,6 +59,19 @@ Constituent::mode_t Constituent::mode () const {
return _mode;
}
bool Constituent::vote (id_t id, term_t term) {
if (id == _id)
return false;
else {
if (term > _term) {
_state = FOLLOWER;
return true;
} else {
return false;
}
}
}
void Constituent::gossip (const Constituent::constituency_t& constituency) {
// Talk to all peers i have not talked to
// Answer by sending my complete list of peers

View File

@ -95,6 +95,8 @@ public:
bool leader() const;
bool vote(id_t, term_t);
private:
/**
@ -115,6 +117,7 @@ private:
term_t _term; /**< @brief term number */
id_t _leader_id; /**< @brief Current leader */
id_t _cur_vote; /**< @brief My current vote */
id_t _id;
constituency_t _constituency; /**< @brief List of consituents */
uint32_t _nvotes; /**< @brief Votes in my favour
* (candidate/leader) */

View File

@ -133,7 +133,8 @@ void ArangoServer::defineHandlers(HttpHandlerFactory* factory) {
// add "/agency" handler
factory->addPrefixHandler(RestVocbaseBaseHandler::AGENCY_PATH,
RestHandlerCreator<RestAgencyHandler>::createNoData);
RestHandlerCreator<RestAgencyHandler>::createData<
consensus::Agent*>, _applicationAgency->agent());
// add "/batch" handler
factory->addPrefixHandler(RestVocbaseBaseHandler::BATCH_PATH,
@ -600,7 +601,7 @@ void ArangoServer::buildApplicationServer() {
_applicationServer->addFeature(_applicationCluster);
// .............................................................................
// cluster options
// agency options
// .............................................................................
_applicationAgency =

View File

@ -34,6 +34,7 @@
#include "Rest/AnyServer.h"
#include "Rest/OperationMode.h"
#include "VocBase/vocbase.h"
#include "Agency/Agent.h"
struct TRI_server_t;
struct TRI_vocbase_defaults_t;
@ -373,6 +374,13 @@ class ArangoServer : public rest::AnyServer {
aql::QueryRegistry* _queryRegistry;
//////////////////////////////////////////////////////////////////////////////
/// @brief the agent
//////////////////////////////////////////////////////////////////////////////
consensus::Agent* _agent;
//////////////////////////////////////////////////////////////////////////////
/// @brief ptr to pair of _applicationV8 and _queryRegistry for _api/aql
/// handler