mirror of https://gitee.com/bigwinds/arangodb
fixed potential race during arangob runs
This commit is contained in:
parent
214d529d36
commit
5cd7b64ce8
|
@ -385,7 +385,7 @@ Handler::status_t RestBatchHandler::execute () {
|
|||
_response->body().appendText(boundary + "--");
|
||||
|
||||
if (errors > 0) {
|
||||
_response->setHeader(HttpResponse::getBatchErrorHeader(), StringUtils::itoa(errors));
|
||||
_response->setHeader(HttpResponse::BatchErrorHeader, StringUtils::itoa(errors));
|
||||
}
|
||||
|
||||
// success
|
||||
|
|
|
@ -97,14 +97,14 @@ namespace triagens {
|
|||
_sslProtocol(sslProtocol),
|
||||
_keepAlive(keepAlive),
|
||||
_async(async),
|
||||
_client(0),
|
||||
_connection(0),
|
||||
_client(nullptr),
|
||||
_connection(nullptr),
|
||||
_offset(0),
|
||||
_counter(0),
|
||||
_time(0.0),
|
||||
_verbose(verbose) {
|
||||
|
||||
_errorHeader = StringUtils::tolower(rest::HttpResponse::getBatchErrorHeader());
|
||||
_errorHeader = StringUtils::tolower(rest::HttpResponse::BatchErrorHeader);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -112,13 +112,8 @@ namespace triagens {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
~BenchmarkThread () {
|
||||
if (_client != 0) {
|
||||
delete _client;
|
||||
}
|
||||
|
||||
if (_connection != 0) {
|
||||
delete _connection;
|
||||
}
|
||||
delete _client;
|
||||
delete _connection;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -487,7 +482,7 @@ namespace triagens {
|
|||
/// @brief batch size
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const unsigned long _batchSize;
|
||||
unsigned long const _batchSize;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief warning counter
|
||||
|
@ -517,19 +512,19 @@ namespace triagens {
|
|||
/// @brief database name
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const std::string _databaseName;
|
||||
std::string const _databaseName;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief HTTP username
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const std::string _username;
|
||||
std::string const _username;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief HTTP password
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const std::string _password;
|
||||
std::string const _password;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief the request timeout (in s)
|
||||
|
|
|
@ -42,6 +42,12 @@ using namespace std;
|
|||
// --SECTION-- static public methods
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief batch error count header
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::string const HttpResponse::BatchErrorHeader = "X-Arango-Errors";
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief http response string
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -239,16 +245,6 @@ HttpResponse::HttpResponseCode HttpResponse::responseCode (int code) {
|
|||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief return the batch error count header
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const string& HttpResponse::getBatchErrorHeader () {
|
||||
static const string header = "X-Arango-Errors";
|
||||
|
||||
return header;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- constructors and destructors
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -278,8 +274,8 @@ HttpResponse::HttpResponse (HttpResponseCode code,
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
HttpResponse::~HttpResponse () {
|
||||
for (vector<char const*>::iterator i = _freeables.begin(); i != _freeables.end(); ++i) {
|
||||
delete[] (*i);
|
||||
for (auto& it : _freeables) {
|
||||
delete[] it;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -311,15 +307,14 @@ size_t HttpResponse::contentLength () {
|
|||
if (_isHeadResponse) {
|
||||
return _bodySize;
|
||||
}
|
||||
else {
|
||||
Dictionary<char const*>::KeyValue const* kv = _headers.lookup("content-length", 14);
|
||||
|
||||
if (kv == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
Dictionary<char const*>::KeyValue const* kv = _headers.lookup("content-length", 14);
|
||||
|
||||
return StringUtils::uint32(kv->_value);
|
||||
if (kv == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return StringUtils::uint32(kv->_value);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -346,12 +341,10 @@ string HttpResponse::header (string const& key) const {
|
|||
string k = StringUtils::tolower(key);
|
||||
Dictionary<char const*>::KeyValue const* kv = _headers.lookup(k.c_str());
|
||||
|
||||
if (kv == 0) {
|
||||
if (kv == nullptr) {
|
||||
return "";
|
||||
}
|
||||
else {
|
||||
return kv->_value;
|
||||
}
|
||||
return kv->_value;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -361,12 +354,10 @@ string HttpResponse::header (string const& key) const {
|
|||
string HttpResponse::header (const char* key, const size_t keyLength) const {
|
||||
Dictionary<char const*>::KeyValue const* kv = _headers.lookup(key, keyLength);
|
||||
|
||||
if (kv == 0) {
|
||||
if (kv == nullptr) {
|
||||
return "";
|
||||
}
|
||||
else {
|
||||
return kv->_value;
|
||||
}
|
||||
return kv->_value;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -377,14 +368,12 @@ string HttpResponse::header (string const& key, bool& found) const {
|
|||
string k = StringUtils::tolower(key);
|
||||
Dictionary<char const*>::KeyValue const* kv = _headers.lookup(k.c_str());
|
||||
|
||||
if (kv == 0) {
|
||||
if (kv == nullptr) {
|
||||
found = false;
|
||||
return "";
|
||||
}
|
||||
else {
|
||||
found = true;
|
||||
return kv->_value;
|
||||
}
|
||||
found = true;
|
||||
return kv->_value;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -394,14 +383,12 @@ string HttpResponse::header (string const& key, bool& found) const {
|
|||
string HttpResponse::header (const char* key, const size_t keyLength, bool& found) const {
|
||||
Dictionary<char const*>::KeyValue const* kv = _headers.lookup(key, keyLength);
|
||||
|
||||
if (kv == 0) {
|
||||
if (kv == nullptr) {
|
||||
found = false;
|
||||
return "";
|
||||
}
|
||||
else {
|
||||
found = true;
|
||||
return kv->_value;
|
||||
}
|
||||
found = true;
|
||||
return kv->_value;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -417,7 +404,7 @@ map<string, string> HttpResponse::headers () const {
|
|||
for (_headers.range(begin, end); begin < end; ++begin) {
|
||||
char const* key = begin->_key;
|
||||
|
||||
if (key == 0) {
|
||||
if (key == nullptr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -438,11 +425,11 @@ void HttpResponse::setHeader (const char* key, const size_t keyLength, string co
|
|||
else {
|
||||
char const* v = StringUtils::duplicate(value);
|
||||
|
||||
if (v != 0) {
|
||||
if (v != nullptr) {
|
||||
_headers.insert(key, keyLength, v);
|
||||
checkHeader(key, v);
|
||||
|
||||
_freeables.push_back(v);
|
||||
_freeables.emplace_back(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -694,11 +681,11 @@ void HttpResponse::writeHeader (StringBuffer* output) {
|
|||
for (_headers.range(begin, end); begin < end; ++begin) {
|
||||
char const* key = begin->_key;
|
||||
|
||||
if (key == 0) {
|
||||
if (key == nullptr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const size_t keyLength = strlen(key);
|
||||
size_t const keyLength = strlen(key);
|
||||
|
||||
// ignore content-length
|
||||
if (keyLength == 14 && *key == 'c' && memcmp(key, "content-length", keyLength) == 0) {
|
||||
|
@ -812,9 +799,7 @@ size_t HttpResponse::bodySize () const {
|
|||
if (_isHeadResponse) {
|
||||
return _bodySize;
|
||||
}
|
||||
else {
|
||||
return _body.length();
|
||||
}
|
||||
return _body.length();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -156,12 +156,6 @@ namespace triagens {
|
|||
|
||||
static HttpResponseCode responseCode (int);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief return the batch response error count header
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static const std::string& getBatchErrorHeader ();
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- constructors and destructors
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -437,6 +431,18 @@ namespace triagens {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::vector<char const*> _freeables;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- public static members
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief batch error count header
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static std::string const BatchErrorHeader;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue