mirror of https://gitee.com/bigwinds/arangodb
Waiting for leader election in AgencyComm::sendWithFailover
This commit is contained in:
parent
0cbe27a799
commit
07cddc3560
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue