1
0
Fork 0

Waiting for leader election in AgencyComm::sendWithFailover

This commit is contained in:
Kaveh Vahedipour 2016-11-03 14:24:23 +01:00
parent 0cbe27a799
commit 07cddc3560
1 changed files with 40 additions and 13 deletions

View File

@ -21,6 +21,8 @@
/// @author Jan Steemann
////////////////////////////////////////////////////////////////////////////////
#include <chrono>
#include "AgencyComm.h"
#include <velocypack/Iterator.h>
@ -327,7 +329,9 @@ void AgencyCommResult::clear() {
////////////////////////////////////////////////////////////////////////////////
VPackSlice AgencyCommResult::slice() {
TRI_ASSERT(_vpack != nullptr);
if (_vpack == nullptr) { // If not initialised, initialise to none.
_vpack = std::make_shared<arangodb::velocypack::Builder>();
}
return _vpack->slice();
}
@ -1609,6 +1613,10 @@ AgencyCommResult AgencyComm::sendWithFailover(
std::string const& url, std::string const& body, bool isWatch) {
size_t numEndpoints;
using namespace std::chrono;
auto start = system_clock::now();
seconds ltimeout(static_cast<int>(timeout));
{
READ_LOCKER(readLocker, AgencyComm::_globalLock);
numEndpoints = AgencyComm::_globalEndpoints.size();
@ -1631,6 +1639,9 @@ AgencyCommResult AgencyComm::sendWithFailover(
AgencyCommResult result;
while (tries++ < numEndpoints) {
size_t ltries = 0;
AgencyEndpoint* agencyEndpoint = popEndpoint(forceEndpoint);
TRI_ASSERT(agencyEndpoint != nullptr);
@ -1640,6 +1651,7 @@ AgencyCommResult AgencyComm::sendWithFailover(
<< agencyEndpoint->_endpoint->specification() << " tries: " << tries;
}
while (true) {
try {
result =
send(agencyEndpoint->_connection, method, timeout, realUrl, body);
@ -1654,7 +1666,22 @@ AgencyCommResult AgencyComm::sendWithFailover(
break;
}
// LOG(WARN) << result._statusCode;
if (system_clock::now() - start > ltimeout) {
LOG_TOPIC(ERR, Logger::AGENCYCOMM) << "Timed out waiting for leader "
<< agencyEndpoint->_endpoint->specification() << " tries: " << ltries;
break;
}
if (result._statusCode !=
(int)arangodb::rest::ResponseCode::SERVICE_UNAVAILABLE) {
break;
} else {
LOG_TOPIC(WARN, Logger::AGENCYCOMM) << "Waiting on leader election "
<< agencyEndpoint->_endpoint->specification() << " tries: " << ltries;
}
sleep(1);
}
if (result._statusCode ==
(int)arangodb::rest::ResponseCode::TEMPORARY_REDIRECT) {