forked from vesoft-inc/nebula
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExecutor.cpp
632 lines (604 loc) · 22.6 KB
/
Executor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
/* Copyright (c) 2020 vesoft inc. All rights reserved.
*
* This source code is licensed under Apache 2.0 License.
*/
#include "graph/executor/Executor.h"
#include <folly/String.h>
#include <folly/executors/InlineExecutor.h>
#include <atomic>
#include "common/base/ObjectPool.h"
#include "common/memory/MemoryUtils.h"
#include "common/time/ScopedTimer.h"
#include "graph/context/ExecutionContext.h"
#include "graph/context/QueryContext.h"
#include "graph/executor/ExecutionError.h"
#include "graph/executor/admin/AddHostsExecutor.h"
#include "graph/executor/admin/ChangePasswordExecutor.h"
#include "graph/executor/admin/CharsetExecutor.h"
#include "graph/executor/admin/ConfigExecutor.h"
#include "graph/executor/admin/CreateUserExecutor.h"
#include "graph/executor/admin/DescribeUserExecutor.h"
#include "graph/executor/admin/DownloadExecutor.h"
#include "graph/executor/admin/DropHostsExecutor.h"
#include "graph/executor/admin/DropUserExecutor.h"
#include "graph/executor/admin/GrantRoleExecutor.h"
#include "graph/executor/admin/IngestExecutor.h"
#include "graph/executor/admin/KillQueryExecutor.h"
#include "graph/executor/admin/ListRolesExecutor.h"
#include "graph/executor/admin/ListUserRolesExecutor.h"
#include "graph/executor/admin/ListUsersExecutor.h"
#include "graph/executor/admin/ListenerExecutor.h"
#include "graph/executor/admin/PartExecutor.h"
#include "graph/executor/admin/RevokeRoleExecutor.h"
#include "graph/executor/admin/SessionExecutor.h"
#include "graph/executor/admin/ShowHostsExecutor.h"
#include "graph/executor/admin/ShowMetaLeaderExecutor.h"
#include "graph/executor/admin/ShowQueriesExecutor.h"
#include "graph/executor/admin/ShowStatsExecutor.h"
#include "graph/executor/admin/ShowTSClientsExecutor.h"
#include "graph/executor/admin/SignInTSServiceExecutor.h"
#include "graph/executor/admin/SignOutTSServiceExecutor.h"
#include "graph/executor/admin/SnapshotExecutor.h"
#include "graph/executor/admin/SpaceExecutor.h"
#include "graph/executor/admin/SubmitJobExecutor.h"
#include "graph/executor/admin/SwitchSpaceExecutor.h"
#include "graph/executor/admin/UpdateUserExecutor.h"
#include "graph/executor/admin/ZoneExecutor.h"
#include "graph/executor/algo/BFSShortestPathExecutor.h"
#include "graph/executor/algo/CartesianProductExecutor.h"
#include "graph/executor/algo/ConjunctPathExecutor.h"
#include "graph/executor/algo/ProduceAllPathsExecutor.h"
#include "graph/executor/algo/ProduceSemiShortestPathExecutor.h"
#include "graph/executor/algo/SubgraphExecutor.h"
#include "graph/executor/logic/LoopExecutor.h"
#include "graph/executor/logic/PassThroughExecutor.h"
#include "graph/executor/logic/SelectExecutor.h"
#include "graph/executor/logic/StartExecutor.h"
#include "graph/executor/maintain/EdgeExecutor.h"
#include "graph/executor/maintain/EdgeIndexExecutor.h"
#include "graph/executor/maintain/FTIndexExecutor.h"
#include "graph/executor/maintain/TagExecutor.h"
#include "graph/executor/maintain/TagIndexExecutor.h"
#include "graph/executor/mutate/DeleteExecutor.h"
#include "graph/executor/mutate/InsertExecutor.h"
#include "graph/executor/mutate/UpdateExecutor.h"
#include "graph/executor/query/AggregateExecutor.h"
#include "graph/executor/query/AppendVerticesExecutor.h"
#include "graph/executor/query/AssignExecutor.h"
#include "graph/executor/query/DataCollectExecutor.h"
#include "graph/executor/query/DedupExecutor.h"
#include "graph/executor/query/FilterExecutor.h"
#include "graph/executor/query/GetEdgesExecutor.h"
#include "graph/executor/query/GetNeighborsExecutor.h"
#include "graph/executor/query/GetVerticesExecutor.h"
#include "graph/executor/query/IndexScanExecutor.h"
#include "graph/executor/query/InnerJoinExecutor.h"
#include "graph/executor/query/IntersectExecutor.h"
#include "graph/executor/query/LeftJoinExecutor.h"
#include "graph/executor/query/LimitExecutor.h"
#include "graph/executor/query/MinusExecutor.h"
#include "graph/executor/query/ProjectExecutor.h"
#include "graph/executor/query/SampleExecutor.h"
#include "graph/executor/query/ScanEdgesExecutor.h"
#include "graph/executor/query/ScanVerticesExecutor.h"
#include "graph/executor/query/SortExecutor.h"
#include "graph/executor/query/TopNExecutor.h"
#include "graph/executor/query/TraverseExecutor.h"
#include "graph/executor/query/UnionAllVersionVarExecutor.h"
#include "graph/executor/query/UnionExecutor.h"
#include "graph/executor/query/UnwindExecutor.h"
#include "graph/planner/plan/Admin.h"
#include "graph/planner/plan/Logic.h"
#include "graph/planner/plan/Maintain.h"
#include "graph/planner/plan/Mutate.h"
#include "graph/planner/plan/PlanNode.h"
#include "graph/planner/plan/Query.h"
#include "graph/service/GraphFlags.h"
#include "interface/gen-cpp2/graph_types.h"
using folly::stringPrintf;
DEFINE_bool(enable_lifetime_optimize, true, "Does enable the lifetime optimize.");
DECLARE_double(system_memory_high_watermark_ratio);
namespace nebula {
namespace graph {
// static
Executor *Executor::create(const PlanNode *node, QueryContext *qctx) {
std::unordered_map<int64_t, Executor *> visited;
return makeExecutor(node, qctx, &visited);
}
// static
Executor *Executor::makeExecutor(const PlanNode *node,
QueryContext *qctx,
std::unordered_map<int64_t, Executor *> *visited) {
DCHECK(qctx != nullptr);
DCHECK(node != nullptr);
auto iter = visited->find(node->id());
if (iter != visited->end()) {
return iter->second;
}
Executor *exec = makeExecutor(qctx, node);
if (node->kind() == PlanNode::Kind::kSelect) {
auto select = asNode<Select>(node);
auto thenBody = makeExecutor(select->then(), qctx, visited);
auto elseBody = makeExecutor(select->otherwise(), qctx, visited);
auto selectExecutor = static_cast<SelectExecutor *>(exec);
selectExecutor->setThenBody(thenBody);
selectExecutor->setElseBody(elseBody);
} else if (node->kind() == PlanNode::Kind::kLoop) {
auto loop = asNode<Loop>(node);
auto body = makeExecutor(loop->body(), qctx, visited);
auto loopExecutor = static_cast<LoopExecutor *>(exec);
loopExecutor->setLoopBody(body);
}
for (size_t i = 0; i < node->numDeps(); ++i) {
exec->dependsOn(makeExecutor(node->dep(i), qctx, visited));
}
visited->insert({node->id(), exec});
return exec;
}
// static
Executor *Executor::makeExecutor(QueryContext *qctx, const PlanNode *node) {
auto pool = qctx->objPool();
switch (node->kind()) {
case PlanNode::Kind::kPassThrough: {
return pool->add(new PassThroughExecutor(node, qctx));
}
case PlanNode::Kind::kAggregate: {
return pool->add(new AggregateExecutor(node, qctx));
}
case PlanNode::Kind::kSort: {
return pool->add(new SortExecutor(node, qctx));
}
case PlanNode::Kind::kTopN: {
return pool->add(new TopNExecutor(node, qctx));
}
case PlanNode::Kind::kFilter: {
return pool->add(new FilterExecutor(node, qctx));
}
case PlanNode::Kind::kGetEdges: {
return pool->add(new GetEdgesExecutor(node, qctx));
}
case PlanNode::Kind::kGetVertices: {
return pool->add(new GetVerticesExecutor(node, qctx));
}
case PlanNode::Kind::kScanEdges: {
return pool->add(new ScanEdgesExecutor(node, qctx));
}
case PlanNode::Kind::kScanVertices: {
return pool->add(new ScanVerticesExecutor(node, qctx));
}
case PlanNode::Kind::kGetNeighbors: {
return pool->add(new GetNeighborsExecutor(node, qctx));
}
case PlanNode::Kind::kLimit: {
return pool->add(new LimitExecutor(node, qctx));
}
case PlanNode::Kind::kSample: {
return pool->add(new SampleExecutor(node, qctx));
}
case PlanNode::Kind::kProject: {
return pool->add(new ProjectExecutor(node, qctx));
}
case PlanNode::Kind::kUnwind: {
return pool->add(new UnwindExecutor(node, qctx));
}
case PlanNode::Kind::kIndexScan:
case PlanNode::Kind::kEdgeIndexFullScan:
case PlanNode::Kind::kEdgeIndexPrefixScan:
case PlanNode::Kind::kEdgeIndexRangeScan:
case PlanNode::Kind::kTagIndexFullScan:
case PlanNode::Kind::kTagIndexPrefixScan:
case PlanNode::Kind::kTagIndexRangeScan: {
return pool->add(new IndexScanExecutor(node, qctx));
}
case PlanNode::Kind::kStart: {
return pool->add(new StartExecutor(node, qctx));
}
case PlanNode::Kind::kUnion: {
return pool->add(new UnionExecutor(node, qctx));
}
case PlanNode::Kind::kUnionAllVersionVar: {
return pool->add(new UnionAllVersionVarExecutor(node, qctx));
}
case PlanNode::Kind::kIntersect: {
return pool->add(new IntersectExecutor(node, qctx));
}
case PlanNode::Kind::kMinus: {
return pool->add(new MinusExecutor(node, qctx));
}
case PlanNode::Kind::kLoop: {
return pool->add(new LoopExecutor(node, qctx));
}
case PlanNode::Kind::kSelect: {
return pool->add(new SelectExecutor(node, qctx));
}
case PlanNode::Kind::kDedup: {
return pool->add(new DedupExecutor(node, qctx));
}
case PlanNode::Kind::kAssign: {
return pool->add(new AssignExecutor(node, qctx));
}
case PlanNode::Kind::kSwitchSpace: {
return pool->add(new SwitchSpaceExecutor(node, qctx));
}
case PlanNode::Kind::kCreateSpace: {
return pool->add(new CreateSpaceExecutor(node, qctx));
}
case PlanNode::Kind::kCreateSpaceAs: {
return pool->add(new CreateSpaceAsExecutor(node, qctx));
}
case PlanNode::Kind::kDescSpace: {
return pool->add(new DescSpaceExecutor(node, qctx));
}
case PlanNode::Kind::kShowSpaces: {
return pool->add(new ShowSpacesExecutor(node, qctx));
}
case PlanNode::Kind::kDropSpace: {
return pool->add(new DropSpaceExecutor(node, qctx));
}
case PlanNode::Kind::kShowCreateSpace: {
return pool->add(new ShowCreateSpaceExecutor(node, qctx));
}
case PlanNode::Kind::kCreateTag: {
return pool->add(new CreateTagExecutor(node, qctx));
}
case PlanNode::Kind::kDescTag: {
return pool->add(new DescTagExecutor(node, qctx));
}
case PlanNode::Kind::kAlterTag: {
return pool->add(new AlterTagExecutor(node, qctx));
}
case PlanNode::Kind::kCreateEdge: {
return pool->add(new CreateEdgeExecutor(node, qctx));
}
case PlanNode::Kind::kDescEdge: {
return pool->add(new DescEdgeExecutor(node, qctx));
}
case PlanNode::Kind::kAlterEdge: {
return pool->add(new AlterEdgeExecutor(node, qctx));
}
case PlanNode::Kind::kShowTags: {
return pool->add(new ShowTagsExecutor(node, qctx));
}
case PlanNode::Kind::kShowEdges: {
return pool->add(new ShowEdgesExecutor(node, qctx));
}
case PlanNode::Kind::kDropTag: {
return pool->add(new DropTagExecutor(node, qctx));
}
case PlanNode::Kind::kDropEdge: {
return pool->add(new DropEdgeExecutor(node, qctx));
}
case PlanNode::Kind::kShowCreateTag: {
return pool->add(new ShowCreateTagExecutor(node, qctx));
}
case PlanNode::Kind::kShowCreateEdge: {
return pool->add(new ShowCreateEdgeExecutor(node, qctx));
}
case PlanNode::Kind::kCreateTagIndex: {
return pool->add(new CreateTagIndexExecutor(node, qctx));
}
case PlanNode::Kind::kCreateEdgeIndex: {
return pool->add(new CreateEdgeIndexExecutor(node, qctx));
}
case PlanNode::Kind::kCreateFTIndex: {
return pool->add(new CreateFTIndexExecutor(node, qctx));
}
case PlanNode::Kind::kDropTagIndex: {
return pool->add(new DropTagIndexExecutor(node, qctx));
}
case PlanNode::Kind::kDropEdgeIndex: {
return pool->add(new DropEdgeIndexExecutor(node, qctx));
}
case PlanNode::Kind::kDropFTIndex: {
return pool->add(new DropFTIndexExecutor(node, qctx));
}
case PlanNode::Kind::kDescTagIndex: {
return pool->add(new DescTagIndexExecutor(node, qctx));
}
case PlanNode::Kind::kDescEdgeIndex: {
return pool->add(new DescEdgeIndexExecutor(node, qctx));
}
case PlanNode::Kind::kShowCreateTagIndex: {
return pool->add(new ShowCreateTagIndexExecutor(node, qctx));
}
case PlanNode::Kind::kShowCreateEdgeIndex: {
return pool->add(new ShowCreateEdgeIndexExecutor(node, qctx));
}
case PlanNode::Kind::kShowTagIndexes: {
return pool->add(new ShowTagIndexesExecutor(node, qctx));
}
case PlanNode::Kind::kShowEdgeIndexes: {
return pool->add(new ShowEdgeIndexesExecutor(node, qctx));
}
case PlanNode::Kind::kShowTagIndexStatus: {
return pool->add(new ShowTagIndexStatusExecutor(node, qctx));
}
case PlanNode::Kind::kShowEdgeIndexStatus: {
return pool->add(new ShowEdgeIndexStatusExecutor(node, qctx));
}
case PlanNode::Kind::kInsertVertices: {
return pool->add(new InsertVerticesExecutor(node, qctx));
}
case PlanNode::Kind::kInsertEdges: {
return pool->add(new InsertEdgesExecutor(node, qctx));
}
case PlanNode::Kind::kDataCollect: {
return pool->add(new DataCollectExecutor(node, qctx));
}
case PlanNode::Kind::kCreateSnapshot: {
return pool->add(new CreateSnapshotExecutor(node, qctx));
}
case PlanNode::Kind::kDropSnapshot: {
return pool->add(new DropSnapshotExecutor(node, qctx));
}
case PlanNode::Kind::kShowSnapshots: {
return pool->add(new ShowSnapshotsExecutor(node, qctx));
}
case PlanNode::Kind::kLeftJoin: {
return pool->add(new LeftJoinExecutor(node, qctx));
}
case PlanNode::Kind::kInnerJoin: {
return pool->add(new InnerJoinExecutor(node, qctx));
}
case PlanNode::Kind::kDeleteVertices: {
return pool->add(new DeleteVerticesExecutor(node, qctx));
}
case PlanNode::Kind::kDeleteTags: {
return pool->add(new DeleteTagsExecutor(node, qctx));
}
case PlanNode::Kind::kDeleteEdges: {
return pool->add(new DeleteEdgesExecutor(node, qctx));
}
case PlanNode::Kind::kUpdateVertex: {
return pool->add(new UpdateVertexExecutor(node, qctx));
}
case PlanNode::Kind::kUpdateEdge: {
return pool->add(new UpdateEdgeExecutor(node, qctx));
}
case PlanNode::Kind::kCreateUser: {
return pool->add(new CreateUserExecutor(node, qctx));
}
case PlanNode::Kind::kDropUser: {
return pool->add(new DropUserExecutor(node, qctx));
}
case PlanNode::Kind::kUpdateUser: {
return pool->add(new UpdateUserExecutor(node, qctx));
}
case PlanNode::Kind::kGrantRole: {
return pool->add(new GrantRoleExecutor(node, qctx));
}
case PlanNode::Kind::kRevokeRole: {
return pool->add(new RevokeRoleExecutor(node, qctx));
}
case PlanNode::Kind::kChangePassword: {
return pool->add(new ChangePasswordExecutor(node, qctx));
}
case PlanNode::Kind::kListUserRoles: {
return pool->add(new ListUserRolesExecutor(node, qctx));
}
case PlanNode::Kind::kListUsers: {
return pool->add(new ListUsersExecutor(node, qctx));
}
case PlanNode::Kind::kListRoles: {
return pool->add(new ListRolesExecutor(node, qctx));
}
case PlanNode::Kind::kDescribeUser: {
return pool->add(new DescribeUserExecutor(node, qctx));
}
case PlanNode::Kind::kShowConfigs: {
return pool->add(new ShowConfigsExecutor(node, qctx));
}
case PlanNode::Kind::kSetConfig: {
return pool->add(new SetConfigExecutor(node, qctx));
}
case PlanNode::Kind::kGetConfig: {
return pool->add(new GetConfigExecutor(node, qctx));
}
case PlanNode::Kind::kSubmitJob: {
return pool->add(new SubmitJobExecutor(node, qctx));
}
case PlanNode::Kind::kShowHosts: {
return pool->add(new ShowHostsExecutor(node, qctx));
}
case PlanNode::Kind::kShowMetaLeader: {
return pool->add(new ShowMetaLeaderExecutor(node, qctx));
}
case PlanNode::Kind::kShowParts: {
return pool->add(new ShowPartsExecutor(node, qctx));
}
case PlanNode::Kind::kShowCharset: {
return pool->add(new ShowCharsetExecutor(node, qctx));
}
case PlanNode::Kind::kShowCollation: {
return pool->add(new ShowCollationExecutor(node, qctx));
}
case PlanNode::Kind::kBFSShortest: {
return pool->add(new BFSShortestPathExecutor(node, qctx));
}
case PlanNode::Kind::kProduceSemiShortestPath: {
return pool->add(new ProduceSemiShortestPathExecutor(node, qctx));
}
case PlanNode::Kind::kConjunctPath: {
return pool->add(new ConjunctPathExecutor(node, qctx));
}
case PlanNode::Kind::kProduceAllPaths: {
return pool->add(new ProduceAllPathsExecutor(node, qctx));
}
case PlanNode::Kind::kCartesianProduct: {
return pool->add(new CartesianProductExecutor(node, qctx));
}
case PlanNode::Kind::kSubgraph: {
return pool->add(new SubgraphExecutor(node, qctx));
}
case PlanNode::Kind::kAddHosts: {
return pool->add(new AddHostsExecutor(node, qctx));
}
case PlanNode::Kind::kDropHosts: {
return pool->add(new DropHostsExecutor(node, qctx));
}
case PlanNode::Kind::kMergeZone: {
return pool->add(new MergeZoneExecutor(node, qctx));
}
case PlanNode::Kind::kRenameZone: {
return pool->add(new RenameZoneExecutor(node, qctx));
}
case PlanNode::Kind::kDropZone: {
return pool->add(new DropZoneExecutor(node, qctx));
}
case PlanNode::Kind::kSplitZone: {
return pool->add(new SplitZoneExecutor(node, qctx));
}
case PlanNode::Kind::kDescribeZone: {
return pool->add(new DescribeZoneExecutor(node, qctx));
}
case PlanNode::Kind::kAddHostsIntoZone: {
return pool->add(new AddHostsIntoZoneExecutor(node, qctx));
}
case PlanNode::Kind::kShowZones: {
return pool->add(new ListZonesExecutor(node, qctx));
}
case PlanNode::Kind::kAddListener: {
return pool->add(new AddListenerExecutor(node, qctx));
}
case PlanNode::Kind::kRemoveListener: {
return pool->add(new RemoveListenerExecutor(node, qctx));
}
case PlanNode::Kind::kShowListener: {
return pool->add(new ShowListenerExecutor(node, qctx));
}
case PlanNode::Kind::kShowStats: {
return pool->add(new ShowStatsExecutor(node, qctx));
}
case PlanNode::Kind::kShowTSClients: {
return pool->add(new ShowTSClientsExecutor(node, qctx));
}
case PlanNode::Kind::kShowFTIndexes: {
return pool->add(new ShowFTIndexesExecutor(node, qctx));
}
case PlanNode::Kind::kSignInTSService: {
return pool->add(new SignInTSServiceExecutor(node, qctx));
}
case PlanNode::Kind::kSignOutTSService: {
return pool->add(new SignOutTSServiceExecutor(node, qctx));
}
case PlanNode::Kind::kDownload: {
return pool->add(new DownloadExecutor(node, qctx));
}
case PlanNode::Kind::kIngest: {
return pool->add(new IngestExecutor(node, qctx));
}
case PlanNode::Kind::kShowSessions: {
return pool->add(new ShowSessionsExecutor(node, qctx));
}
case PlanNode::Kind::kUpdateSession: {
return pool->add(new UpdateSessionExecutor(node, qctx));
}
case PlanNode::Kind::kShowQueries: {
return pool->add(new ShowQueriesExecutor(node, qctx));
}
case PlanNode::Kind::kKillQuery: {
return pool->add(new KillQueryExecutor(node, qctx));
}
case PlanNode::Kind::kTraverse: {
return pool->add(new TraverseExecutor(node, qctx));
}
case PlanNode::Kind::kAppendVertices: {
return pool->add(new AppendVerticesExecutor(node, qctx));
}
case PlanNode::Kind::kUnknown: {
LOG(FATAL) << "Unknown plan node kind " << static_cast<int32_t>(node->kind());
break;
}
}
return nullptr;
}
Executor::Executor(const std::string &name, const PlanNode *node, QueryContext *qctx)
: id_(DCHECK_NOTNULL(node)->id()),
name_(name),
node_(DCHECK_NOTNULL(node)),
qctx_(DCHECK_NOTNULL(qctx)),
ectx_(DCHECK_NOTNULL(qctx->ectx())) {
// Initialize the position in ExecutionContext for each executor before
// execution plan starting to run. This will avoid lock something for thread
// safety in real execution
if (!ectx_->exist(node->outputVar())) {
ectx_->initVar(node->outputVar());
}
}
Executor::~Executor() {}
Status Executor::open() {
if (qctx_->isKilled()) {
VLOG(1) << "Execution is being killed. session: " << qctx()->rctx()->session()->id()
<< "ep: " << qctx()->plan()->id() << "query: " << qctx()->rctx()->query();
return Status::Error("Execution had been killed");
}
NG_RETURN_IF_ERROR(checkMemoryWatermark());
numRows_ = 0;
execTime_ = 0;
totalDuration_.reset();
return Status::OK();
}
Status Executor::close() {
ProfilingStats stats;
stats.totalDurationInUs = totalDuration_.elapsedInUSec();
stats.rows = numRows_;
stats.execDurationInUs = execTime_;
if (!otherStats_.empty()) {
stats.otherStats =
std::make_unique<std::unordered_map<std::string, std::string>>(std::move(otherStats_));
}
qctx()->plan()->addProfileStats(node_->id(), std::move(stats));
return Status::OK();
}
Status Executor::checkMemoryWatermark() {
if (node_->isQueryNode() && MemoryUtils::kHitMemoryHighWatermark.load()) {
return Status::Error("Used memory hits the high watermark(%lf) of total system memory.",
FLAGS_system_memory_high_watermark_ratio);
}
return Status::OK();
}
folly::Future<Status> Executor::start(Status status) const {
return folly::makeFuture(std::move(status)).via(runner());
}
folly::Future<Status> Executor::error(Status status) const {
return folly::makeFuture<Status>(std::move(status)).via(runner());
}
void Executor::drop() {
for (const auto &inputVar : node()->inputVars()) {
if (inputVar != nullptr) {
// Make sure use the variable happened-before decrement count
if (inputVar->userCount.fetch_sub(1, std::memory_order_release) == 1) {
// Make sure drop happened-after count decrement
CHECK_EQ(inputVar->userCount.load(std::memory_order_acquire), 0);
ectx_->dropResult(inputVar->name);
VLOG(1) << node()->kind() << " Drop variable " << inputVar->name;
}
}
}
}
Status Executor::finish(Result &&result) {
if (!FLAGS_enable_lifetime_optimize ||
node()->outputVarPtr()->userCount.load(std::memory_order_relaxed) != 0) {
numRows_ = result.size();
result.checkMemory(node()->isQueryNode());
ectx_->setResult(node()->outputVar(), std::move(result));
} else {
VLOG(1) << "Drop variable " << node()->outputVar();
}
if (FLAGS_enable_lifetime_optimize) {
drop();
}
return Status::OK();
}
Status Executor::finish(Value &&value) {
return finish(ResultBuilder().value(std::move(value)).iter(Iterator::Kind::kDefault).build());
}
folly::Executor *Executor::runner() const {
if (!qctx() || !qctx()->rctx() || !qctx()->rctx()->runner()) {
// This is just for test
return &folly::InlineExecutor::instance();
}
return qctx()->rctx()->runner();
}
} // namespace graph
} // namespace nebula