1
0
Fork 0

Merge branch 'devel' of github.com:arangodb/arangodb into bug-fix/fuerte-micro-optimizations

This commit is contained in:
jsteemann 2019-11-04 09:06:59 +01:00
commit 864f69f530
3 changed files with 35 additions and 13 deletions

View File

@ -287,7 +287,7 @@ std::string HttpConnection<ST>::buildRequestBody(Request const& req) {
// construct request path ("/_db/<name>/" prefix) // construct request path ("/_db/<name>/" prefix)
if (!req.header.database.empty()) { if (!req.header.database.empty()) {
header.append("/_db/"); header.append("/_db/", 5);
http::urlEncode(header, req.header.database); http::urlEncode(header, req.header.database);
} }
// must start with /, also turns /_db/abc into /_db/abc/ // must start with /, also turns /_db/abc into /_db/abc/

View File

@ -32,12 +32,11 @@ Connection::~Connection() {
} }
// sendRequest and wait for it to finished. // sendRequest and wait for it to finished.
std::unique_ptr<Response> Connection::sendRequest( std::unique_ptr<Response> Connection::sendRequest(std::unique_ptr<Request> request) {
std::unique_ptr<Request> request) {
FUERTE_LOG_TRACE << "sendRequest (sync): before send" << std::endl; FUERTE_LOG_TRACE << "sendRequest (sync): before send" << std::endl;
WaitGroup wg; WaitGroup wg;
auto rv = std::unique_ptr<Response>(nullptr); std::unique_ptr<Response> rv;
::arangodb::fuerte::v1::Error error = Error::NoError; ::arangodb::fuerte::v1::Error error = Error::NoError;
auto cb = [&](::arangodb::fuerte::v1::Error e, auto cb = [&](::arangodb::fuerte::v1::Error e,
@ -69,11 +68,14 @@ std::unique_ptr<Response> Connection::sendRequest(
std::string Connection::endpoint() const { std::string Connection::endpoint() const {
std::string endpoint; std::string endpoint;
endpoint.reserve(16); endpoint.reserve(32);
// http/vst
endpoint.append(fuerte::to_string(_config._protocolType)); endpoint.append(fuerte::to_string(_config._protocolType));
endpoint.push_back('+'); endpoint.push_back('+');
// tcp/ssl/unix
endpoint.append(fuerte::to_string(_config._socketType)); endpoint.append(fuerte::to_string(_config._socketType));
endpoint.append("://"); endpoint.append("://");
// domain name or IP (xxx.xxx.xxx.xxx)
endpoint.append(_config._host); endpoint.append(_config._host);
if (_config._socketType != SocketType::Unix) { if (_config._socketType != SocketType::Unix) {
endpoint.push_back(':'); endpoint.push_back(':');

View File

@ -161,12 +161,12 @@ std::shared_ptr<fuerte::Connection> V8ClientConnection::createConnection() {
return newConnection; return newConnection;
} }
} }
return _connection;
} catch (fuerte::Error const& e) { // connection error } catch (fuerte::Error const& e) { // connection error
_lastErrorMessage = fuerte::to_string(e); _lastErrorMessage = fuerte::to_string(e);
_lastHttpReturnCode = 503; _lastHttpReturnCode = 503;
}
return nullptr; return nullptr;
}
} }
std::shared_ptr<fuerte::Connection> V8ClientConnection::acquireConnection() { std::shared_ptr<fuerte::Connection> V8ClientConnection::acquireConnection() {
@ -175,7 +175,9 @@ std::shared_ptr<fuerte::Connection> V8ClientConnection::acquireConnection() {
_lastErrorMessage = ""; _lastErrorMessage = "";
_lastHttpReturnCode = 0; _lastHttpReturnCode = 0;
if (!_connection || _connection->state() == fuerte::Connection::State::Failed) { if (!_connection ||
(_connection->state() == fuerte::Connection::State::Disconnected ||
_connection->state() == fuerte::Connection::State::Failed)) {
return createConnection(); return createConnection();
} }
return _connection; return _connection;
@ -186,7 +188,8 @@ void V8ClientConnection::setInterrupted(bool interrupted) {
if (interrupted && _connection != nullptr) { if (interrupted && _connection != nullptr) {
shutdownConnection(); shutdownConnection();
} else if (!interrupted && (_connection == nullptr || } else if (!interrupted && (_connection == nullptr ||
_connection->state() == fuerte::Connection::State::Failed)) { (_connection->state() == fuerte::Connection::State::Disconnected ||
_connection->state() == fuerte::Connection::State::Failed))) {
createConnection(); createConnection();
} }
} }
@ -218,7 +221,6 @@ void V8ClientConnection::timeout(double value) {
} }
void V8ClientConnection::connect(ClientFeature* client) { void V8ClientConnection::connect(ClientFeature* client) {
TRI_ASSERT(client); TRI_ASSERT(client);
std::lock_guard<std::recursive_mutex> guard(_lock); std::lock_guard<std::recursive_mutex> guard(_lock);
_forceJson = client->forceJson(); _forceJson = client->forceJson();
@ -1514,6 +1516,9 @@ v8::Local<v8::Value> V8ClientConnection::requestData(
v8::Local<v8::Value> const& body, v8::Local<v8::Value> const& body,
std::unordered_map<std::string, std::string> const& headerFields, bool isFile) { std::unordered_map<std::string, std::string> const& headerFields, bool isFile) {
bool retry = true;
again:
auto req = std::make_unique<fuerte::Request>(); auto req = std::make_unique<fuerte::Request>();
req->header.restVerb = method; req->header.restVerb = method;
req->header.database = _databaseName; req->header.database = _databaseName;
@ -1589,14 +1594,20 @@ v8::Local<v8::Value> V8ClientConnection::requestData(
return v8::Undefined(isolate); return v8::Undefined(isolate);
} }
fuerte::Error rc = fuerte::Error::NoError;
std::unique_ptr<fuerte::Response> response; std::unique_ptr<fuerte::Response> response;
try { try {
response = connection->sendRequest(std::move(req)); response = connection->sendRequest(std::move(req));
} catch (fuerte::Error const& ec) { } catch (fuerte::Error const& ec) {
return handleResult(isolate, nullptr, ec); rc = ec;
} }
return handleResult(isolate, std::move(response), fuerte::Error::NoError); if (rc == fuerte::Error::ConnectionClosed && retry) {
retry = false;
goto again;
}
return handleResult(isolate, std::move(response), rc);
} }
v8::Local<v8::Value> V8ClientConnection::requestDataRaw( v8::Local<v8::Value> V8ClientConnection::requestDataRaw(
@ -1604,6 +1615,9 @@ v8::Local<v8::Value> V8ClientConnection::requestDataRaw(
v8::Local<v8::Value> const& body, v8::Local<v8::Value> const& body,
std::unordered_map<std::string, std::string> const& headerFields) { std::unordered_map<std::string, std::string> const& headerFields) {
bool retry = true;
again:
auto req = std::make_unique<fuerte::Request>(); auto req = std::make_unique<fuerte::Request>();
req->header.restVerb = method; req->header.restVerb = method;
req->header.database = _databaseName; req->header.database = _databaseName;
@ -1651,21 +1665,27 @@ v8::Local<v8::Value> V8ClientConnection::requestDataRaw(
req->timeout(std::chrono::duration_cast<std::chrono::milliseconds>(_requestTimeout)); req->timeout(std::chrono::duration_cast<std::chrono::milliseconds>(_requestTimeout));
std::shared_ptr<fuerte::Connection> connection = acquireConnection(); std::shared_ptr<fuerte::Connection> connection = acquireConnection();
if (!connection || connection->state() == fuerte::Connection::State::Failed) { if (!connection || connection->state() == fuerte::Connection::State::Failed) {
TRI_V8_SET_EXCEPTION_MESSAGE(TRI_ERROR_SIMPLE_CLIENT_COULD_NOT_CONNECT, TRI_V8_SET_EXCEPTION_MESSAGE(TRI_ERROR_SIMPLE_CLIENT_COULD_NOT_CONNECT,
"not connected"); "not connected");
return v8::Undefined(isolate); return v8::Undefined(isolate);
} }
fuerte::Error rc = fuerte::Error::NoError;
std::unique_ptr<fuerte::Response> response; std::unique_ptr<fuerte::Response> response;
try { try {
response = connection->sendRequest(std::move(req)); response = connection->sendRequest(std::move(req));
} catch (fuerte::Error const& e) { } catch (fuerte::Error const& e) {
rc = e;
_lastErrorMessage.assign(fuerte::to_string(e)); _lastErrorMessage.assign(fuerte::to_string(e));
_lastHttpReturnCode = 503; _lastHttpReturnCode = 503;
} }
if (rc == fuerte::Error::ConnectionClosed && retry) {
retry = false;
goto again;
}
v8::Local<v8::Object> result = v8::Object::New(isolate); v8::Local<v8::Object> result = v8::Object::New(isolate);
if (!response) { if (!response) {
result->Set(TRI_V8_STD_STRING(isolate, StaticStrings::Error), result->Set(TRI_V8_STD_STRING(isolate, StaticStrings::Error),