1
0
Fork 0

use X-Etcd-Index header

This commit is contained in:
Jan Steemann 2013-12-09 17:55:49 +01:00
parent 996be652f1
commit a67ee89a9e
3 changed files with 18 additions and 3 deletions

View File

@ -86,6 +86,7 @@ AgencyEndpoint::~AgencyEndpoint () {
AgencyCommResult::AgencyCommResult ()
: _message(),
_body(),
_index(0),
_statusCode(0) {
}
@ -882,10 +883,17 @@ bool AgencyComm::send (triagens::httpclient::GeneralClientConnection* connection
delete response;
return false;
}
result._statusCode = response->getHttpReturnCode();
result._message = response->getHttpReturnMessage();
result._body = response->getBody().str();
result._index = 0;
result._statusCode = response->getHttpReturnCode();
bool found = false;
std::string lastIndex = response->getHeaderField("x-etcd-index", found);
if (found) {
result._index = triagens::basics::StringUtils::uint64(lastIndex);
}
LOG_TRACE("request to agency returned status code %d, message: '%s', body: '%s'",
result._statusCode,

View File

@ -130,7 +130,8 @@ namespace triagens {
std::string _message;
std::string _body;
int _statusCode;
uint64_t _index;
int _statusCode;
};
// -----------------------------------------------------------------------------

View File

@ -115,6 +115,7 @@ void HeartbeatThread::run () {
if (result.successful()) {
// value has changed!
handleStateChange(result, lastCommandIndex);
// sleep a while
@ -180,6 +181,11 @@ uint64_t HeartbeatThread::getLastCommandIndex () {
}
}
}
if (result._index > 0) {
// use the value returned in header X-Etcd-Index
return result._index;
}
// nothing found. this is not an error
return 0;