1
0
Fork 0

fixed potential race during arangob runs

This commit is contained in:
Jan Steemann 2015-05-11 22:57:30 +02:00
parent 214d529d36
commit 5cd7b64ce8
4 changed files with 51 additions and 65 deletions

View File

@ -385,7 +385,7 @@ Handler::status_t RestBatchHandler::execute () {
_response->body().appendText(boundary + "--"); _response->body().appendText(boundary + "--");
if (errors > 0) { if (errors > 0) {
_response->setHeader(HttpResponse::getBatchErrorHeader(), StringUtils::itoa(errors)); _response->setHeader(HttpResponse::BatchErrorHeader, StringUtils::itoa(errors));
} }
// success // success

View File

@ -97,14 +97,14 @@ namespace triagens {
_sslProtocol(sslProtocol), _sslProtocol(sslProtocol),
_keepAlive(keepAlive), _keepAlive(keepAlive),
_async(async), _async(async),
_client(0), _client(nullptr),
_connection(0), _connection(nullptr),
_offset(0), _offset(0),
_counter(0), _counter(0),
_time(0.0), _time(0.0),
_verbose(verbose) { _verbose(verbose) {
_errorHeader = StringUtils::tolower(rest::HttpResponse::getBatchErrorHeader()); _errorHeader = StringUtils::tolower(rest::HttpResponse::BatchErrorHeader);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -112,13 +112,8 @@ namespace triagens {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
~BenchmarkThread () { ~BenchmarkThread () {
if (_client != 0) { delete _client;
delete _client; delete _connection;
}
if (_connection != 0) {
delete _connection;
}
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -487,7 +482,7 @@ namespace triagens {
/// @brief batch size /// @brief batch size
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
const unsigned long _batchSize; unsigned long const _batchSize;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief warning counter /// @brief warning counter
@ -517,19 +512,19 @@ namespace triagens {
/// @brief database name /// @brief database name
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
const std::string _databaseName; std::string const _databaseName;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief HTTP username /// @brief HTTP username
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
const std::string _username; std::string const _username;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief HTTP password /// @brief HTTP password
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
const std::string _password; std::string const _password;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief the request timeout (in s) /// @brief the request timeout (in s)

View File

@ -42,6 +42,12 @@ using namespace std;
// --SECTION-- static public methods // --SECTION-- static public methods
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @brief batch error count header
////////////////////////////////////////////////////////////////////////////////
std::string const HttpResponse::BatchErrorHeader = "X-Arango-Errors";
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief http response string /// @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 // --SECTION-- constructors and destructors
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -278,8 +274,8 @@ HttpResponse::HttpResponse (HttpResponseCode code,
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
HttpResponse::~HttpResponse () { HttpResponse::~HttpResponse () {
for (vector<char const*>::iterator i = _freeables.begin(); i != _freeables.end(); ++i) { for (auto& it : _freeables) {
delete[] (*i); delete[] it;
} }
} }
@ -311,15 +307,14 @@ size_t HttpResponse::contentLength () {
if (_isHeadResponse) { if (_isHeadResponse) {
return _bodySize; return _bodySize;
} }
else {
Dictionary<char const*>::KeyValue const* kv = _headers.lookup("content-length", 14);
if (kv == nullptr) { Dictionary<char const*>::KeyValue const* kv = _headers.lookup("content-length", 14);
return 0;
}
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); string k = StringUtils::tolower(key);
Dictionary<char const*>::KeyValue const* kv = _headers.lookup(k.c_str()); Dictionary<char const*>::KeyValue const* kv = _headers.lookup(k.c_str());
if (kv == 0) { if (kv == nullptr) {
return ""; 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 { string HttpResponse::header (const char* key, const size_t keyLength) const {
Dictionary<char const*>::KeyValue const* kv = _headers.lookup(key, keyLength); Dictionary<char const*>::KeyValue const* kv = _headers.lookup(key, keyLength);
if (kv == 0) { if (kv == nullptr) {
return ""; 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); string k = StringUtils::tolower(key);
Dictionary<char const*>::KeyValue const* kv = _headers.lookup(k.c_str()); Dictionary<char const*>::KeyValue const* kv = _headers.lookup(k.c_str());
if (kv == 0) { if (kv == nullptr) {
found = false; found = false;
return ""; return "";
} }
else { found = true;
found = true; return kv->_value;
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 { string HttpResponse::header (const char* key, const size_t keyLength, bool& found) const {
Dictionary<char const*>::KeyValue const* kv = _headers.lookup(key, keyLength); Dictionary<char const*>::KeyValue const* kv = _headers.lookup(key, keyLength);
if (kv == 0) { if (kv == nullptr) {
found = false; found = false;
return ""; return "";
} }
else { found = true;
found = true; return kv->_value;
return kv->_value;
}
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -417,7 +404,7 @@ map<string, string> HttpResponse::headers () const {
for (_headers.range(begin, end); begin < end; ++begin) { for (_headers.range(begin, end); begin < end; ++begin) {
char const* key = begin->_key; char const* key = begin->_key;
if (key == 0) { if (key == nullptr) {
continue; continue;
} }
@ -438,11 +425,11 @@ void HttpResponse::setHeader (const char* key, const size_t keyLength, string co
else { else {
char const* v = StringUtils::duplicate(value); char const* v = StringUtils::duplicate(value);
if (v != 0) { if (v != nullptr) {
_headers.insert(key, keyLength, v); _headers.insert(key, keyLength, v);
checkHeader(key, 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) { for (_headers.range(begin, end); begin < end; ++begin) {
char const* key = begin->_key; char const* key = begin->_key;
if (key == 0) { if (key == nullptr) {
continue; continue;
} }
const size_t keyLength = strlen(key); size_t const keyLength = strlen(key);
// ignore content-length // ignore content-length
if (keyLength == 14 && *key == 'c' && memcmp(key, "content-length", keyLength) == 0) { if (keyLength == 14 && *key == 'c' && memcmp(key, "content-length", keyLength) == 0) {
@ -812,9 +799,7 @@ size_t HttpResponse::bodySize () const {
if (_isHeadResponse) { if (_isHeadResponse) {
return _bodySize; return _bodySize;
} }
else { return _body.length();
return _body.length();
}
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@ -156,12 +156,6 @@ namespace triagens {
static HttpResponseCode responseCode (int); static HttpResponseCode responseCode (int);
////////////////////////////////////////////////////////////////////////////////
/// @brief return the batch response error count header
////////////////////////////////////////////////////////////////////////////////
static const std::string& getBatchErrorHeader ();
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// --SECTION-- constructors and destructors // --SECTION-- constructors and destructors
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -437,6 +431,18 @@ namespace triagens {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
std::vector<char const*> _freeables; std::vector<char const*> _freeables;
// -----------------------------------------------------------------------------
// --SECTION-- public static members
// -----------------------------------------------------------------------------
public:
////////////////////////////////////////////////////////////////////////////////
/// @brief batch error count header
////////////////////////////////////////////////////////////////////////////////
static std::string const BatchErrorHeader;
}; };
} }
} }