8000 refactored cursor API · ezhangle/arangodb@80a99ab · GitHub
[go: up one dir, main page]

Skip to content

Commit 80a99ab

Browse files
committed
refactored cursor API
1 parent 3ddf23d commit 80a99ab

29 files changed

+1734
-1867
lines changed

UnitTests/HttpInterface/api-cursor-spec.rb

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
doc.headers['content-type'].should eq("application/json; charset=utf-8")
2626
doc.parsed_response['error'].should eq(true)
2727
doc.parsed_response['code'].should eq(400)
28-
doc.parsed_response['errorNum'].should eq(1502)
28+
doc.parsed_response['errorNum'].should eq(600)
2929
end
3030

3131
it "returns an error if collection is unknown" do
@@ -416,6 +416,34 @@
416416
doc.parsed_response['count'].should eq(5)
417417
doc.parsed_response['result'].length.should eq(1)
418418
end
419+
420+
it "creates a query that executes a v8 expression during query optimization" do
421+
cmd = api
422+
body = "{ \"query\" : \"RETURN CONCAT('foo', 'bar', 'baz')\" }"
423+
doc = ArangoDB.log_post("#{prefix}-create-v8", cmd, :body => body)
424+
425+
doc.code.should eq(201)
426+
doc.headers['content-type'].should eq("application/json; charset=utf-8")
427+
doc.parsed_response['error'].should eq(false)
428+
doc.parsed_response['code'].should eq(201)
429+
doc.parsed_response['id'].should be_nil
430+
doc.parsed_response['hasMore'].should eq(false)
431+
doc.parsed_response['result'].length.should eq(1)
432+
end
433+
6302 434+
it "creates a query that executes a v8 expression during query execution" do
435+
cmd = api
436+
body = "{ \"query\" : \"FOR u IN #{@cn} RETURN PASSTHRU(KEEP(u, '_key'))\" }"
437+
doc = ArangoDB.log_post("#{prefix}-create-v8", cmd, :body => body)
438+
439+
doc.code.should eq(201)
440+
doc.headers['content-type'].should eq("application/json; charset=utf-8")
441+
doc.parsed_response['error'].should eq(false)
442+
doc.parsed_response['code'].should eq(201)
443+
doc.parsed_response['id'].should be_nil
444+
doc.parsed_response['hasMore'].should eq(false)
445+
doc.parsed_response['result'].length.should eq(10)
446+
end
419447
end
420448

421449
################################################################################

arangod/Aql/ExecutionBlock.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,8 @@ bool IndexRangeBlock::initRanges () {
11731173

11741174
// must invalidate the expression now as we might be called from
11751175
// different threads
1176-
if (triagens::arango::ServerState::instance()->isRunningInCluster()) {
1176+
if (triagens::arango::ServerState::instance()->isRunningInCluster() ||
1177+
engine->getQuery()->willExitContext()) {
11771178
for (auto e : _allVariableBoundExpressions) {
11781179
e->invalidate();
11791180
}
@@ -2736,7 +2737,8 @@ void CalculationBlock::doEvaluation (AqlItemBlock* result) {
27362737
[&]() -> void {
27372738
// must invalidate the expression now as we might be called from
27382739
// different threads
2739-
if (triagens::arango::ServerState::instance()->isRunningInCluster()) {
2740+
if (triagens::arango::ServerState::instance()->isRunningInCluster() ||
2741+
_engine->getQuery()->willExitContext()) {
27402742
_expression->invalidate();
27412743
}
27422744
_engine->getQuery()->exitContext();

arangod/Aql/Query.cpp

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -523,11 +523,6 @@ QueryResult Query::prepare (QueryRegistry* registry) {
523523
parser->parse(false);
524524
// put in bind parameters
525525
parser->ast()->injectBindParameters(_bindParameters);
526-
527-
// optimize the ast
528-
enterState(AST_OPTIMIZATION);
529-
parser->ast()->validateAndOptimize();
530-
// std::cout << "AST: " << triagens::basics::JsonHelper::toString(parser->ast()->toJson(TRI_UNKNOWN_MEM_ZONE, false)) << "\n";
531526
}
532527

533528
// create the transaction object, but do not start it yet
@@ -544,8 +539,15 @@ QueryResult Query::prepare (QueryRegistry* registry) {
544539
return transactionError(res);
545540
}
546541

542+
// optimize the ast
543+
enterState(AST_OPTIMIZATION);
544+
545+
parser->ast()->validateAndOptimize();
546+
// std::cout << "AST: " << triagens::basics::JsonHelper::toString(parser->ast()->toJson(TRI_UNKNOWN_MEM_ZONE, false)) << "\n";
547+
547548
enterState(PLAN_INSTANCIATION);
548549
plan.reset(ExecutionPlan::instanciateFromAst(parser->ast()));
550+
549551
if (plan.get() == nullptr) {
550552
// oops
551553
return QueryResult(TRI_ERROR_INTERNAL, "failed to create query execution engine");
@@ -971,6 +973,8 @@ void Query::enterContext () {
971973
}
972974

973975
// register transaction and resolver in context
976+
TRI_ASSERT(_trx != nullptr);
977+
974978
ISOLATE;
975979
TRI_GET_GLOBALS();
976980
auto ctx = static_cast<triagens::arango::V8TransactionContext*>(v8g->_transactionContext);
@@ -1005,6 +1009,19 @@ void Query::exitContext () {
10051009
}
10061010
}
10071011

1012+
////////////////////////////////////////////////////////////////////////////////
1013+
/// @brief whether or not a V8 context will actually be exited
1014+
////////////////////////////////////////////////////////////////////////////////
1015+
1016+
bool Query::willExitContext () const {
1017+
if (! _contextOwnedByExterior) {
1018+
if (_context != nullptr) {
1019+
return true;
1020+
}
1021+
}
1022+
return false;
1023+
}
1024+
10081025
////////////////////////////////////////////////////////////////////////////////
10091026
/// @brief returns statistics for current query.
10101027
////////////////////////////////////////////////////////////////////////////////

arangod/Aql/Query.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,12 @@ namespace triagens {
442442

443443
void exitContext ();
444444

445+
////////////////////////////////////////////////////////////////////////////////
446+
/// @brief whether or not a V8 context will actually be exited
447+
////////////////////////////////////////////////////////////////////////////////
448+
449+
bool willExitContext () const;
450+
445451
////////////////////////////////////////////////////////////////////////////////
446452
/// @brief returns statistics for current query.
447453
////////////////////////////////////////////////////////////////////////////////

arangod/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ add_executable(
102102
Replication/InitialSyncer.cpp
103103
Replication/Syncer.cpp
104104
RestHandler/RestBatchHandler.cpp
105+
RestHandler/RestCursorHandler.cpp
105106
RestHandler/RestDocumentHandler.cpp
106107
RestHandler/RestEdgeHandler.cpp
107108
RestHandler/RestImportHandler.cpp
@@ -115,6 +116,8 @@ add_executable(
115116
RestServer/VocbaseContext.cpp
116117
RestServer/arangod.cpp
117118
SkipLists/skiplistIndex.cpp
119+
Utils/Cursor.cpp
120+
Utils/CursorRepository.cpp
118121
Utils/DocumentHelper.cpp
119122
Utils/StandaloneTransactionContext.cpp
120123
Utils/Transaction.cpp
@@ -146,7 +149,6 @@ add_executable(
146149
VocBase/datafile.cpp
147150
VocBase/document-collection.cpp
148151
VocBase/edge-collection.cpp
149-
VocBase/general-cursor.cpp
150152
VocBase/headers.cpp
151153
VocBase/index.cpp
152154
VocBase/key-generator.cpp

arangod/Makefile.files

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ arangod_libarangod_a_SOURCES = \
7575
arangod/Replication/InitialSyncer.cpp \
7676
arangod/Replication/Syncer.cpp \
7777
arangod/RestHandler/RestBatchHandler.cpp \
78+
arangod/RestHandler/RestCursorHandler.cpp \
7879
arangod/RestHandler/RestDocumentHandler.cpp \
7980
arangod/RestHandler/RestEdgeHandler.cpp \
8081
arangod/RestHandler/RestImportHandler.cpp \
@@ -88,6 +89,8 @@ arangod_libarangod_a_SOURCES = \
8889
arangod/RestServer/VocbaseContext.cpp \
8990
arangod/RestServer/arangod.cpp \
9091
arangod/SkipLists/skiplistIndex.cpp \
92+
arangod/Utils/Cursor.cpp \
93+
arangod/Utils/CursorRepository.cpp \
9194
arangod/Utils/DocumentHelper.cpp \
9295
arangod/Utils/StandaloneTransactionContext.cpp \
9396
arangod/Utils/Transaction.cpp \
@@ -119,7 +122,6 @@ arangod_libarangod_a_SOURCES = \
119122
arangod/VocBase/datafile.cpp \
120123
arangod/VocBase/document-collection.cpp \
121124
arangod/VocBase/edge-collection.cpp \
122-
arangod/VocBase/general-cursor.cpp \
123125
arangod/VocBase/headers.cpp \
124126
arangod/VocBase/index.cpp \
125127
arangod/VocBase/key-generator.cpp \

0 commit comments

Comments
 (0)
0