1
0
Fork 0

Merge branch 'devel' of https://github.com/arangodb/arangodb into devel

This commit is contained in:
jsteemann 2016-04-25 22:31:58 +02:00
commit fdd3d0d516
11 changed files with 42 additions and 42 deletions

View File

@ -52,7 +52,7 @@ Agent::Agent (config_t const& config)
}
// This agent's id
id_t Agent::id() const {
arangodb::consensus::id_t Agent::id() const {
return _config.id;
}
@ -84,7 +84,7 @@ inline size_t Agent::size() const {
}
// Handle vote request
priv_rpc_ret_t Agent::requestVote(term_t t, id_t id, index_t lastLogIndex,
priv_rpc_ret_t Agent::requestVote(term_t t, arangodb::consensus::id_t id, index_t lastLogIndex,
index_t lastLogTerm, query_t const& query) {
/// Are we receiving new endpoints
@ -110,7 +110,7 @@ config_t const& Agent::config () const {
}
// Leader's id
id_t Agent::leaderID () const {
arangodb::consensus::id_t Agent::leaderID () const {
return _constituent.leaderID();
}
@ -120,7 +120,7 @@ bool Agent::leading() const {
}
// Persist term and id we vote for
void Agent::persist(term_t t, id_t i) {
void Agent::persist(term_t t, arangodb::consensus::id_t i) {
// _state.persist(t, i);
}
@ -156,7 +156,7 @@ bool Agent::waitFor (index_t index, double timeout) {
}
// AgentCallback reports id of follower and its highest processed index
void Agent::reportIn (id_t id, index_t index) {
void Agent::reportIn (arangodb::consensus::id_t id, index_t index) {
MUTEX_LOCKER(mutexLocker, _ioLock);
if (index > _confirmed[id]) // progress this follower?
@ -181,7 +181,7 @@ void Agent::reportIn (id_t id, index_t index) {
}
// Followers' append entries
bool Agent::recvAppendEntriesRPC (term_t term, id_t leaderId, index_t prevIndex,
bool Agent::recvAppendEntriesRPC (term_t term, arangodb::consensus::id_t leaderId, index_t prevIndex,
term_t prevTerm, index_t leaderCommitIndex, query_t const& queries) {
//Update commit index
@ -233,7 +233,7 @@ bool Agent::recvAppendEntriesRPC (term_t term, id_t leaderId, index_t prevIndex,
}
// Leader's append entries
append_entries_t Agent::sendAppendEntriesRPC (id_t follower_id) {
append_entries_t Agent::sendAppendEntriesRPC (arangodb::consensus::id_t follower_id) {
index_t last_confirmed = _confirmed[follower_id];
std::vector<log_t> unconfirmed = _state.get(last_confirmed);
@ -374,7 +374,7 @@ void Agent::run() {
_appendCV.wait(); // Just sit there doing nothing
// Collect all unacknowledged
for (id_t i = 0; i < size(); ++i) {
for (arangodb::consensus::id_t i = 0; i < size(); ++i) {
if (i != id()) {
sendAppendEntriesRPC(i);
}

View File

@ -50,10 +50,10 @@ public:
term_t term() const;
/// @brief Get current term
id_t id() const;
arangodb::consensus::id_t id() const;
/// @brief Vote request
priv_rpc_ret_t requestVote(term_t, id_t, index_t, index_t, query_t const&);
priv_rpc_ret_t requestVote(term_t, arangodb::consensus::id_t, index_t, index_t, query_t const&);
/// @brief Provide configuration
config_t const& config() const;
@ -69,7 +69,7 @@ public:
bool fitness() const;
/// @brief Leader ID
id_t leaderID() const;
arangodb::consensus::id_t leaderID() const;
/// @brief Are we leading?
bool leading() const;
@ -88,13 +88,13 @@ public:
/// @brief Received by followers to replicate log entries ($5.3);
/// also used as heartbeat ($5.2).
bool recvAppendEntriesRPC(term_t term, id_t leaderId, index_t prevIndex,
bool recvAppendEntriesRPC(term_t term, arangodb::consensus::id_t leaderId, index_t prevIndex,
term_t prevTerm, index_t lastCommitIndex,
query_t const& queries);
/// @brief Invoked by leader to replicate log entries ($5.3);
/// also used as heartbeat ($5.2).
append_entries_t sendAppendEntriesRPC(id_t slave_id);
append_entries_t sendAppendEntriesRPC(arangodb::consensus::id_t slave_id);
/// @brief 1. Deal with appendEntries to slaves.
/// 2. Report success of write processes.
@ -104,7 +104,7 @@ public:
void beginShutdown() override final;
/// @brief Report appended entries from AgentCallback
void reportIn(id_t id, index_t idx);
void reportIn(arangodb::consensus::id_t id, index_t idx);
/// @brief Wait for slaves to confirm appended entries
bool waitFor(index_t last_entry, double timeout = 2.0);
@ -119,7 +119,7 @@ public:
log_t const& lastLog() const;
/// @brief Persist term
void persist (term_t, id_t);
void persist (term_t, arangodb::consensus::id_t);
/// @brief State machine
State const& state() const;

View File

@ -30,7 +30,7 @@ using namespace arangodb::velocypack;
AgentCallback::AgentCallback() : _agent(0), _last(0), _slaveID(0) {}
AgentCallback::AgentCallback(Agent* agent, id_t slaveID, index_t last) :
AgentCallback::AgentCallback(Agent* agent, arangodb::consensus::id_t slaveID, index_t last) :
_agent(agent), _last(last), _slaveID(slaveID) {}
void AgentCallback::shutdown() {

View File

@ -38,7 +38,7 @@ public:
AgentCallback();
AgentCallback(Agent*, id_t, index_t);
AgentCallback(Agent*, arangodb::consensus::id_t, index_t);
virtual bool operator()(arangodb::ClusterCommResult*) override final;
@ -47,7 +47,7 @@ public:
private:
Agent* _agent;
index_t _last;
id_t _slaveID;
arangodb::consensus::id_t _slaveID;
};

View File

@ -29,7 +29,7 @@ namespace consensus {
struct config_t {
id_t id;
arangodb::consensus::id_t id;
double minPing;
double maxPing;
std::string endpoint;

View File

@ -211,13 +211,13 @@ bool Constituent::running() const {
}
/// @brief Get current leader's id
id_t Constituent::leaderID() const { return _leaderID; }
arangodb::consensus::id_t Constituent::leaderID() const { return _leaderID; }
/// @brief Agency size
size_t Constituent::size() const { return config().size(); }
/// @brief Get endpoint to an id
std::string const& Constituent::endpoint(id_t id) const {
std::string const& Constituent::endpoint(arangodb::consensus::id_t id) const {
return config().endpoints[id];
}
@ -230,7 +230,7 @@ std::vector<std::string> const& Constituent::endpoints() const {
void Constituent::notifyAll () {
std::vector<std::string> toNotify;
// Send request to all but myself
for (id_t i = 0; i < size(); ++i) {
for (arangodb::consensus::id_t i = 0; i < size(); ++i) {
if (i != _id) {
toNotify.push_back(endpoint(i));
}
@ -256,10 +256,10 @@ void Constituent::notifyAll () {
}
/// @brief Vote
bool Constituent::vote(term_t term, id_t id, index_t prevLogIndex,
bool Constituent::vote(term_t term, arangodb::consensus::id_t id, index_t prevLogIndex,
term_t prevLogTerm) {
term_t t = 0;
id_t lid = 0;
arangodb::consensus::id_t lid = 0;
{
MUTEX_LOCKER(guard, _castLock);
t = _term;
@ -303,7 +303,7 @@ void Constituent::callElection() {
<< "&prevLogTerm=" << _agent->lastLog().term;
// Ask everyone for their vote
for (id_t i = 0; i < config().endpoints.size(); ++i) {
for (arangodb::consensus::id_t i = 0; i < config().endpoints.size(); ++i) {
if (i != _id && endpoint(i) != "") {
std::unique_ptr<std::map<std::string, std::string>> headerFields =
std::make_unique<std::map<std::string, std::string>>();
@ -319,7 +319,7 @@ void Constituent::callElection() {
sleepFor(.5 * config().minPing, .8 * config().minPing));
// Collect votes
for (id_t i = 0; i < config().endpoints.size(); ++i) {
for (arangodb::consensus::id_t i = 0; i < config().endpoints.size(); ++i) {
if (i != _id && endpoint(i) != "") {
ClusterCommResult res =
arangodb::ClusterComm::instance()->enquire(results[i].operationID);

View File

@ -78,13 +78,13 @@ public:
bool running() const;
/// @brief Called by REST handler
bool vote(term_t, id_t, index_t, term_t);
bool vote(term_t, arangodb::consensus::id_t, index_t, term_t);
/// @brief My daily business
void run() override final;
/// @brief Who is leading
id_t leaderID () const;
arangodb::consensus::id_t leaderID () const;
/// @brief Configuration
config_t const& config () const;
@ -109,7 +109,7 @@ private:
std::vector<std::string> const& endpoints() const;
/// @brief Endpoint of agent with id
std::string const& endpoint(id_t) const;
std::string const& endpoint(arangodb::consensus::id_t) const;
/// @brief Run for leadership
void candidate();
@ -141,13 +141,13 @@ private:
std::atomic<bool> _cast; /**< @brief cast a vote this term */
std::atomic<state_t> _state; /**< @brief State (follower, candidate, leader)*/
id_t _leaderID; /**< @brief Current leader */
id_t _id; /**< @brief My own id */
arangodb::consensus::id_t _leaderID; /**< @brief Current leader */
arangodb::consensus::id_t _id; /**< @brief My own id */
constituency_t _constituency; /**< @brief List of consituents */
std::mt19937 _gen; /**< @brief Random number generator */
role_t _role; /**< @brief My role */
Agent* _agent; /**< @brief My boss */
id_t _votedFor;
arangodb::consensus::id_t _votedFor;
std::unique_ptr<NotifierThread> _notifier;

View File

@ -68,7 +68,7 @@ inline HttpHandler::status_t RestAgencyHandler::reportUnknownMethod() {
return HttpHandler::status_t(HANDLER_DONE);
}
void RestAgencyHandler::redirectRequest(id_t leaderId) {
void RestAgencyHandler::redirectRequest(arangodb::consensus::id_t leaderId) {
try {
std::string url = Endpoint::uriForm(

View File

@ -82,7 +82,7 @@ HttpHandler::status_t RestAgencyPrivHandler::execute() {
return reportTooManySuffices();
} else {
term_t term, prevLogTerm;
id_t id; // leaderId for appendEntries, cadidateId for requestVote
arangodb::consensus::id_t id; // leaderId for appendEntries, cadidateId for requestVote
index_t prevLogIndex, leaderCommit;
if (_request->suffix()[0] == "appendEntries") { // appendEntries
if (_request->requestType() != GeneralRequest::RequestType::POST) {

View File

@ -57,13 +57,13 @@ State::State(std::string const& endpoint)
VPackSlice value = arangodb::basics::VelocyPackHelper::EmptyObjectValue();
buf->append(value.startAs<char const>(), value.byteSize());
if (!_log.size()) {
_log.push_back(log_t(index_t(0), term_t(0), id_t(0), buf));
_log.push_back(log_t(index_t(0), term_t(0), arangodb::consensus::id_t(0), buf));
}
}
State::~State() {}
bool State::persist(index_t index, term_t term, id_t lid,
bool State::persist(index_t index, term_t term, arangodb::consensus::id_t lid,
arangodb::velocypack::Slice const& entry) {
Builder body;
body.add(VPackValue(VPackValueType::Object));
@ -95,7 +95,7 @@ bool State::persist(index_t index, term_t term, id_t lid,
//Leader
std::vector<index_t> State::log (
query_t const& query, std::vector<bool> const& appl, term_t term, id_t lid) {
query_t const& query, std::vector<bool> const& appl, term_t term, arangodb::consensus::id_t lid) {
std::vector<index_t> idx(appl.size());
std::vector<bool> good = appl;
@ -117,7 +117,7 @@ std::vector<index_t> State::log (
}
// Follower
bool State::log(query_t const& queries, term_t term, id_t lid,
bool State::log(query_t const& queries, term_t term, arangodb::consensus::id_t lid,
index_t prevLogIndex, term_t prevLogTerm) { // TODO: Throw exc
if (queries->slice().type() != VPackValueType::Array) {
return false;
@ -257,7 +257,7 @@ bool State::loadCollection(std::string const& name) {
_log.push_back(
log_t(std::stoi(i.get(TRI_VOC_ATTRIBUTE_KEY).copyString()),
static_cast<term_t>(i.get("term").getUInt()),
static_cast<id_t>(i.get("leader").getUInt()), tmp));
static_cast<arangodb::consensus::id_t>(i.get("leader").getUInt()), tmp));
}
}

View File

@ -62,11 +62,11 @@ public:
/// @brief Log entries (leader)
std::vector<index_t> log (query_t const& query, std::vector<bool> const& indices, term_t term, id_t lid);
std::vector<index_t> log (query_t const& query, std::vector<bool> const& indices, term_t term, arangodb::consensus::id_t lid);
/// @brief Log entries (followers)
bool log (query_t const& queries, term_t term, id_t leaderId, index_t prevLogIndex, term_t prevLogTerm);
bool log (query_t const& queries, term_t term, arangodb::consensus::id_t leaderId, index_t prevLogIndex, term_t prevLogTerm);
/// @brief Find entry at index with term
@ -114,7 +114,7 @@ private:
bool snapshot ();
/// @brief Save currentTerm, votedFor, log entries
bool persist (index_t index, term_t term, id_t lid,
bool persist (index_t index, term_t term, arangodb::consensus::id_t lid,
arangodb::velocypack::Slice const& entry);
/// @brief Load collection from persistent store