1
0
Fork 0

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

This commit is contained in:
Jan Steemann 2016-03-23 18:14:12 +01:00
commit 6abcc57459
34 changed files with 146 additions and 135 deletions

View File

@ -410,6 +410,7 @@ else ()
CFLAGS=${V8_CFLAGS} CFLAGS=${V8_CFLAGS}
CXXFLAGS=${V8_CXXFLAGS} CXXFLAGS=${V8_CXXFLAGS}
LDFLAGS=${V8_LDFLAGS} LDFLAGS=${V8_LDFLAGS}
PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}
) )
list(APPEND V8_COMPILE_ARGS icui18n icuuc icudata) list(APPEND V8_COMPILE_ARGS icui18n icuuc icudata)

View File

@ -66,7 +66,7 @@
}, },
'host_arch%': '<(host_arch)', 'host_arch%': '<(host_arch)',
'target_arch%': '<(host_arch)', 'target_arch%': '<(host_arch)',
'base_dir%': '<!(cd <(DEPTH) && python -c "import os; print os.getcwd()")', 'base_dir%': '<!(cd <(DEPTH) && ${PYTHON_EXECUTABLE} -c "import os; print os.getcwd()")',
# Instrument for code coverage with gcov. # Instrument for code coverage with gcov.
'coverage%': 0, 'coverage%': 0,
@ -421,7 +421,7 @@
# (defines are passed via the command line, and build systems rebuild # (defines are passed via the command line, and build systems rebuild
# things when their commandline changes). Nothing should ever read this # things when their commandline changes). Nothing should ever read this
# define. # define.
'defines': ['CR_CLANG_REVISION=<!(python <(DEPTH)/tools/clang/scripts/update.py --print-revision)'], 'defines': ['CR_CLANG_REVISION=<!(${PYTHON_EXECUTABLE} <(DEPTH)/tools/clang/scripts/update.py --print-revision)'],
'conditions': [ 'conditions': [
['host_clang==1', { ['host_clang==1', {
'target_conditions': [ 'target_conditions': [

View File

@ -38,7 +38,7 @@
'ubsan%': 0, 'ubsan%': 0,
'ubsan_vptr%': 0, 'ubsan_vptr%': 0,
'v8_target_arch%': '<(target_arch)', 'v8_target_arch%': '<(target_arch)',
'v8_host_byteorder%': '<!(python -c "import sys; print sys.byteorder")', 'v8_host_byteorder%': '<!(${PYTHON_EXECUTABLE} -c "import sys; print sys.byteorder")',
# Native Client builds currently use the V8 ARM JIT and # Native Client builds currently use the V8 ARM JIT and
# arm/simulator-arm.cc to defer the significant effort required # arm/simulator-arm.cc to defer the significant effort required
# for NaCl JIT support. The nacl_target_arch variable provides # for NaCl JIT support. The nacl_target_arch variable provides

View File

@ -1839,14 +1839,14 @@
'<(PRODUCT_DIR)/natives_blob_host.bin', '<(PRODUCT_DIR)/natives_blob_host.bin',
], ],
'action': [ 'action': [
'python', '<@(_inputs)', '<(PRODUCT_DIR)/natives_blob_host.bin' '$(PYTHON_EXECUTABLE)', '<@(_inputs)', '<(PRODUCT_DIR)/natives_blob_host.bin'
], ],
}, { }, {
'outputs': [ 'outputs': [
'<(PRODUCT_DIR)/natives_blob.bin', '<(PRODUCT_DIR)/natives_blob.bin',
], ],
'action': [ 'action': [
'python', '<@(_inputs)', '<(PRODUCT_DIR)/natives_blob.bin' '$(PYTHON_EXECUTABLE)', '<@(_inputs)', '<(PRODUCT_DIR)/natives_blob.bin'
], ],
}], }],
], ],
@ -1855,7 +1855,7 @@
'<(PRODUCT_DIR)/natives_blob.bin', '<(PRODUCT_DIR)/natives_blob.bin',
], ],
'action': [ 'action': [
'python', '<@(_inputs)', '<(PRODUCT_DIR)/natives_blob.bin' '$(PYTHON_EXECUTABLE)', '<@(_inputs)', '<(PRODUCT_DIR)/natives_blob.bin'
], ],
}], }],
], ],
@ -1952,7 +1952,7 @@
], ],
'outputs': ['<(SHARED_INTERMEDIATE_DIR)/libraries.cc'], 'outputs': ['<(SHARED_INTERMEDIATE_DIR)/libraries.cc'],
'action': [ 'action': [
'python', '$(PYTHON_EXECUTABLE)',
'../../tools/js2c.py', '../../tools/js2c.py',
'<(SHARED_INTERMEDIATE_DIR)/libraries.cc', '<(SHARED_INTERMEDIATE_DIR)/libraries.cc',
'CORE', 'CORE',
@ -1969,7 +1969,7 @@
], ],
'outputs': ['<@(libraries_bin_file)'], 'outputs': ['<@(libraries_bin_file)'],
'action': [ 'action': [
'python', '$(PYTHON_EXECUTABLE)',
'../../tools/js2c.py', '../../tools/js2c.py',
'<(SHARED_INTERMEDIATE_DIR)/libraries.cc', '<(SHARED_INTERMEDIATE_DIR)/libraries.cc',
'CORE', 'CORE',
@ -1987,7 +1987,7 @@
], ],
'outputs': ['<(SHARED_INTERMEDIATE_DIR)/experimental-libraries.cc'], 'outputs': ['<(SHARED_INTERMEDIATE_DIR)/experimental-libraries.cc'],
'action': [ 'action': [
'python', '$(PYTHON_EXECUTABLE)',
'../../tools/js2c.py', '../../tools/js2c.py',
'<(SHARED_INTERMEDIATE_DIR)/experimental-libraries.cc', '<(SHARED_INTERMEDIATE_DIR)/experimental-libraries.cc',
'EXPERIMENTAL', 'EXPERIMENTAL',
@ -2002,7 +2002,7 @@
], ],
'outputs': ['<@(libraries_experimental_bin_file)'], 'outputs': ['<@(libraries_experimental_bin_file)'],
'action': [ 'action': [
'python', '$(PYTHON_EXECUTABLE)',
'../../tools/js2c.py', '../../tools/js2c.py',
'<(SHARED_INTERMEDIATE_DIR)/experimental-libraries.cc', '<(SHARED_INTERMEDIATE_DIR)/experimental-libraries.cc',
'EXPERIMENTAL', 'EXPERIMENTAL',
@ -2019,7 +2019,7 @@
], ],
'outputs': ['<(SHARED_INTERMEDIATE_DIR)/extras-libraries.cc'], 'outputs': ['<(SHARED_INTERMEDIATE_DIR)/extras-libraries.cc'],
'action': [ 'action': [
'python', '$(PYTHON_EXECUTABLE)',
'../../tools/js2c.py', '../../tools/js2c.py',
'<(SHARED_INTERMEDIATE_DIR)/extras-libraries.cc', '<(SHARED_INTERMEDIATE_DIR)/extras-libraries.cc',
'EXTRAS', 'EXTRAS',
@ -2034,7 +2034,7 @@
], ],
'outputs': ['<@(libraries_extras_bin_file)'], 'outputs': ['<@(libraries_extras_bin_file)'],
'action': [ 'action': [
'python', '$(PYTHON_EXECUTABLE)',
'../../tools/js2c.py', '../../tools/js2c.py',
'<(SHARED_INTERMEDIATE_DIR)/extras-libraries.cc', '<(SHARED_INTERMEDIATE_DIR)/extras-libraries.cc',
'EXTRAS', 'EXTRAS',
@ -2053,7 +2053,7 @@
'<(SHARED_INTERMEDIATE_DIR)/experimental-extras-libraries.cc', '<(SHARED_INTERMEDIATE_DIR)/experimental-extras-libraries.cc',
], ],
'action': [ 'action': [
'python', '$(PYTHON_EXECUTABLE)',
'../../tools/js2c.py', '../../tools/js2c.py',
'<(SHARED_INTERMEDIATE_DIR)/experimental-extras-libraries.cc', '<(SHARED_INTERMEDIATE_DIR)/experimental-extras-libraries.cc',
'EXPERIMENTAL_EXTRAS', 'EXPERIMENTAL_EXTRAS',
@ -2068,7 +2068,7 @@
], ],
'outputs': ['<@(libraries_experimental_extras_bin_file)'], 'outputs': ['<@(libraries_experimental_extras_bin_file)'],
'action': [ 'action': [
'python', '$(PYTHON_EXECUTABLE)',
'../../tools/js2c.py', '../../tools/js2c.py',
'<(SHARED_INTERMEDIATE_DIR)/experimental-extras-libraries.cc', '<(SHARED_INTERMEDIATE_DIR)/experimental-extras-libraries.cc',
'EXPERIMENTAL_EXTRAS', 'EXPERIMENTAL_EXTRAS',
@ -2099,7 +2099,7 @@
'<(SHARED_INTERMEDIATE_DIR)/debug-support.cc', '<(SHARED_INTERMEDIATE_DIR)/debug-support.cc',
], ],
'action': [ 'action': [
'python', '$(PYTHON_EXECUTABLE)',
'../../tools/gen-postmortem-metadata.py', '../../tools/gen-postmortem-metadata.py',
'<@(_outputs)', '<@(_outputs)',
'<@(heapobject_files)' '<@(heapobject_files)'

View File

@ -1 +0,0 @@
/usr/bin/vim

View File

@ -251,7 +251,7 @@ static void copyString32to8(char* dst, size_t dstLen, const char32_t* src) {
} }
static void copyString32(char32_t* dst, const char32_t* src, size_t len) { static void copyString32(char32_t* dst, const char32_t* src, size_t len) {
while (*src && 1 < len) { while (0 < len && *src) {
*dst++ = *src++; *dst++ = *src++;
--len; --len;
} }
@ -1963,7 +1963,7 @@ int InputBuffer::completeLine(PromptBase& pi) {
int tailIndex = startIndex + longestCommonPrefix; int tailIndex = startIndex + longestCommonPrefix;
memcpy(&displayText[tailIndex], &buf32[pos], memcpy(&displayText[tailIndex], &buf32[pos],
sizeof(char32_t) * (displayLength - tailIndex + 1)); sizeof(char32_t) * (displayLength - tailIndex + 1));
copyString32(buf32, displayText.get(), buflen + 1); copyString32(buf32, displayText.get(), displayLength);
pos = startIndex + longestCommonPrefix; pos = startIndex + longestCommonPrefix;
len = displayLength; len = displayLength;
refreshLine(pi); refreshLine(pi);
@ -2303,7 +2303,7 @@ int InputBuffer::incrementalHistorySearch(PromptBase& pi, int startChar) {
--dp.searchTextLen; --dp.searchTextLen;
dp.searchText[dp.searchTextLen] = 0; dp.searchText[dp.searchTextLen] = 0;
copyString32(tempUnicode.get(), dp.searchText.get(), copyString32(tempUnicode.get(), dp.searchText.get(),
dp.searchTextLen + 1); dp.searchTextLen);
dp.updateSearchText(tempUnicode.get()); dp.updateSearchText(tempUnicode.get());
} else { } else {
beep(); beep();
@ -2318,7 +2318,7 @@ int InputBuffer::incrementalHistorySearch(PromptBase& pi, int startChar) {
unique_ptr<char32_t[]> tempUnicode( unique_ptr<char32_t[]> tempUnicode(
new char32_t[dp.searchTextLen + 2]); new char32_t[dp.searchTextLen + 2]);
copyString32(tempUnicode.get(), dp.searchText.get(), copyString32(tempUnicode.get(), dp.searchText.get(),
dp.searchTextLen + 2); dp.searchTextLen);
tempUnicode[dp.searchTextLen] = c; tempUnicode[dp.searchTextLen] = c;
tempUnicode[dp.searchTextLen + 1] = 0; tempUnicode[dp.searchTextLen + 1] = 0;
dp.updateSearchText(tempUnicode.get()); dp.updateSearchText(tempUnicode.get());
@ -2395,7 +2395,7 @@ int InputBuffer::incrementalHistorySearch(PromptBase& pi, int startChar) {
Utf32String tempUnicode(pb.promptBytes + 1); Utf32String tempUnicode(pb.promptBytes + 1);
copyString32(tempUnicode.get(), &pi.promptText[pi.promptLastLinePosition], copyString32(tempUnicode.get(), &pi.promptText[pi.promptLastLinePosition],
pb.promptBytes + 1); pb.promptBytes - pi.promptLastLinePosition);
tempUnicode.initFromBuffer(); tempUnicode.initFromBuffer();
pb.promptText = tempUnicode; pb.promptText = tempUnicode;
pb.promptExtraLines = 0; pb.promptExtraLines = 0;

View File

@ -83,7 +83,7 @@ struct Exception : std::exception {
explicit Exception(ExceptionType type) : Exception(type, message(type)) {} explicit Exception(ExceptionType type) : Exception(type, message(type)) {}
char const* what() const throw() { return _msg.c_str(); } char const* what() const throw() override final { return _msg.c_str(); }
ExceptionType errorCode() const throw() { return _type; } ExceptionType errorCode() const throw() { return _type; }

View File

@ -213,8 +213,6 @@ unsigned int const Slice::FirstSubMap[32] = {
8, // 0x12, object with unsorted index table 8, // 0x12, object with unsorted index table
0}; 0};
static char const* NullStr = "0x18";
// creates a Slice from Json and adds it to a scope // creates a Slice from Json and adds it to a scope
Slice Slice::fromJson(SliceScope& scope, std::string const& json, Slice Slice::fromJson(SliceScope& scope, std::string const& json,
Options const* options) { Options const* options) {

View File

@ -11,7 +11,7 @@ if (POLICY CMP0037)
endif () endif ()
option(VERBOSE OFF) 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) project(ArangoDB)
@ -175,11 +175,11 @@ if (WINDOWS)
set(BASE_C_FLAGS "" CACHE STRING "base C flags") set(BASE_C_FLAGS "" CACHE STRING "base C flags")
set(BASE_CXX_FLAGS "/GR /EHsc" CACHE STRING "base C++flags") set(BASE_CXX_FLAGS "/GR /EHsc" CACHE STRING "base C++flags")
else () else ()
set(BASE_FLAGS "" CACHE STRING "base flags") set(BASE_FLAGS "" CACHE STRING "base flags")
set(BASE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "base C flags") set(BASE_C_FLAGS "${CMAKE_C_FLAGS} $ENV{CFLAGS}" CACHE STRING "base C flags")
set(BASE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "base C++ flags") set(BASE_CXX_FLAGS "${CMAKE_CXX_FLAGS} $ENV{CXXFLAGS}" CACHE STRING "base C++ flags")
set(BASE_LD_FLAGS "$ENV{LDFLAGS}" CACHE STRING "base linker flags") set(BASE_LD_FLAGS "$ENV{LDFLAGS}" CACHE STRING "base linker flags")
set(BASE_LIBS "$ENV{LIBS}" CACHE STRING "base libraries") set(BASE_LIBS "$ENV{LIBS}" CACHE STRING "base libraries")
endif () endif ()
if (SOLARIS) if (SOLARIS)
@ -447,13 +447,13 @@ if (VERBOSE)
message(STATUS) message(STATUS)
endif () endif ()
set(CMAKE_C_FLAGS "${BASE_FLAGS} ${BASE_C_FLAGS}") set(CMAKE_C_FLAGS "${BASE_FLAGS} ${BASE_C_FLAGS} ${CMAKE_C_FLAGS}")
set(CMAKE_C_FLAGS_DEBUG "${BASE_FLAGS} ${BASE_C_FLAGS} ${CMAKE_C_FLAGS_DEBUG}") set(CMAKE_C_FLAGS_DEBUG "${BASE_FLAGS} ${BASE_C_FLAGS} ${CMAKE_C_FLAGS_DEBUG}")
set(CMAKE_C_FLAGS_RELEASE "${BASE_FLAGS} ${BASE_C_FLAGS} ${CMAKE_C_FLAGS_RELEASE}") set(CMAKE_C_FLAGS_RELEASE "${BASE_FLAGS} ${BASE_C_FLAGS} ${CMAKE_C_FLAGS_RELEASE}")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${BASE_FLAGS} ${BASE_C_FLAGS} ${CMAKE_C_FLAGS_RELWITHDEBINFO}") set(CMAKE_C_FLAGS_RELWITHDEBINFO "${BASE_FLAGS} ${BASE_C_FLAGS} ${CMAKE_C_FLAGS_RELWITHDEBINFO}")
set(CMAKE_C_FLAGS_MINSIZEREL "${BASE_FLAGS} ${BASE_C_FLAGS} ${CMAKE_C_FLAGS_MINSIZEREL}") set(CMAKE_C_FLAGS_MINSIZEREL "${BASE_FLAGS} ${BASE_C_FLAGS} ${CMAKE_C_FLAGS_MINSIZEREL}")
set(CMAKE_CXX_FLAGS "${BASE_FLAGS} ${BASE_CXX_FLAGS}") set(CMAKE_CXX_FLAGS "${BASE_FLAGS} ${BASE_CXX_FLAGS} ${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS_DEBUG "${BASE_FLAGS} ${BASE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG}") set(CMAKE_CXX_FLAGS_DEBUG "${BASE_FLAGS} ${BASE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG}")
set(CMAKE_CXX_FLAGS_RELEASE "${BASE_FLAGS} ${BASE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE}") set(CMAKE_CXX_FLAGS_RELEASE "${BASE_FLAGS} ${BASE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE}")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${BASE_FLAGS} ${BASE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}") set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${BASE_FLAGS} ${BASE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")

View File

@ -52,8 +52,7 @@ help:
@echo " -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl" @echo " -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl"
@echo " sets the location of the openssl includes and libraries" @echo " sets the location of the openssl includes and libraries"
@echo "" @echo ""
@echo "BOOST supports:" @echo "TCMALLOC supports:"
@echo ""
@echo " -DUSE_TCMALLOC=on" @echo " -DUSE_TCMALLOC=on"
@echo " if ON, link against TCMALLOC" @echo " if ON, link against TCMALLOC"
@echo "" @echo ""

View File

@ -82,16 +82,27 @@ inline std::ostream& operator<< (std::ostream& os, std::list<T> const& l) {
return os; return os;
} }
struct constituent_t { // Constituent type
id_t id;
std::string endpoint;
};
typedef std::vector<constituent_t> constituency_t; // Constituency type
typedef uint32_t state_t; // State type
typedef std::chrono::duration<double> duration_t; // Duration type
using query_t = std::shared_ptr<arangodb::velocypack::Builder>;
struct AgentConfiguration { struct AgentConfiguration {
id_t id; id_t id;
float min_ping; float min_ping;
float max_ping; float max_ping;
float election_timeout;
float append_entries_retry_interval; float append_entries_retry_interval;
std::vector<std::string> end_points; std::vector<std::string> end_points;
std::string end_point_persist; std::string end_point_persist;
bool notify; bool notify;
AgentConfiguration () : min_ping(.15), max_ping(.3) {}; AgentConfiguration () : id(0), min_ping(.15), max_ping(.3), notify(false) {};
AgentConfiguration (uint32_t i, float min_p, float max_p, float appent_i, AgentConfiguration (uint32_t i, float min_p, float max_p, float appent_i,
std::vector<std::string> const& end_p, bool n = false) : std::vector<std::string> const& end_p, bool n = false) :
id(i), min_ping(min_p), max_ping(max_p), id(i), min_ping(min_p), max_ping(max_p),
@ -109,23 +120,25 @@ struct AgentConfiguration {
s << *this; s << *this;
return s.str(); return s.str();
} }
query_t const toBuilder () const {
query_t ret = std::make_shared<arangodb::velocypack::Builder>();
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; typedef AgentConfiguration config_t;
struct constituent_t { // Constituent type
id_t id;
std::string endpoint;
};
typedef std::vector<constituent_t> constituency_t; // Constituency type
typedef uint32_t state_t; // State type
typedef std::chrono::duration<double> duration_t; // Duration type
using query_t = std::shared_ptr<arangodb::velocypack::Builder>;
struct vote_ret_t { struct vote_ret_t {
query_t result; query_t result;
vote_ret_t (query_t res) : result(res) {} explicit vote_ret_t (query_t res) : result(res) {}
}; };
struct read_ret_t { struct read_ret_t {

View File

@ -167,7 +167,7 @@ bool Agent::recvAppendEntriesRPC (term_t term, id_t leaderId, index_t prevIndex,
if (queries->slice().length()) { if (queries->slice().length()) {
LOG(INFO) << "AGENCY: Appending "<< queries->slice().length() LOG(INFO) << "AGENCY: Appending "<< queries->slice().length()
<< " entries to state machine."; << " entries to state machine.";
} else { } else {
// heart-beat // heart-beat
} }
@ -223,8 +223,10 @@ append_entries_t Agent::sendAppendEntriesRPC (
builder.close(); builder.close();
// Send // Send
LOG(INFO) << "AGENCY: Appending " << unconfirmed.size() << " entries up to index " if (unconfirmed.size() > 1) {
<< last << " to follower " << slave_id; LOG(INFO) << "AGENCY: Appending " << unconfirmed.size() << " entries up to index "
<< last << " to follower " << slave_id;
}
arangodb::ClusterComm::instance()->asyncRequest arangodb::ClusterComm::instance()->asyncRequest
("1", 1, _config.end_points[slave_id], ("1", 1, _config.end_points[slave_id],
rest::HttpRequest::HTTP_REQUEST_POST, rest::HttpRequest::HTTP_REQUEST_POST,

View File

@ -45,7 +45,7 @@ public:
/** /**
* @brief Construct with program options * @brief Construct with program options
*/ */
Agent (config_t const&); explicit Agent (config_t const&);
/** /**
* @brief Clean up * @brief Clean up
@ -129,8 +129,8 @@ public:
* @brief 1. Deal with appendEntries to slaves. * @brief 1. Deal with appendEntries to slaves.
* 2. Report success of write processes. * 2. Report success of write processes.
*/ */
void run (); void run () override final;
void beginShutdown () override; void beginShutdown () override final;
/** /**
* @brief Report appended entries from AgentCallback * @brief Report appended entries from AgentCallback

View File

@ -4,7 +4,7 @@
using namespace arangodb::consensus; using namespace arangodb::consensus;
using namespace arangodb::velocypack; using namespace arangodb::velocypack;
AgentCallback::AgentCallback() : _agent(0) {} AgentCallback::AgentCallback() : _agent(0), _last(0), _slave_id(0) {}
AgentCallback::AgentCallback(Agent* agent, id_t slave_id, index_t last) : AgentCallback::AgentCallback(Agent* agent, id_t slave_id, index_t last) :
_agent(agent), _last(last), _slave_id(slave_id) {} _agent(agent), _last(last), _slave_id(slave_id) {}

View File

@ -35,11 +35,10 @@ using namespace arangodb::basics;
using namespace arangodb::rest; using namespace arangodb::rest;
ApplicationAgency::ApplicationAgency() ApplicationAgency::ApplicationAgency()
: ApplicationFeature("agency"), _size(1), _min_election_timeout(0.5), : ApplicationFeature("agency"), _size(1), _min_election_timeout(0.1),
_max_election_timeout(2.0), _election_call_rate_mul(2.5), _max_election_timeout(1.0), _election_call_rate_mul(0.85),
_append_entries_retry_interval(1.0), _append_entries_retry_interval(1.0),
_agent_id(std::numeric_limits<uint32_t>::max()) { _agent_id(std::numeric_limits<uint32_t>::max()) {
} }
@ -71,8 +70,7 @@ void ApplicationAgency::setupOptions(
bool ApplicationAgency::prepare() { bool ApplicationAgency::prepare() {
_disabled = _agency_endpoints.empty() || _disabled = (_agent_id == std::numeric_limits<uint32_t>::max());
_agent_id == std::numeric_limits<uint32_t>::max();
if (_disabled) { if (_disabled) {
return true; return true;

View File

@ -93,12 +93,12 @@ class ApplicationAgency : virtual public arangodb::rest::ApplicationFeature {
public: public:
void setupOptions(std::map<std::string, void setupOptions(std::map<std::string,
arangodb::basics::ProgramOptionsDescription>&); arangodb::basics::ProgramOptionsDescription>&) override final;
bool prepare(); bool prepare() override final;
bool start(); bool start() override final;
bool open(); bool open() override final;
void close(); void close() override final;
agent_t* agent() const; agent_t* agent() const;

View File

@ -42,8 +42,12 @@ void Constituent::configure(Agent* agent) {
_agent = agent; _agent = agent;
if (size() == 1) { if (size() == 1) {
_role = LEADER; _role = LEADER;
} else { } else {
_votes.resize(size()); try {
_votes.resize(size());
} catch (std::exception const& e) {
LOG(FATAL) << "Cannot resize votes vector to " << size();
}
_id = _agent->config().id; _id = _agent->config().id;
if (_agent->config().notify) {// (notify everyone) if (_agent->config().notify) {// (notify everyone)
notifyAll(); notifyAll();
@ -51,8 +55,9 @@ void Constituent::configure(Agent* agent) {
} }
} }
Constituent::Constituent() : Thread("Constituent"), _term(0), _id(0), Constituent::Constituent() :
_gen(std::random_device()()), _role(FOLLOWER), _agent(0) {} Thread("Constituent"), _term(0), _id(0), _gen(std::random_device()()),
_role(FOLLOWER), _leader_id(0), _agent(0) {}
Constituent::~Constituent() { Constituent::~Constituent() {
shutdown(); shutdown();
@ -131,7 +136,6 @@ std::vector<std::string> const& Constituent::end_points() const {
size_t Constituent::notifyAll () { size_t Constituent::notifyAll () {
// Last process notifies everyone // Last process notifies everyone
std::vector<ClusterCommResult> results(_agent->config().end_points.size());
std::stringstream path; std::stringstream path;
path << "/_api/agency_priv/notifyAll?term=" << _term << "&agencyId=" << _id; path << "/_api/agency_priv/notifyAll?term=" << _term << "&agencyId=" << _id;
@ -151,7 +155,7 @@ size_t Constituent::notifyAll () {
if (i != _id) { if (i != _id) {
std::unique_ptr<std::map<std::string, std::string>> headerFields = std::unique_ptr<std::map<std::string, std::string>> headerFields =
std::make_unique<std::map<std::string, std::string> >(); std::make_unique<std::map<std::string, std::string> >();
results[i] = arangodb::ClusterComm::instance()->asyncRequest( arangodb::ClusterComm::instance()->asyncRequest(
"1", 1, end_point(i), rest::HttpRequest::HTTP_REQUEST_POST, path.str(), "1", 1, end_point(i), rest::HttpRequest::HTTP_REQUEST_POST, path.str(),
std::make_shared<std::string>(body.toString()), headerFields, nullptr, std::make_shared<std::string>(body.toString()), headerFields, nullptr,
0.0, true); 0.0, true);
@ -190,8 +194,12 @@ const constituency_t& Constituent::gossip () {
} }
void Constituent::callElection() { 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; _cast = true;
if(_role == CANDIDATE) if(_role == CANDIDATE)
_term++; // raise my term _term++; // raise my term

View File

@ -84,7 +84,7 @@ public:
/** /**
* @brief My daily business * @brief My daily business
*/ */
void run(); void run() override final;
/** /**
* @brief Who is leading * @brief Who is leading

View File

@ -54,7 +54,7 @@ public:
/// @brief Default constructor /// @brief Default constructor
State (std::string const& end_point = "tcp://localhost:8529"); explicit State (std::string const& end_point = "tcp://localhost:8529");
/// @brief Default Destructor /// @brief Default Destructor

View File

@ -53,8 +53,8 @@ using namespace arangodb::velocypack;
class StoreException : public std::exception { class StoreException : public std::exception {
public: public:
StoreException(std::string const& message) : _message(message) {} explicit 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: private:
std::string _message; std::string _message;
}; };
@ -72,7 +72,7 @@ public:
typedef std::map<TimePoint, std::shared_ptr<Node>> TimeTable; typedef std::map<TimePoint, std::shared_ptr<Node>> TimeTable;
/// @brief Construct with name /// @brief Construct with name
Node (std::string const& name); explicit Node (std::string const& name);
/// @brief Construct with name and introduce to tree under parent /// @brief Construct with name and introduce to tree under parent
Node (std::string const& name, Node* parent); Node (std::string const& name, Node* parent);
@ -175,7 +175,7 @@ class Store : public Node, public arangodb::Thread {
public: public:
/// @brief Construct with name /// @brief Construct with name
Store (std::string const& name = "root"); explicit Store (std::string const& name = "root");
/// @brief Destruct /// @brief Destruct
virtual ~Store (); virtual ~Store ();

View File

@ -53,9 +53,9 @@ class DispatcherThread : public Thread {
~DispatcherThread() {shutdown();} ~DispatcherThread() {shutdown();}
protected: protected:
void run(); void run() override;
void addStatus(arangodb::velocypack::Builder* b); void addStatus(arangodb::velocypack::Builder* b) override;
public: public:
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////

View File

@ -70,12 +70,14 @@ inline HttpHandler::status_t RestAgencyHandler::reportUnknownMethod () {
return HttpHandler::status_t(HANDLER_DONE); return HttpHandler::status_t(HANDLER_DONE);
} }
inline HttpHandler::status_t RestAgencyHandler::redirect (id_t leader_id) { void RestAgencyHandler::redirectRequest (id_t leaderId) {
LOG(WARN) << "Redirecting request to " << leader_id; std::string rendpoint = _agent->config().end_points.at(leaderId);
generateError(HttpResponse::NOT_FOUND,404); rendpoint = rendpoint.substr(6,rendpoint.size()-6);
return HttpHandler::status_t(HANDLER_DONE); rendpoint = std::string("http://" + rendpoint + _request->requestPath());
createResponse(HttpResponse::TEMPORARY_REDIRECT);
_response->setHeader("Location", rendpoint);
} }
#include <iostream>
inline HttpHandler::status_t RestAgencyHandler::handleWrite () { inline HttpHandler::status_t RestAgencyHandler::handleWrite () {
arangodb::velocypack::Options options; // TODO: User not wait. arangodb::velocypack::Options options; // TODO: User not wait.
if (_request->requestType() == HttpRequest::HTTP_REQUEST_POST) { if (_request->requestType() == HttpRequest::HTTP_REQUEST_POST) {
@ -89,10 +91,10 @@ inline HttpHandler::status_t RestAgencyHandler::handleWrite () {
} }
write_ret_t ret = _agent->write (query); write_ret_t ret = _agent->write (query);
size_t errors = 0; size_t errors = 0;
if (ret.accepted) { if (ret.accepted) { // We're leading and handling the request
Builder body; Builder body;
body.add(VPackValue(VPackValueType::Object)); body.add(VPackValue(VPackValueType::Object));
_agent->waitFor (ret.indices.back()); // Wait for confirmation (last entry is enough) _agent->waitFor (ret.indices.back()); // Wait for confirmation
for (size_t i = 0; i < ret.indices.size(); ++i) { for (size_t i = 0; i < ret.indices.size(); ++i) {
body.add(std::to_string(i), Value(ret.indices[i])); body.add(std::to_string(i), Value(ret.indices[i]));
if (ret.indices[i] == 0) { if (ret.indices[i] == 0) {
@ -100,19 +102,16 @@ inline HttpHandler::status_t RestAgencyHandler::handleWrite () {
} }
} }
body.close(); body.close();
if (errors > 0) { // epic fail if (errors > 0) { // Some/all requests failed
generateResult(HttpResponse::PRECONDITION_FAILED,body.slice()); generateResult(HttpResponse::PRECONDITION_FAILED,body.slice());
} else {// full success } else { // All good
generateResult(body.slice()); generateResult(body.slice());
} }
} else { } else { // Redirect to leader
//_response->setHeader("Location", _agent->config().end_points[ret.redirect]); redirectRequest(ret.redirect);
generateError(HttpResponse::TEMPORARY_REDIRECT,307);
return HttpHandler::status_t(HANDLER_DONE);
} }
} else { } else { // Unknown method
generateError(HttpResponse::METHOD_NOT_ALLOWED,405); generateError(HttpResponse::METHOD_NOT_ALLOWED,405);
return HttpHandler::status_t(HANDLER_DONE);
} }
return HttpHandler::status_t(HANDLER_DONE); return HttpHandler::status_t(HANDLER_DONE);
} }
@ -124,15 +123,16 @@ inline HttpHandler::status_t RestAgencyHandler::handleRead () {
try { try {
query = _request->toVelocyPack(&options); query = _request->toVelocyPack(&options);
} catch (std::exception const& e) { } catch (std::exception const& e) {
LOG(FATAL) << e.what(); LOG(WARN) << e.what();
generateError(HttpResponse::UNPROCESSABLE_ENTITY,422); generateError(HttpResponse::BAD,400);
return HttpHandler::status_t(HANDLER_DONE); return HttpHandler::status_t(HANDLER_DONE);
} }
read_ret_t ret = _agent->read (query); read_ret_t ret = _agent->read (query);
if (ret.accepted) {
if (ret.accepted) { // I am leading
generateResult(ret.result->slice()); generateResult(ret.result->slice());
} else { } else { // Redirect to leader
generateError(HttpResponse::TEMPORARY_REDIRECT,307); redirectRequest(ret.redirect);
return HttpHandler::status_t(HANDLER_DONE); return HttpHandler::status_t(HANDLER_DONE);
} }
} else { } else {
@ -148,7 +148,7 @@ HttpHandler::status_t RestAgencyHandler::handleTest() {
body.add("id", Value(_agent->id())); body.add("id", Value(_agent->id()));
body.add("term", Value(_agent->term())); body.add("term", Value(_agent->term()));
body.add("leaderId", Value(_agent->leaderID())); body.add("leaderId", Value(_agent->leaderID()));
body.add("configuration", Value(_agent->config().toString())); body.add("configuration", _agent->config().toBuilder()->slice());
body.close(); body.close();
generateResult(body.slice()); generateResult(body.slice());
return HttpHandler::status_t(HANDLER_DONE); return HttpHandler::status_t(HANDLER_DONE);

View File

@ -48,13 +48,13 @@ class RestAgencyHandler : public arangodb::RestBaseHandler {
status_t reportErrorEmptyRequest() ; status_t reportErrorEmptyRequest() ;
status_t reportTooManySuffices() ; status_t reportTooManySuffices() ;
status_t reportUnknownMethod() ; status_t reportUnknownMethod() ;
status_t redirect(id_t leader_id) ;
status_t handleRead() ; status_t handleRead() ;
status_t handleWrite() ; status_t handleWrite() ;
status_t handleTest(); status_t handleTest();
status_t reportMethodNotAllowed(); status_t reportMethodNotAllowed();
status_t handleState(); status_t handleState();
void redirectRequest (id_t leaderId);
consensus::Agent* _agent; consensus::Agent* _agent;
}; };

View File

@ -46,7 +46,7 @@ class RestBaseHandler : public rest::HttpHandler {
explicit RestBaseHandler(rest::HttpRequest* request); explicit RestBaseHandler(rest::HttpRequest* request);
public: public:
void handleError(basics::Exception const&); void handleError(basics::Exception const&) override;
public: public:
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////

View File

@ -466,13 +466,6 @@ class ArangoServer {
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

View File

@ -88,13 +88,13 @@ class VocbaseContext : public arangodb::rest::RequestContext {
/// @brief return authentication realm /// @brief return authentication realm
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
char const* getRealm() const; char const* getRealm() const override;
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
/// @brief checks the authentication /// @brief checks the authentication
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
rest::HttpResponse::HttpResponseCode authenticate(); rest::HttpResponse::HttpResponseCode authenticate() override final;
public: public:
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@ -80,17 +80,17 @@ class ApplicationScheduler : public ApplicationFeature {
void disableControlCHandler(); void disableControlCHandler();
public: public:
void setupOptions(std::map<std::string, basics::ProgramOptionsDescription>&); void setupOptions(std::map<std::string, basics::ProgramOptionsDescription>&) override;
bool afterOptionParsing(basics::ProgramOptions&); bool afterOptionParsing(basics::ProgramOptions&) override;
bool prepare(); bool prepare() override ;
bool start(); bool start() override;
bool open(); bool open() override;
void stop(); void stop() override;
private: private:
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////

View File

@ -69,7 +69,7 @@ struct CustomTypeHandlerImpl : public VPackCustomTypeHandler {
: resolver(resolver) {} : resolver(resolver) {}
void toJson(VPackSlice const& value, VPackDumper* dumper, void toJson(VPackSlice const& value, VPackDumper* dumper,
VPackSlice const& base) { VPackSlice const& base) override {
if (value.head() == 0xf0) { if (value.head() == 0xf0) {
// _id // _id
if (!base.isObject()) { if (!base.isObject()) {
@ -110,7 +110,7 @@ struct CustomTypeHandlerImpl : public VPackCustomTypeHandler {
throw "unknown type!"; throw "unknown type!";
} }
VPackValueLength byteSize(VPackSlice const& value) { VPackValueLength byteSize(VPackSlice const& value) override {
if (value.head() == 0xf0) { if (value.head() == 0xf0) {
// _id // _id
return 1 + 8; // 0xf0 + 8 bytes for collection id return 1 + 8; // 0xf0 + 8 bytes for collection id

View File

@ -81,7 +81,7 @@ class BenchmarkThread : public arangodb::Thread {
/// @brief the thread program /// @brief the thread program
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
void run() { void run() override {
try { try {
_httpClient = _client->createHttpClient(); _httpClient = _client->createHttpClient();
} catch (...) { } catch (...) {

View File

@ -66,13 +66,13 @@ function agencyTestSuite () {
return res; return res;
} }
function writeAgencyRaw(list) { /* function writeAgencyRaw(list) {
var res = request({url: agencyServers[whoseTurn] + "/_api/agency/write", method: "POST", var res = request({url: agencyServers[whoseTurn] + "/_api/agency/write", method: "POST",
followRedirects: true, body: list, followRedirects: true, body: list,
headers: {"Content-Type": "application/json"}}); headers: {"Content-Type": "application/json"}});
res.bodyParsed = JSON.parse(res.body); res.bodyParsed = JSON.parse(res.body);
return res; return res;
} }*/
function readAndCheck(list) { function readAndCheck(list) {
var res = readAgency(list); var res = readAgency(list);

View File

@ -96,7 +96,7 @@ class Exception : public virtual std::exception {
~Exception() throw(); ~Exception() throw();
public: public:
char const* what() const throw(); char const* what() const throw() override;
std::string message() const throw(); std::string message() const throw();
int code() const throw(); int code() const throw();
void addToMessage(std::string const&); void addToMessage(std::string const&);

View File

@ -73,31 +73,31 @@ class EndpointIp : public Endpoint {
/// @brief connect the endpoint /// @brief connect the endpoint
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
TRI_socket_t connect(double, double); TRI_socket_t connect(double, double) override;
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
/// @brief disconnect the endpoint /// @brief disconnect the endpoint
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
virtual void disconnect(); virtual void disconnect() override;
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
/// @brief init an incoming connection /// @brief init an incoming connection
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
virtual bool initIncoming(TRI_socket_t); virtual bool initIncoming(TRI_socket_t) override;
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
/// @brief get port /// @brief get port
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
int getPort() const { return _port; } int getPort() const override { return _port; }
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
/// @brief get host /// @brief get host
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
std::string getHost() const { return _host; } std::string getHost() const override { return _host; }
private: private:
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////

View File

@ -51,13 +51,13 @@ class EndpointIpV4 final : public EndpointIp {
/// @brief get endpoint domain /// @brief get endpoint domain
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
int getDomain() const { return AF_INET; } int getDomain() const override { return AF_INET; }
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
/// @brief get host string for HTTP requests /// @brief get host string for HTTP requests
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
std::string getHostString() const { std::string getHostString() const override{
return getHost() + ':' + arangodb::basics::StringUtils::itoa(getPort()); return getHost() + ':' + arangodb::basics::StringUtils::itoa(getPort());
} }
}; };

View File

@ -51,13 +51,13 @@ class EndpointIpV6 final : public EndpointIp {
/// @brief get endpoint domain /// @brief get endpoint domain
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
int getDomain() const { return AF_INET6; } int getDomain() const override { return AF_INET6; }
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
/// @brief get host string for HTTP requests /// @brief get host string for HTTP requests
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
std::string getHostString() const { std::string getHostString() const override {
return '[' + getHost() + "]:" + return '[' + getHost() + "]:" +
arangodb::basics::StringUtils::itoa(getPort()); arangodb::basics::StringUtils::itoa(getPort());
} }