Skip to content

Commit

Permalink
implement a global deadline when running testcode in the local arango…
Browse files Browse the repository at this point in the history
  • Loading branch information
dothebart authored Mar 13, 2020
1 parent 9ec1e92 commit f57786d
Show file tree
Hide file tree
Showing 14 changed files with 351 additions and 24 deletions.
4 changes: 3 additions & 1 deletion arangod/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,9 @@ target_link_libraries(arango_utils arango::validation)
target_link_libraries(arango_v8server arango_agency)
target_link_libraries(arango_v8server arango_iresearch)
target_link_libraries(arango_v8server arango_replication)
target_link_libraries(arango_v8server arango_v8 ${V8_LIBS})
target_link_libraries(arango_v8server arango_v8)
target_link_libraries(arango_v8server arango_v8_no_deadline)
target_link_libraries(arango_v8server ${V8_LIBS})

target_link_libraries(arango_vocbase arango_agency)
target_link_libraries(arango_vocbase arango_cluster_methods)
Expand Down
1 change: 1 addition & 0 deletions arangod/V8Server/V8DealerFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#include "V8/v8-globals.h"
#include "V8/v8-shell.h"
#include "V8/v8-utils.h"
#include "V8/v8-deadline.h"
#include "V8Server/FoxxQueuesFeature.h"
#include "V8Server/V8Context.h"
#include "V8Server/v8-actions.h"
Expand Down
1 change: 1 addition & 0 deletions arangosh/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ add_executable(${BIN_ARANGOSH}
target_include_directories(${BIN_ARANGOSH} PRIVATE ${PROJECT_SOURCE_DIR}/arangosh)

target_link_libraries(${BIN_ARANGOSH}
arango_v8_deadline
arango_v8
arango
${LINENOISE_LIBS}
Expand Down
108 changes: 97 additions & 11 deletions arangosh/Shell/V8ClientConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "V8/v8-buffer.h"
#include "V8/v8-utils.h"
#include "V8/v8-vpack.h"
#include "V8/v8-deadline.h"

#include <velocypack/Builder.h>
#include <velocypack/Parser.h>
Expand Down Expand Up @@ -154,7 +155,7 @@ std::shared_ptr<fu::Connection> V8ClientConnection::createConnection() {
setCustomError(503, msg);
return nullptr;
}

std::lock_guard<std::recursive_mutex> guard(_lock);
_connection = newConnection;

Expand Down Expand Up @@ -204,11 +205,11 @@ std::shared_ptr<fu::Connection> V8ClientConnection::createConnection() {

std::shared_ptr<fu::Connection> V8ClientConnection::acquireConnection() {
std::lock_guard<std::recursive_mutex> guard(_lock);

_lastErrorMessage = "";
_lastHttpReturnCode = 0;
if (!_connection ||

if (!_connection ||
(_connection->state() == fu::Connection::State::Disconnected ||
_connection->state() == fu::Connection::State::Failed)) {
return createConnection();
Expand Down Expand Up @@ -455,6 +456,9 @@ static void ClientConnection_ConstructorCallback(v8::FunctionCallbackInfo<v8::Va
static void ClientConnection_reconnect(v8::FunctionCallbackInfo<v8::Value> const& args) {
TRI_V8_TRY_CATCH_BEGIN(isolate);
v8::HandleScope scope(isolate);
if (isExecutionDeadlineReached(isolate)) {
return;
}

V8ClientConnection* v8connection =
TRI_UnwrapClass<V8ClientConnection>(args.Holder(), WRAP_TYPE_CONNECTION, TRI_IGETC);
Expand Down Expand Up @@ -564,6 +568,9 @@ static void ClientConnection_httpGetAny(v8::FunctionCallbackInfo<v8::Value> cons
TRI_V8_TRY_CATCH_BEGIN(isolate);
v8::HandleScope scope(isolate);

if (isExecutionDeadlineReached(isolate)) {
return;
}
// get the connection
V8ClientConnection* v8connection =
TRI_UnwrapClass<V8ClientConnection>(args.Holder(), WRAP_TYPE_CONNECTION, TRI_IGETC);
Expand Down Expand Up @@ -614,6 +621,9 @@ static void ClientConnection_httpHeadAny(v8::FunctionCallbackInfo<v8::Value> con
bool raw) {
TRI_V8_TRY_CATCH_BEGIN(isolate);
v8::HandleScope scope(isolate);
if (isExecutionDeadlineReached(isolate)) {
return;
}

// get the connection
V8ClientConnection* v8connection =
Expand Down Expand Up @@ -666,6 +676,9 @@ static void ClientConnection_httpDeleteAny(v8::FunctionCallbackInfo<v8::Value> c
bool raw) {
TRI_V8_TRY_CATCH_BEGIN(isolate);
v8::HandleScope scope(isolate);
if (isExecutionDeadlineReached(isolate)) {
return;
}

// get the connection
V8ClientConnection* v8connection =
Expand Down Expand Up @@ -722,6 +735,9 @@ static void ClientConnection_httpOptionsAny(v8::FunctionCallbackInfo<v8::Value>
bool raw) {
TRI_V8_TRY_CATCH_BEGIN(isolate);
v8::HandleScope scope(isolate);
if (isExecutionDeadlineReached(isolate)) {
return;
}

// get the connection
V8ClientConnection* v8connection =
Expand Down Expand Up @@ -774,6 +790,9 @@ static void ClientConnection_httpPostAny(v8::FunctionCallbackInfo<v8::Value> con
bool raw) {
TRI_V8_TRY_CATCH_BEGIN(isolate);
v8::HandleScope scope(isolate);
if (isExecutionDeadlineReached(isolate)) {
return;
}

// get the connection
V8ClientConnection* v8connection =
Expand Down Expand Up @@ -825,6 +844,9 @@ static void ClientConnection_httpPutAny(v8::FunctionCallbackInfo<v8::Value> cons
bool raw) {
TRI_V8_TRY_CATCH_BEGIN(isolate);
v8::HandleScope scope(isolate);
if (isExecutionDeadlineReached(isolate)) {
return;
}

// get the connection
V8ClientConnection* v8connection =
Expand Down Expand Up @@ -878,6 +900,9 @@ static void ClientConnection_httpPatchAny(v8::FunctionCallbackInfo<v8::Value> co
TRI_V8_TRY_CATCH_BEGIN(isolate);
v8::HandleScope scope(isolate);

if (isExecutionDeadlineReached(isolate)) {
return;
}
// get the connection
V8ClientConnection* v8connection =
TRI_UnwrapClass<V8ClientConnection>(args.Holder(), WRAP_TYPE_CONNECTION, TRI_IGETC);
Expand Down Expand Up @@ -928,6 +953,10 @@ static void ClientConnection_httpSendFile(v8::FunctionCallbackInfo<v8::Value> co
TRI_V8_TRY_CATCH_BEGIN(isolate);
v8::HandleScope scope(isolate);

if (isExecutionDeadlineReached(isolate)) {
return;
}

// get the connection
V8ClientConnection* v8connection =
TRI_UnwrapClass<V8ClientConnection>(args.Holder(), WRAP_TYPE_CONNECTION, TRI_IGETC);
Expand Down Expand Up @@ -982,6 +1011,9 @@ static void ClientConnection_getEndpoint(v8::FunctionCallbackInfo<v8::Value> con
TRI_V8_TRY_CATCH_BEGIN(isolate)
v8::HandleScope scope(isolate);

if (isExecutionDeadlineReached(isolate)) {
return;
}
// get the connection
V8ClientConnection* v8connection =
TRI_UnwrapClass<V8ClientConnection>(args.Holder(), WRAP_TYPE_CONNECTION, TRI_IGETC);
Expand Down Expand Up @@ -1013,6 +1045,9 @@ static void ClientConnection_importCsv(v8::FunctionCallbackInfo<v8::Value> const
v8::Local<v8::Context> context = isolate->GetCurrentContext();
v8::HandleScope scope(isolate);

if (isExecutionDeadlineReached(isolate)) {
return;
}
if (args.Length() < 2) {
TRI_V8_THROW_EXCEPTION_USAGE(
"importCsvFile(<filename>, <collection>[, <options>])");
Expand Down Expand Up @@ -1121,6 +1156,9 @@ static void ClientConnection_importJson(v8::FunctionCallbackInfo<v8::Value> cons
TRI_V8_TRY_CATCH_BEGIN(isolate);
v8::HandleScope scope(isolate);

if (isExecutionDeadlineReached(isolate)) {
return;
}
if (args.Length() < 2) {
TRI_V8_THROW_EXCEPTION_USAGE("importJsonFile(<filename>, <collection>)");
}
Expand Down Expand Up @@ -1195,6 +1233,10 @@ static void ClientConnection_lastHttpReturnCode(v8::FunctionCallbackInfo<v8::Val
TRI_V8_TRY_CATCH_BEGIN(isolate);
v8::HandleScope scope(isolate);

if (isExecutionDeadlineReached(isolate)) {
return;
}

// get the connection
V8ClientConnection* v8connection =
TRI_UnwrapClass<V8ClientConnection>(args.Holder(), WRAP_TYPE_CONNECTION, TRI_IGETC);
Expand All @@ -1220,6 +1262,10 @@ static void ClientConnection_lastErrorMessage(v8::FunctionCallbackInfo<v8::Value
TRI_V8_TRY_CATCH_BEGIN(isolate);
v8::HandleScope scope(isolate);

if (isExecutionDeadlineReached(isolate)) {
return;
}

// get the connection
V8ClientConnection* v8connection =
TRI_UnwrapClass<V8ClientConnection>(args.Holder(), WRAP_TYPE_CONNECTION, TRI_IGETC);
Expand All @@ -1245,6 +1291,10 @@ static void ClientConnection_isConnected(v8::FunctionCallbackInfo<v8::Value> con
TRI_V8_TRY_CATCH_BEGIN(isolate);
v8::HandleScope scope(isolate);

if (isExecutionDeadlineReached(isolate)) {
return;
}

// get the connection
V8ClientConnection* v8connection =
TRI_UnwrapClass<V8ClientConnection>(args.Holder(), WRAP_TYPE_CONNECTION, TRI_IGETC);
Expand Down Expand Up @@ -1272,6 +1322,10 @@ static void ClientConnection_forceJson(v8::FunctionCallbackInfo<v8::Value> const
TRI_V8_TRY_CATCH_BEGIN(isolate);
v8::HandleScope scope(isolate);

if (isExecutionDeadlineReached(isolate)) {
return;
}

// get the connection
V8ClientConnection* v8connection =
TRI_UnwrapClass<V8ClientConnection>(args.Holder(), WRAP_TYPE_CONNECTION, TRI_IGETC);
Expand Down Expand Up @@ -1306,6 +1360,10 @@ static void ClientConnection_timeout(v8::FunctionCallbackInfo<v8::Value> const&
TRI_V8_TRY_CATCH_BEGIN(isolate);
v8::HandleScope scope(isolate);

if (isExecutionDeadlineReached(isolate)) {
return;
}

// get the connection
V8ClientConnection* v8connection =
TRI_UnwrapClass<V8ClientConnection>(args.Holder(), WRAP_TYPE_CONNECTION, TRI_IGETC);
Expand Down Expand Up @@ -1343,6 +1401,10 @@ static void ClientConnection_toString(v8::FunctionCallbackInfo<v8::Value> const&
TRI_V8_TRY_CATCH_BEGIN(isolate);
v8::HandleScope scope(isolate);

if (isExecutionDeadlineReached(isolate)) {
return;
}

// get the connection
V8ClientConnection* v8connection =
TRI_UnwrapClass<V8ClientConnection>(args.Holder(), WRAP_TYPE_CONNECTION, TRI_IGETC);
Expand Down Expand Up @@ -1379,6 +1441,10 @@ static void ClientConnection_getVersion(v8::FunctionCallbackInfo<v8::Value> cons
TRI_V8_TRY_CATCH_BEGIN(isolate);
v8::HandleScope scope(isolate);

if (isExecutionDeadlineReached(isolate)) {
return;
}

// get the connection
V8ClientConnection* v8connection =
TRI_UnwrapClass<V8ClientConnection>(args.Holder(), WRAP_TYPE_CONNECTION, TRI_IGETC);
Expand All @@ -1403,6 +1469,10 @@ static void ClientConnection_getMode(v8::FunctionCallbackInfo<v8::Value> const&
TRI_V8_TRY_CATCH_BEGIN(isolate);
v8::HandleScope scope(isolate);

if (isExecutionDeadlineReached(isolate)) {
return;
}

// get the connection
V8ClientConnection* v8connection =
TRI_UnwrapClass<V8ClientConnection>(args.Holder(), WRAP_TYPE_CONNECTION, TRI_IGETC);
Expand All @@ -1427,6 +1497,10 @@ static void ClientConnection_getRole(v8::FunctionCallbackInfo<v8::Value> const&
TRI_V8_TRY_CATCH_BEGIN(isolate);
v8::HandleScope scope(isolate);

if (isExecutionDeadlineReached(isolate)) {
return;
}

// get the connection
V8ClientConnection* v8connection =
TRI_UnwrapClass<V8ClientConnection>(args.Holder(), WRAP_TYPE_CONNECTION, TRI_IGETC);
Expand All @@ -1451,6 +1525,10 @@ static void ClientConnection_getDatabaseName(v8::FunctionCallbackInfo<v8::Value>
TRI_V8_TRY_CATCH_BEGIN(isolate);
v8::HandleScope scope(isolate);

if (isExecutionDeadlineReached(isolate)) {
return;
}

// get the connection
V8ClientConnection* v8connection =
TRI_UnwrapClass<V8ClientConnection>(args.Holder(), WRAP_TYPE_CONNECTION, TRI_IGETC);
Expand All @@ -1475,6 +1553,10 @@ static void ClientConnection_setDatabaseName(v8::FunctionCallbackInfo<v8::Value>
TRI_V8_TRY_CATCH_BEGIN(isolate);
v8::HandleScope scope(isolate);

if (isExecutionDeadlineReached(isolate)) {
return;
}

// get the connection
V8ClientConnection* v8connection =
TRI_UnwrapClass<V8ClientConnection>(args.Holder(), WRAP_TYPE_CONNECTION, TRI_IGETC);
Expand Down Expand Up @@ -1590,7 +1672,7 @@ v8::Local<v8::Value> V8ClientConnection::requestData(
} else {
req->header.contentType(fu::ContentType::Custom);
}

} else if (boost::iequals(StaticStrings::Accept, pair.first)) {
if (pair.second == StaticStrings::MimeTypeVPack) {
req->header.acceptType(fu::ContentType::VPack);
Expand Down Expand Up @@ -1667,7 +1749,9 @@ v8::Local<v8::Value> V8ClientConnection::requestData(
req->header.acceptType(fu::ContentType::VPack);
}
}
req->timeout(std::chrono::duration_cast<std::chrono::milliseconds>(_requestTimeout));
req->timeout(
correctTimeoutToExecutionDeadline(
std::chrono::duration_cast<std::chrono::milliseconds>(_requestTimeout)));

std::shared_ptr<fu::Connection> connection = acquireConnection();
if (!connection || connection->state() == fu::Connection::State::Failed) {
Expand All @@ -1683,7 +1767,7 @@ v8::Local<v8::Value> V8ClientConnection::requestData(
} catch (fu::Error const& ec) {
rc = ec;
}

if (rc == fu::Error::ConnectionClosed && retry) {
retry = false;
goto again;
Expand All @@ -1696,7 +1780,7 @@ v8::Local<v8::Value> V8ClientConnection::requestDataRaw(
v8::Isolate* isolate, fu::RestVerb method, arangodb::velocypack::StringRef const& location,
v8::Local<v8::Value> const& body,
std::unordered_map<std::string, std::string> const& headerFields) {

bool retry = true;

again:
Expand Down Expand Up @@ -1749,7 +1833,9 @@ v8::Local<v8::Value> V8ClientConnection::requestDataRaw(
if (req->header.acceptType() == fu::ContentType::Unset) {
req->header.acceptType(fu::ContentType::VPack);
}
req->timeout(std::chrono::duration_cast<std::chrono::milliseconds>(_requestTimeout));
req->timeout(
correctTimeoutToExecutionDeadline(
std::chrono::duration_cast<std::chrono::milliseconds>(_requestTimeout)));

std::shared_ptr<fu::Connection> connection = acquireConnection();
if (!connection || connection->state() == fu::Connection::State::Failed) {
Expand All @@ -1766,7 +1852,7 @@ v8::Local<v8::Value> V8ClientConnection::requestDataRaw(
_lastErrorMessage.assign(fu::to_string(e));
_lastHttpReturnCode = 503;
}

if (rc == fu::Error::ConnectionClosed && retry) {
retry = false;
goto again;
Expand Down Expand Up @@ -1939,7 +2025,7 @@ v8::Local<v8::Value> V8ClientConnection::handleResult(v8::Isolate* isolate,
VPackParser parser(builder);
try {
parser.parse(str, sb.size());
ret = TRI_VPackToV8(isolate, builder->slice(), parser.options, nullptr);
ret = TRI_VPackToV8(isolate, builder->slice(), parser.options, nullptr);
} catch (std::exception const& ex) {
std::string err("Error parsing the server JSON reply: ");
err += ex.what();
Expand Down
2 changes: 2 additions & 0 deletions arangosh/Shell/V8ShellFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include "V8/v8-globals.h"
#include "V8/v8-shell.h"
#include "V8/v8-utils.h"
#include "V8/v8-deadline.h"
#include "V8/v8-vpack.h"

#include <regex>
Expand Down Expand Up @@ -1100,6 +1101,7 @@ void V8ShellFeature::initGlobals() {

TRI_InitV8Buffer(_isolate);
TRI_InitV8Utils(_isolate, context, _startupDirectory, modules);
TRI_InitV8Deadline(_isolate);
TRI_InitV8Shell(_isolate);

// pager functions (overwrite existing SYS_OUTPUT from InitV8Utils)
Expand Down
9 changes: 9 additions & 0 deletions js/client/bootstrap/modules/internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@
delete global.SYS_ARANGO;
}

// //////////////////////////////////////////////////////////////////////////////
// / @brief set deadline for external requests & sleeps
// //////////////////////////////////////////////////////////////////////////////

if (global.SYS_COMMUNICATE_SLEEP_DEADLINE) {
exports.SetGlobalExecutionDeadlineTo = global.SYS_COMMUNICATE_SLEEP_DEADLINE;
delete global.SYS_COMMUNICATE_SLEEP_DEADLINE;
}

// //////////////////////////////////////////////////////////////////////////////
// / @brief write-ahead log functionality
// //////////////////////////////////////////////////////////////////////////////
Expand Down
Loading

0 comments on commit f57786d

Please sign in to comment.