mirror of https://gitee.com/bigwinds/arangodb
Agency is attached to application. Vote reception runnin.g
This commit is contained in:
parent
b89cf5a8e6
commit
a8af99aca5
|
@ -37,6 +37,10 @@ Constituent::term_t Agent::term () const {
|
||||||
return _constituent.term();
|
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) {
|
Slice const& Agent::log (const Slice& slice) {
|
||||||
if (_constituent.leader())
|
if (_constituent.leader())
|
||||||
return _log.log(slice);
|
return _log.log(slice);
|
||||||
|
|
|
@ -84,8 +84,10 @@ namespace consensus {
|
||||||
Slice const& log (Slice const&);
|
Slice const& log (Slice const&);
|
||||||
Slice const& redirect (Slice const&);
|
Slice const& redirect (Slice const&);
|
||||||
|
|
||||||
|
bool vote(Constituent::id_t, Constituent::term_t);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Constituent _constituent; /**< @brief Leader election delegate */
|
Constituent _constituent; /**< @brief Leader election delegate */
|
||||||
Log _log; /**< @brief Log replica */
|
Log _log; /**< @brief Log replica */
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -36,10 +36,12 @@ using namespace arangodb::basics;
|
||||||
using namespace arangodb::rest;
|
using namespace arangodb::rest;
|
||||||
|
|
||||||
ApplicationAgency::ApplicationAgency()
|
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(
|
void ApplicationAgency::setupOptions(
|
||||||
std::map<std::string, ProgramOptionsDescription>& options) {
|
std::map<std::string, ProgramOptionsDescription>& options) {
|
||||||
options["Agency Options:help-agency"]("agency.size", &_size, "Agency size")
|
options["Agency Options:help-agency"]("agency.size", &_size, "Agency size")
|
||||||
("agency.election-timeout-min", &_size, "Minimum timeout before an agent"
|
("agency.election-timeout-min", &_min_election_timeout, "Minimum "
|
||||||
" calls for new election (default: 150ms)")
|
"timeout before an agent calls for new election [s]")
|
||||||
("agency.election-timeout-max", &_size, "Minimum timeout before an agent"
|
("agency.election-timeout-max", &_max_election_timeout, "Minimum "
|
||||||
" calls for new election (default: 300ms)");
|
"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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
#include "Basics/Common.h"
|
#include "Basics/Common.h"
|
||||||
|
|
||||||
#include "ApplicationServer/ApplicationFeature.h"
|
#include "ApplicationServer/ApplicationFeature.h"
|
||||||
#include "ApplicationAgency.h"
|
#include "Agency/Agent.h"
|
||||||
|
|
||||||
|
|
||||||
namespace arangodb {
|
namespace arangodb {
|
||||||
|
@ -105,10 +105,16 @@ class Task;
|
||||||
|
|
||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
|
consensus::Agent* agent() const;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
uint64_t _size; /**< @brief: agency size (default: 5)*/
|
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;
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,6 +59,19 @@ Constituent::mode_t Constituent::mode () const {
|
||||||
return _mode;
|
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) {
|
void Constituent::gossip (const Constituent::constituency_t& constituency) {
|
||||||
// Talk to all peers i have not talked to
|
// Talk to all peers i have not talked to
|
||||||
// Answer by sending my complete list of peers
|
// Answer by sending my complete list of peers
|
||||||
|
|
|
@ -95,6 +95,8 @@ public:
|
||||||
|
|
||||||
bool leader() const;
|
bool leader() const;
|
||||||
|
|
||||||
|
bool vote(id_t, term_t);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -115,6 +117,7 @@ private:
|
||||||
term_t _term; /**< @brief term number */
|
term_t _term; /**< @brief term number */
|
||||||
id_t _leader_id; /**< @brief Current leader */
|
id_t _leader_id; /**< @brief Current leader */
|
||||||
id_t _cur_vote; /**< @brief My current vote */
|
id_t _cur_vote; /**< @brief My current vote */
|
||||||
|
id_t _id;
|
||||||
constituency_t _constituency; /**< @brief List of consituents */
|
constituency_t _constituency; /**< @brief List of consituents */
|
||||||
uint32_t _nvotes; /**< @brief Votes in my favour
|
uint32_t _nvotes; /**< @brief Votes in my favour
|
||||||
* (candidate/leader) */
|
* (candidate/leader) */
|
||||||
|
|
|
@ -133,7 +133,8 @@ void ArangoServer::defineHandlers(HttpHandlerFactory* factory) {
|
||||||
|
|
||||||
// add "/agency" handler
|
// add "/agency" handler
|
||||||
factory->addPrefixHandler(RestVocbaseBaseHandler::AGENCY_PATH,
|
factory->addPrefixHandler(RestVocbaseBaseHandler::AGENCY_PATH,
|
||||||
RestHandlerCreator<RestAgencyHandler>::createNoData);
|
RestHandlerCreator<RestAgencyHandler>::createData<
|
||||||
|
consensus::Agent*>, _applicationAgency->agent());
|
||||||
|
|
||||||
// add "/batch" handler
|
// add "/batch" handler
|
||||||
factory->addPrefixHandler(RestVocbaseBaseHandler::BATCH_PATH,
|
factory->addPrefixHandler(RestVocbaseBaseHandler::BATCH_PATH,
|
||||||
|
@ -600,7 +601,7 @@ void ArangoServer::buildApplicationServer() {
|
||||||
_applicationServer->addFeature(_applicationCluster);
|
_applicationServer->addFeature(_applicationCluster);
|
||||||
|
|
||||||
// .............................................................................
|
// .............................................................................
|
||||||
// cluster options
|
// agency options
|
||||||
// .............................................................................
|
// .............................................................................
|
||||||
|
|
||||||
_applicationAgency =
|
_applicationAgency =
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
#include "Rest/AnyServer.h"
|
#include "Rest/AnyServer.h"
|
||||||
#include "Rest/OperationMode.h"
|
#include "Rest/OperationMode.h"
|
||||||
#include "VocBase/vocbase.h"
|
#include "VocBase/vocbase.h"
|
||||||
|
#include "Agency/Agent.h"
|
||||||
|
|
||||||
struct TRI_server_t;
|
struct TRI_server_t;
|
||||||
struct TRI_vocbase_defaults_t;
|
struct TRI_vocbase_defaults_t;
|
||||||
|
@ -373,6 +374,13 @@ class ArangoServer : public rest::AnyServer {
|
||||||
|
|
||||||
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
|
||||||
|
|
Loading…
Reference in New Issue