10000 implement a global deadline when running testcode in the local arango… · arangodb/arangodb@f57786d · GitHub
[go: up one dir, main page]

Skip to content

Commit f57786d

Browse files
authored
implement a global deadline when running testcode in the local arangosh (#11123)
1 parent 9ec1e92 commit f57786d

File tree

14 files changed

+351
-24
lines changed

14 files changed

+351
-24
lines changed

arangod/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,9 @@ target_link_libraries(arango_utils arango::validation)
934934
target_link_libraries(arango_v8server arango_agency)
935935
target_link_libraries(arango_v8server arango_iresearch)
936936
target_link_libraries(arango_v8server arango_replication)
937-
target_link_libraries(arango_v8server arango_v8 ${V8_LIBS})
937+
target_link_libraries(arango_v8server arango_v8)
938+
target_link_libraries(arango_v8server arango_v8_no_deadline)
939+
target_link_libraries(arango_v8server ${V8_LIBS})
938940

939941
target_link_libraries(arango_vocbase arango_agency)
940942
target_link_libraries(arango_vocbase arango_cluster_methods)

arangod/V8Server/V8DealerFeature.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
#include "V8/v8-globals.h"
6161
#include "V8/v8-shell.h"
6262
#include "V8/v8-utils.h"
63+
#include "V8/v8-deadline.h"
6364
#include "V8Server/FoxxQueuesFeature.h"
6465
#include "V8Server/V8Context.h"
6566
#include "V8Server/v8-actions.h"

arangosh/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
< B41A /tbody>
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,7 @@ add_executable(${BIN_ARANGOSH}
413413
target_include_directories(${BIN_ARANGOSH} PRIVATE ${PROJECT_SOURCE_DIR}/arangosh)
414414

415415
target_link_libraries(${BIN_ARANGOSH}
416+
arango_v8_deadline
416417
arango_v8
417418
arango
418419
${LINENOISE_LIBS}

arangosh/Shell/V8ClientConnection.cpp

Lines changed: 97 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include "V8/v8-buffer.h"
4848
#include "V8/v8-utils.h"
4949
#include "V8/v8-vpack.h"
50+
#include "V8/v8-deadline.h"
5051

5152
#include <velocypack/Builder.h>
5253
#include <velocypack/Parser.h>
@@ -154,7 +155,7 @@ std::shared_ptr<fu::Connection> V8ClientConnection::createConnection() {
154155
setCustomError(503, msg);
155156
return nullptr;
156157
}
157-
158+
158159
std::lock_guard<std::recursive_mutex> guard(_lock);
159160
_connection = newConnection;
160161

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

205206
std::shared_ptr<fu::Connection> V8ClientConnection::acquireConnection() {
206207
std::lock_guard<std::recursive_mutex> guard(_lock);
207-
208+
208209
_lastErrorMessage = "";
209210
_lastHttpReturnCode = 0;
210-
211-
if (!_connection ||
211+
212+
if (!_connection ||
212213
(_connection->state() == fu::Connection::State::Disconnected ||
213214
_connection->state() == fu::Connection::State::Failed)) {
214215
return createConnection();
@@ -455,6 +456,9 @@ static void ClientConnection_ConstructorCallback(v8::FunctionCallbackInfo<v8::Va
455456
static void ClientConnection_reconnect(v8::FunctionCallbackInfo<v8::Value> const& args) {
456457
TRI_V8_TRY_CATCH_BEGIN(isolate);
457458
v8::HandleScope scope(isolate);
459+
if (isExecutionDeadlineReached(isolate)) {
460+
return;
461+
}
458462

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

571+
if (isExecutionDeadlineReached(isolate)) {
572+
return;
573+
}
567574
// get the connection
568575
V8ClientConnection* v8connection =
569576
TRI_UnwrapClass<V8ClientConnection>(args.Holder(), WRAP_TYPE_CONNECTION, TRI_IGETC);
@@ -614,6 +621,9 @@ static void ClientConnection_httpHeadAny(v8::FunctionCallbackInfo<v8::Value> con
614621
bool raw) {
615622
TRI_V8_TRY_CATCH_BEGIN(isolate);
616623
v8::HandleScope scope(isolate);
624+
if (isExecutionDeadlineReached(isolate)) {
625+
return;
626+
}
617627

618628
// get the connection
619629
V8ClientConnection* v8connection =
@@ -666,6 +676,9 @@ static void ClientConnection_httpDeleteAny(v8::FunctionCallbackInfo<v8::Value> c
666676
bool raw) {
667677
TRI_V8_TRY_CATCH_BEGIN(isolate);
668678
v8::HandleScope scope(isolate);
679+
if (isExecutionDeadlineReached(isolate)) {
680+
return;
681+
}
669682

670683
// get the connection
671684
V8ClientConnection* v8connection =
@@ -722,6 +735,9 @@ static void ClientConnection_httpOptionsAny(v8::FunctionCallbackInfo<v8::Value>
722735
bool raw) {
723736
TRI_V8_TRY_CATCH_BEGIN(isolate);
724737
v8::HandleScope scope(isolate);
738+
if (isExecutionDeadlineReached(isolate)) {
739+
return;
740+
}
725741

726742
// get the connection
727743
V8ClientConnection* v8connection =
@@ -774,6 +790,9 @@ static void ClientConnection_httpPostAny(v8::FunctionCallbackInfo<v8::Value> con
774790
bool raw) {
775791
TRI_V8_TRY_CATCH_BEGIN(isolate);
776792
v8::HandleScope scope(isolate);
793+
if (isExecutionDeadlineReached(isolate)) {
794+
return;
795+
}
777796

778797
// get the connection
779798
V8ClientConnection* v8connection =
@@ -825,6 +844,9 @@ static void ClientConnection_httpPutAny(v8::FunctionCallbackInfo<v8::Value> cons
825844
bool raw) {
826845
TRI_V8_TRY_CATCH_BEGIN(isolate);
827846
v8::HandleScope scope(isolate);
847+
if (isExecutionDeadlineReached(isolate)) {
848+
return;
849+
}
828850

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

903+
if (isExecutionDeadlineReached(isolate)) {
904+
return;
905+
}
881906
// get the connection
882907
V8ClientConnection* v8connection =
883908
TRI_UnwrapClass<V8ClientConnection>(args.Holder(), WRAP_TYPE_CONNECTION, TRI_IGETC);
@@ -928,6 +953,10 @@ static void ClientConnection_httpSendFile(v8::FunctionCallbackInfo<v8::Value> co
928953
TRI_V8_TRY_CATCH_BEGIN(isolate);
929954
v8::HandleScope scope(isolate);
930955

956+
if (isExecutionDeadlineReached(isolate)) {
957+
return;
958+
}
959+
931960
// get the connection
932961
V8ClientConnection* v8connection =
933962
TRI_UnwrapClass<V8ClientConnection>(args.Holder(), WRAP_TYPE_CONNECTION, TRI_IGETC);
@@ -982,6 +1011,9 @@ static void ClientConnection_getEndpoint(v8::FunctionCallbackInfo<v8::Value> con
9821011
TRI_V8_TRY_CATCH_BEGIN(isolate)
9831012
v8::HandleScope scope(isolate);
9841013

1014+
if (isExecutionDeadlineReached(isolate)) {
1015+
return;
1016+
}
9851017
// get the connection
9861018
V8ClientConnection* v8connection =
9871019
TRI_UnwrapClass<V8ClientConnection>(args.Holder(), WRAP_TYPE_CONNECTION, TRI_IGETC);
@@ -1013,6 +1045,9 @@ static void ClientConnection_importCsv(v8::FunctionCallbackInfo<v8::Value> const
10131045
v8::Local<v8::Context> context = isolate->GetCurrentContext();
10141046
v8::HandleScope scope(isolate);
10151047

1048+
if (isExecutionDeadlineReached(isolate)) {
1049+
return;
1050+
}
10161051
if (args.Length() < 2) {
10171052
TRI_V8_THROW_EXCEPTION_USAGE(
10181053
"importCsvFile(<filename>, <collection>[, <options>])");
@@ -1121,6 +1156,9 @@ static void ClientConnection_importJson(v8::FunctionCallbackInfo<v8::Value> cons
11211156
TRI_V8_TRY_CATCH_BEGIN(isolate);
11221157
v8::HandleScope scope(isolate);
11231158

1159+
if (isExecutionDeadlineReached(isolate)) {
1160+
return;
1161+
}
11241162
if (args.Length() < 2) {
11251163
TRI_V8_THROW_EXCEPTION_USAGE("importJsonFile(<filename>, <collection>)");
11261164
}
@@ -1195,6 +1233,10 @@ static void ClientConnection_lastHttpReturnCode(v8::FunctionCallbackInfo<v8::Val
11951233
TRI_V8_TRY_CATCH_BEGIN(isolate);
11961234
v8::HandleScope scope(isolate);
11971235

1236+
if (isExecutionDeadlineReached(isolate)) {
1237+
return;
1238+
}
1239+
11981240
// get the connection
11991241
V8ClientConnection* v8connection =
12001242
TRI_UnwrapClass<V8ClientConnection>(args.Holder(), WRAP_TYPE_CONNECTION, TRI_IGETC);
@@ -1220,6 +1262,10 @@ static void ClientConnection_lastErrorMessage(v8::FunctionCallbackInfo<v8::Value
12201262
TRI_V8_TRY_CATCH_BEGIN(isolate);
12211263
v8::HandleScope scope(isolate);
12221264

1265+
if (isExecutionDeadlineReached(isolate)) {
1266+
return;
1267+
}
1268+
12231269
// get the connection
12241270
V8ClientConnection* v8connection =
12251271
TRI_UnwrapClass<V8ClientConnection>(args.Holder(), WRAP_TYPE_CONNECTION, TRI_IGETC);
@@ -1245,6 +1291,10 @@ static void ClientConnection_isConnected(v8::FunctionCallbackInfo<v8::Value> con
12451291
TRI_V8_TRY_CATCH_BEGIN(isolate);
12461292
v8::HandleScope scope(isolate);
12471293

1294+
if (isExecutionDeadlineReached(isolate)) {
1295+
return;
1296+
}
1297+
12481298
// get the connection
12491299
V8ClientConnection* v8connection =
12501300
TRI_UnwrapClass<V8ClientConnection>(args.Holder(), WRAP_TYPE_CONNECTION, TRI_IGETC);
@@ -1272,6 +1322,10 @@ static void ClientConnection_forceJson(v8::FunctionCallbackInfo<v8::Value> const
12721322
TRI_V8_TRY_CATCH_BEGIN(isolate);
12731323
v8::HandleScope scope(isolate);
12741324

1325+
if (isExecutionDeadlineReached(isolate)) {
1326+
return;
1327+
}
1328+
12751329
// get the connection
12761330
V8ClientConnection* v8connection =
12771331
TRI_UnwrapClass<V8ClientConnection>(args.Holder(), WRAP_TYPE_CONNECTION, TRI_IGETC);
@@ -1306,6 +1360,10 @@ static void ClientConnection_timeout(v8::FunctionCallbackInfo<v8::Value> const&
13061360
TRI_V8_TRY_CATCH_BEGIN(isolate);
13071361
v8::HandleScope scope(isolate);
13081362

1363+
if (isExecutionDeadlineReached(isolate)) {
1364+
return;
1365+
}
1366+
13091367
// get the connection
13101368
V8ClientConnection* v8connection =
13111369
TRI_UnwrapClass<V8ClientConnection>(args.Holder(), WRAP_TYPE_CONNECTION, TRI_IGETC);
@@ -1343,6 +1401,10 @@ static void ClientConnection_toString(v8::FunctionCallbackInfo<v8::Value> const&
13431401
TRI_V8_TRY_CATCH_BEGIN(isolate);
13441402
v8::HandleScope scope(isolate);
13451403

1404+
if (isExecutionDeadlineReached(isolate)) {
1405+
return;
1406+
}
1407+
13461408
// get the connection
13471409
V8ClientConnection* v8connection =
13481410
TRI_UnwrapClass<V8ClientConnection>(args.Holder(), WRAP_TYPE_CONNECTION, TRI_IGETC);
@@ -1379,6 +1441,10 @@ static void ClientConnection_getVersion(v8::FunctionCallbackInfo<v8::Value> cons
13791441
TRI_V8_TRY_CATCH_BEGIN(isolate);
13801442
v8::HandleScope scope(isolate);
13811443

1444+
if (isExecutionDeadlineReached(isolate)) {
1445+
return;
1446+
}
1447+
13821448
// get the connection
13831449
V8ClientConnection* v8connection =
13841450
TRI_UnwrapClass<V8ClientConnection>(args.Holder(), WRAP_TYPE_CONNECTION, TRI_IGETC);
@@ -1403,6 +1469,10 @@ static void ClientConnection_getMode(v8::FunctionCallbackInfo<v8::Value> const&
14031469
TRI_V8_TRY_CATCH_BEGIN(isolate);
14041470
v8::HandleScope scope(isolate);
14051471

1472+
if (isExecutionDeadlineReached(isolate)) {
1473+
return;
1474+
}
1475+
14061476
// get the connection
14071477
V8ClientConnection* v8connection =
14081478
TRI_UnwrapClass<V8ClientConnection>(args.Holder(), WRAP_TYPE_CONNECTION, TRI_IGETC);
@@ -1427,6 +1497,10 @@ static void ClientConnection_getRole(v8::FunctionCallbackInfo<v8::Value> const&
14271497
TRI_V8_TRY_CATCH_BEGIN(isolate);
14281498
v8::HandleScope scope(isolate);
14291499

1500+
if (isExecutionDeadlineReached(isolate)) {
1501+
return;
1502+
}
1503+
14301504
// get the connection
14311505
V8ClientConnection* v8connection =
14321506
TRI_UnwrapClass<V8ClientConnection>(args.Holder(), WRAP_TYPE_CONNECTION, TRI_IGETC);
@@ -1451,6 +1525,10 @@ static void ClientConnection_getDatabaseName(v8::FunctionCallbackInfo<v8::Value>
14511525
TRI_V8_TRY_CATCH_BEGIN(isolate);
14521526
v8::HandleScope scope(isolate);
14531527

1528+
if (isExecutionDeadlineReached(isolate)) {
1529+
return;
1530+
}
1531+
14541532
// get the connection
14551533
V8ClientConnection* v8connection =
14561534
TRI_UnwrapClass<V8ClientConnection>(args.Holder(), WRAP_TYPE_CONNECTION, TRI_IGETC);
@@ -1475,6 +1553,10 @@ static void ClientConnection_setDatabaseName(v8::FunctionCallbackInfo<v8::Value>
14751553
TRI_V8_TRY_CATCH_BEGIN(isolate);
14761554
v8::HandleScope scope(isolate);
14771555

1556+
if (isExecutionDeadlineReached(isolate)) {
1557+
return;
1558+
}
1559+
14781560
// get the connection
14791561
V8ClientConnection* v8connection =
14801562
TRI_UnwrapClass<V8ClientConnection>(args.Holder(), WRAP_TYPE_CONNECTION, TRI_IGETC);
@@ -1590,7 +1672,7 @@ v8::Local<v8::Value> V8ClientConnection::requestData(
15901672
} else {
15911673
req->header.contentType(fu::ContentType::Custom);
15921674
}
1593-
1675+
15941676
} else if (boost::iequals(StaticStrings::Accept, pair.first)) {
15951677
if (pair.second == StaticStrings::MimeTypeVPack) {
15961678
req->header.acceptType(fu::ContentType::VPack);
@@ -1667,7 +1749,9 @@ v8::Local<v8::Value> V8ClientConnection::requestData(
16671749
req->header.acceptType(fu::ContentType::VPack);
16681750
}
16691751
}
1670-
req->timeout(std::chrono::duration_cast<std::chrono::milliseconds>(_requestTimeout));
1752+
req->timeout(
1753+
correctTimeoutToExecutionDeadline(
1754+
std::chrono::duration_cast<std::chrono::milliseconds>(_requestTimeout)));
16711755

16721756
std::shared_ptr<fu::Connection> connection = acquireConnection();
16731757
if (!connection || connection->state() == fu::Connection::State::Failed) {
@@ -1683,7 +1767,7 @@ v8::Local<v8::Value> V8ClientConnection::requestData(
16831767
} catch (fu::Error const& ec) {
16841768
rc = ec;
16851769
}
1686-
1770+
16871771
if (rc == fu::Error::ConnectionClosed && retry) {
16881772
retry = false;
16891773
goto again;
@@ -1696,7 +1780,7 @@ v8::Local<v8::Value> V8ClientConnection::requestDataRaw(
16961780
v8::Isolate* isolate, fu::RestVerb method, arangodb::velocypack::StringRef const& location,
16971781
v8::Local<v8::Value> const& body,
16981782
std::unordered_map<std::string, std::string> const& headerFields) {
1699-
1783+
17001784
bool retry = true;
17011785

17021786
again:
@@ -1749,7 +1833,9 @@ v8::Local<v8::Value> V8ClientConnection::requestDataRaw(
17491833
if (req->header.acceptType() == fu::ContentType::Unset) {
17501834
req->header.acceptType(fu::ContentType::VPack);
17511835
}
1752-
req->timeout(std::chrono::duration_cast<std::chrono::milliseconds>(_requestTimeout));
1836+
req->timeout(
1837+
correctTimeoutToExecutionDeadline(
1838+
std::chrono::duration_cast<std::chrono::milliseconds>(_requestTimeout)));
17531839

17541840
std::shared_ptr<fu::Connection> connection = acquireConnection();
17551841
if (!connection || connection->state() == fu::Connection::State::Failed) {
@@ -1766,7 +1852,7 @@ v8::Local<v8::Value> V8ClientConnection::requestDataRaw(
17661852
_lastErrorMessage.assign(fu::to_string(e));
17671853
_lastHttpReturnCode = 503;
17681854
}
1769-
1855+
17701856
if (rc == fu::Error::ConnectionClosed && retry) {
17711857
retry = false;
17721858
goto again;
@@ -1939,7 +2025,7 @@ v8::Local<v8::Value> V8ClientConnection::handleResult(v8::Isolate* isolate,
19392025
VPackParser parser(builder);
19402026
try {
19412027
parser.parse(str, sb.size());
1942-
ret = TRI_VPackToV8(isolate, builder->slice(), parser.options, nullptr);
2028+
ret = TRI_VPackToV8(isolate, builder->slice(), parser.options, nullptr);
19432029
} catch (std::exception const& ex) {
19442030
std::string err("Error parsing the server JSON reply: ");
19452031
err += ex.what();

arangosh/Shell/V8ShellFeature.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#include "V8/v8-globals.h"
5555
#include "V8/v8-shell.h"
5656
#include "V8/v8-utils.h"
57+
#include "V8/v8-deadline.h"
5758
#include "V8/v8-vpack.h"
5859

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

11011102
TRI_InitV8Buffer(_isolate);
11021103
TRI_InitV8Utils(_isolate, context, _startupDirectory, modules);
1104+
TRI_InitV8Deadline(_isolate);
11031105
TRI_InitV8Shell(_isolate);
11041106

11051107
// pager functions (overwrite existing SYS_OUTPUT from InitV8Utils)

js/client/bootstrap/modules/internal.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@
4646
delete global.SYS_ARANGO;
4747
}
4848

49+
// //////////////////////////////////////////////////////////////////////////////
50+
// / @brief set deadline for external requests & sleeps
51+
// //////////////////////////////////////////////////////////////////////////////
52+
53+
if (global.SYS_COMMUNICATE_SLEEP_DEADLINE) {
54+
exports.SetGlobalExecutionDeadlineTo = global.SYS_COMMUNICATE_SLEEP_DEADLINE;
55+
delete global.SYS_COMMUNICATE_SLEEP_DEADLINE;
56+
}
57+
4958
// //////////////////////////////////////////////////////////////////////////////
5059
// / @brief write-ahead log functionality
5160
// //////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)
0