-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathQLPlan.actor.h
More file actions
729 lines (642 loc) · 26.1 KB
/
QLPlan.actor.h
File metadata and controls
729 lines (642 loc) · 26.1 KB
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
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
/*
* QLPlan.h
*
* This source file is part of the FoundationDB open source project
*
* Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if defined(NO_INTELLISENSE) && !defined(_QL_PLAN_ACTOR_G_H_)
#define _QL_PLAN_ACTOR_G_H_
#include "QLPlan.actor.g.h"
#elif !defined(_QL_PLAN_ACTOR_H_)
#define _QL_PLAN_ACTOR_H_
#pragma once
#include "MetadataManager.h"
#include "QLContext.h"
#include "QLOperations.h"
#include "QLPredicate.h"
#include "QLProjection.actor.h"
/**
* Represents a plan running in a particular transaction(al try) and its bounds in the keyspace
* of each scan.
*/
struct PlanCheckpoint : ReferenceCounted<PlanCheckpoint>, FastAllocated<PlanCheckpoint> {
/**
* Interface for retry loop
*/
PlanCheckpoint(); // Unbounded
/**
* Cancels all outstanding operations, and returns a new PlanCheckpoint bounded to the remainder of
* this plan's original bounds. Must not be called with any actor in the plan on the C++ call stack
* (see implementation comment for details).
*/
Reference<PlanCheckpoint> stopAndCheckpoint();
/**
* Cancels any outstanding operations but doesn't change the bounds of this.
*/
void stop();
/**
* Interface for operations.
* addOperation and addScan must be called in a topological sort order (inputs before outputs).
*/
void addOperation(Future<Void> actors, PromiseStream<Reference<ScanReturnedContext>> output);
int addScan();
FDB::KeyRange getBounds(int whichScan);
bool splitBoundWanted();
/**
* Modified by operations at cancellation time if splitBooundWanted().
*/
FDB::Key& splitBound(int whichScan);
/**
* Returns a state variable which will be preserved at the beginning of the bounds of each
* checkpoint.
*/
int64_t& getIntState(int64_t defaultValue);
FlowLock* getDocumentFinishedLock() {
return &flowControlLock;
} // To be called in topsort order along with addOperation(), addScan(), etc.
// void newDocumentFinishedLock();
std::string toString();
private:
struct OpInfo {
Future<Void> actors;
PromiseStream<Reference<ScanReturnedContext>> output;
OpInfo(Future<Void> const& actors, PromiseStream<Reference<ScanReturnedContext>> const& output)
: actors(actors), output(output) {}
};
struct ScanInfo {
FDB::KeyRange bounds;
FDB::Key split;
ScanInfo() : bounds(FDB::KeyRangeRef(StringRef(), LiteralStringRef("\xff"))), split(LiteralStringRef("\xff")) {}
};
struct StateInfo {
int64_t begin;
int64_t split;
explicit StateInfo(int64_t x) : begin(x) {}
};
FlowLock flowControlLock;
std::vector<OpInfo> ops;
// Scans either added to this via addScan() or bounds inherited from previous stopAndCheckpoint().
std::vector<ScanInfo> scans;
std::vector<StateInfo> states;
// Number of scans added to this via addScan().
int scansAdded;
bool boundsWanted;
int stateAdded;
};
enum class PlanType : uint8_t {
TableScan,
Filter,
IndexScan,
PrimaryKeyLookup,
Union,
Empty,
NonIsolated,
Projection,
Skip,
ProjectAndUpdate,
Update,
Insert,
IndexInsert,
Sort,
Retry,
BuildIndex,
UpdateIndexStatus,
FlushChanges,
FindAndModify
};
/**
* Plan represents a (sub)plan which outputs a stream of documents.
*
* Plan::execute() generates actual actors to evaluate the plan, while other Plan methods like Plan::push_down()
* participate in planning and optimization. So this interface and its implementations straddle the planner and
* execution engine.
*/
struct Plan {
virtual void addref() = 0;
virtual void delref() = 0;
virtual ~Plan() = default;
virtual bson::BSONObj describe() = 0;
virtual PlanType getType() = 0;
virtual bool hasScanOfType(PlanType type) { return getType() == type; }
/**
* Executes the plan within the given checkpoint's bounds and with the given transaction, and return a stream of
* resulting documents. The caller must call checkpoint->getDocumentFinishedLock() before calling execute()
* and must release the lock for each document which it receives to allow the plan to continue executing.
*
* Implementations of execute() have a complex contract with respect to their interaction with the checkpoint to
* implement flow control and non-isolated scans. See the comment at the top of QLPlan.cpp for a detailed contract
* and the implementation comment of PlanCheckpoint::stopAndCheckpoint for an understanding of the checkpoint
* bounds mechanism.
*/
virtual FutureStream<Reference<ScanReturnedContext>> execute(PlanCheckpoint* checkpoint,
Reference<DocTransaction> tr) = 0;
/**
* Return a plan equivalent to, but more efficient than, FilterPlan(this, query), or Optional() if no such plan can
* be found.
*/
virtual Optional<Reference<Plan>> push_down(Reference<UnboundCollectionContext> cx, Reference<IPredicate> query) {
return Optional<Reference<Plan>>();
}
virtual bool empty() { return false; }
virtual bool wasMetadataChangeOkay(Reference<UnboundCollectionContext> cx) { return false; }
};
template <class PlanType>
struct ConcretePlan : Plan, ReferenceCounted<PlanType>, FastAllocated<PlanType> {
void addref() override { ReferenceCounted<PlanType>::addref(); }
void delref() override { ReferenceCounted<PlanType>::delref(); }
};
struct TableScanPlan : ConcretePlan<TableScanPlan> {
explicit TableScanPlan(Reference<UnboundCollectionContext> cx) : cx(cx) {}
bson::BSONObj describe() override {
return BSON("type"
<< "table scan");
}
FutureStream<Reference<ScanReturnedContext>> execute(PlanCheckpoint* checkpoint,
Reference<DocTransaction> tr) override;
PlanType getType() override { return PlanType::TableScan; }
Optional<Reference<Plan>> push_down(Reference<UnboundCollectionContext> cx, Reference<IPredicate> query) override;
bool wasMetadataChangeOkay(Reference<UnboundCollectionContext> cx) override { return true; }
private:
Reference<UnboundCollectionContext> cx;
};
struct FilterPlan : ConcretePlan<FilterPlan> {
bson::BSONObj describe() override {
return BSON(
// clang-format off
"type" << "filter" <<
"source_plan" << source->describe() <<
"filter" << filter->toString()
// clang-format on
);
}
FutureStream<Reference<ScanReturnedContext>> execute(PlanCheckpoint* checkpoint,
Reference<DocTransaction> tr) override;
PlanType getType() override { return PlanType::Filter; }
bool hasScanOfType(PlanType type) override { return source->hasScanOfType(type); }
static Reference<Plan> construct_filter_plan(Reference<UnboundCollectionContext> cx,
Reference<Plan> source,
Reference<IPredicate> filter);
static Reference<Plan> construct_filter_plan_no_pushdown(Reference<UnboundCollectionContext> cx,
Reference<Plan> source,
Reference<IPredicate> filter) {
return Reference<Plan>(new FilterPlan(cx, source, filter));
}
bool wasMetadataChangeOkay(Reference<UnboundCollectionContext> cx) override {
return source->wasMetadataChangeOkay(cx);
}
Optional<Reference<Plan>> push_down(Reference<UnboundCollectionContext> cx, Reference<IPredicate> query) override;
private:
Reference<Plan> source;
Reference<IPredicate> filter;
Reference<UnboundCollectionContext> cx;
FilterPlan(Reference<UnboundCollectionContext> cx, Reference<Plan> source, Reference<IPredicate> filter)
: cx(cx), source(source), filter(filter) {}
};
struct IndexScanPlan : ConcretePlan<IndexScanPlan> {
IndexScanPlan(Reference<UnboundCollectionContext> cx,
Reference<IndexInfo> index,
Optional<Key> begin,
Optional<Key> end,
std::vector<std::string> matchedPrefix)
: cx(cx), index(index), begin(begin), end(end), matchedPrefix(matchedPrefix) {}
bson::BSONObj describe() override {
// #17: Added decode_bytes and decode_key_part to update explain output with user readable keys
std::string bound_begin;
std::string bound_end;
bson::BSONObjBuilder bound;
size_t pos;
DataKey begin_key = DataKey::decode_bytes(begin.get());
DataKey end_key = DataKey::decode_bytes(end.get());
for (int i = 0; i < begin_key.size(); ++i) {
bound_begin = DataValue::decode_key_part(begin_key[i]).toString();
bound_end = DataValue::decode_key_part(end_key[i]).toString();
if ((DVTypeCode)end_key[i][0] == DVTypeCode::SPL_CHAR) {
pos = bound_end.find('-', 0);
if (pos != std::string::npos) {
bound_end.erase(pos, 1);
}
}
bound.append(matchedPrefix[i], BSON("begin" << bound_begin << "end" << bound_end));
}
return BSON(
// clang-format off
"type" << "index scan" <<
"index name" << index->indexName <<
"bounds" << bound.obj()
// clang-format on
);
}
FutureStream<Reference<ScanReturnedContext>> execute(PlanCheckpoint* checkpoint,
Reference<DocTransaction> tr) override;
PlanType getType() override { return PlanType::IndexScan; }
Optional<Reference<Plan>> push_down(Reference<UnboundCollectionContext> cx, Reference<IPredicate> query) override;
bool single_key() { return begin.present() && end.present() && begin.get() == end.get(); }
private:
Reference<UnboundCollectionContext> cx;
Reference<IndexInfo> index;
Optional<Key> begin;
Optional<Key> end;
// Matched index not necessarily the exact match. This plan could simply use prefix of index.
// For now, index direction is not honored by Doc Layer, probably SOMEDAY
std::vector<std::string> matchedPrefix;
};
struct PrimaryKeyLookupPlan : ConcretePlan<PrimaryKeyLookupPlan> {
PrimaryKeyLookupPlan(Reference<UnboundCollectionContext> cx, Optional<DataValue> begin, Optional<DataValue> end)
: cx(cx), begin(begin), end(end) {}
bson::BSONObj describe() override {
std::string bound_begin = begin.present() ? begin.get().toString() : "-inf";
std::string bound_end = end.present() ? end.get().toString() : "+inf";
return BSON(
// clang-format off
"type" << "PK lookup" <<
"bounds" << BSON("begin" << bound_begin << "end" << bound_end)
// clang-format on
);
}
FutureStream<Reference<ScanReturnedContext>> execute(PlanCheckpoint* checkpoint,
Reference<DocTransaction> tr) override;
PlanType getType() override { return PlanType::PrimaryKeyLookup; }
bool wasMetadataChangeOkay(Reference<UnboundCollectionContext> cx) override { return true; }
private:
Reference<UnboundCollectionContext> cx;
Optional<DataValue> begin;
Optional<DataValue> end;
};
struct UnionPlan : ConcretePlan<UnionPlan> {
UnionPlan(Reference<Plan> plan1, Reference<Plan> plan2) : plan1(plan1), plan2(plan2) {}
bson::BSONObj describe() override {
return BSON(
// clang-format off
"type" << "union" <<
"plans" << BSON_ARRAY(plan1->describe() << plan2->describe())
// clang-format on
);
}
FutureStream<Reference<ScanReturnedContext>> execute(PlanCheckpoint* checkpoint,
Reference<DocTransaction> tr) override;
PlanType getType() override { return PlanType::Union; }
bool hasScanOfType(PlanType type) override { return plan1->hasScanOfType(type) || plan2->hasScanOfType(type); }
private:
Reference<Plan> plan1, plan2;
};
struct EmptyPlan : ConcretePlan<EmptyPlan> {
bson::BSONObj describe() override {
return BSON("type"
<< "EMPTY");
}
FutureStream<Reference<ScanReturnedContext>> execute(PlanCheckpoint* checkpoint,
Reference<DocTransaction> tr) override {
PromiseStream<Reference<ScanReturnedContext>> p;
p.sendError(end_of_stream());
checkpoint->addOperation(Void(), p);
return p.getFuture();
}
PlanType getType() override { return PlanType::Empty; }
};
struct NonIsolatedPlan : ConcretePlan<NonIsolatedPlan> {
Reference<Plan> subPlan;
bool isReadOnly;
Reference<MetadataManager> mm;
NonIsolatedPlan(Reference<Plan> subPlan,
bool isReadOnly,
Reference<UnboundCollectionContext> cx,
Reference<FDB::Database> database,
Reference<MetadataManager> mm)
: subPlan(subPlan), isReadOnly(isReadOnly), cx(cx), database(database), mm(mm) {}
bson::BSONObj describe() override {
return BSON(
// clang-format off
"type" << "non-isolated" <<
"source_plan" << subPlan->describe()
// clang-format on
);
}
PlanType getType() override { return PlanType::NonIsolated; }
FutureStream<Reference<ScanReturnedContext>> execute(PlanCheckpoint* checkpoint,
Reference<DocTransaction> tr) override;
bool hasScanOfType(PlanType type) override { return subPlan->hasScanOfType(type); }
Reference<DocTransaction> newTransaction();
static Reference<DocTransaction> newTransaction(Reference<FDB::Database> database);
private:
Reference<UnboundCollectionContext> cx;
Reference<FDB::Database> database;
};
/**
* Since a RetryPlan may reset the transaction it uses an arbitrary number of times, responsibility
* for creating/opening collection directories must belong to the subPlan nested within.
*/
struct RetryPlan : ConcretePlan<RetryPlan> {
Reference<Plan> subPlan;
int64_t timeout;
int64_t retryLimit;
RetryPlan(Reference<Plan> subPlan, int64_t timeout, int64_t retryLimit, Reference<FDB::Database> database)
: subPlan(subPlan), timeout(timeout), retryLimit(retryLimit), database(database) {}
bson::BSONObj describe() override {
return BSON(
// clang-format off
"type" << "retry" <<
"source_plan" << subPlan->describe()
// clang-format on
);
}
PlanType getType() override { return PlanType::Retry; }
FutureStream<Reference<ScanReturnedContext>> execute(PlanCheckpoint* checkpoint,
Reference<DocTransaction> tr) override;
bool hasScanOfType(PlanType type) override { return subPlan->hasScanOfType(type); }
Reference<DocTransaction> newTransaction();
private:
Reference<FDB::Database> database;
};
struct ProjectionPlan : ConcretePlan<ProjectionPlan> {
Reference<Projection> projection;
Reference<Plan> subPlan;
Optional<bson::BSONObj> ordering;
ProjectionPlan(Reference<Projection> projection,
Reference<Plan> subPlan,
Optional<bson::BSONObj> ordering = Optional<bson::BSONObj>())
: projection(projection), subPlan(subPlan), ordering(ordering) {}
bson::BSONObj describe() override {
return BSON(
// clang-format off
"type" << "projection" <<
"projection" << projection->debugString() <<
"source_plan" << subPlan->describe()
// clang-format on
);
}
PlanType getType() override { return PlanType::Projection; }
FutureStream<Reference<ScanReturnedContext>> execute(PlanCheckpoint* checkpoint,
Reference<DocTransaction> tr) override;
bool hasScanOfType(PlanType type) override { return subPlan->hasScanOfType(type); }
bool wasMetadataChangeOkay(Reference<UnboundCollectionContext> cx) override {
return subPlan->wasMetadataChangeOkay(cx);
}
};
struct UpdatePlan : ConcretePlan<UpdatePlan> {
Reference<Plan> subPlan;
Reference<IUpdateOp> updateOp;
Reference<IInsertOp> upsertOp;
int64_t limit;
Reference<UnboundCollectionContext> cx;
UpdatePlan(Reference<Plan> subPlan,
Reference<IUpdateOp> updateOp,
Reference<IInsertOp> upsertOp,
int64_t limit,
Reference<UnboundCollectionContext> cx)
: subPlan(subPlan), updateOp(updateOp), upsertOp(upsertOp), limit(limit), cx(cx) {}
bson::BSONObj describe() override {
return BSON(
// clang-format off
"type" << "update" <<
"updateOp" << updateOp->describe() <<
"upsertOp" << (upsertOp ? upsertOp->describe() : "none") <<
"source_plan" << subPlan->describe()
// clang-format on
);
}
PlanType getType() override { return PlanType::Update; }
FutureStream<Reference<ScanReturnedContext>> execute(PlanCheckpoint* checkpoint,
Reference<DocTransaction> tr) override;
bool hasScanOfType(PlanType type) override { return subPlan->hasScanOfType(type); }
// RW plan needs to worry that directory might have changed
bool wasMetadataChangeOkay(Reference<UnboundCollectionContext> cx) override { return false; }
};
struct ProjectAndUpdatePlan : ConcretePlan<ProjectAndUpdatePlan> {
Reference<Plan> subPlan;
Reference<IUpdateOp> updateOp;
Reference<IInsertOp> upsertOp;
Reference<Projection> projection;
Optional<bson::BSONObj> ordering;
bool projectNew;
Reference<UnboundCollectionContext> cx;
ProjectAndUpdatePlan(Reference<Plan> subPlan,
Reference<IUpdateOp> updateOp,
Reference<IInsertOp> upsertOp,
Reference<Projection> projection,
Optional<bson::BSONObj> ordering,
bool projectNew,
Reference<UnboundCollectionContext> cx)
: subPlan(subPlan),
updateOp(updateOp),
upsertOp(upsertOp),
projection(projection),
projectNew(projectNew),
ordering(ordering),
cx(cx) {}
bson::BSONObj describe() override {
return BSON(
// clang-format off
"type" << "projectAndUpdate" <<
"projection" << projection->debugString() <<
"updateOp" << updateOp->describe() <<
"upsertOp" << (upsertOp ? upsertOp->describe() : "none") <<
"source_plan" << subPlan->describe()
// clang-format on
);
}
PlanType getType() override { return PlanType::ProjectAndUpdate; }
FutureStream<Reference<ScanReturnedContext>> execute(PlanCheckpoint* checkpoint,
Reference<DocTransaction> tr) override;
bool hasScanOfType(PlanType type) override { return subPlan->hasScanOfType(type); }
// RW plan needs to worry that directory might have changed
bool wasMetadataChangeOkay(Reference<UnboundCollectionContext> cx) override { return false; }
};
struct FindAndModifyPlan : ConcretePlan<FindAndModifyPlan> {
Reference<Plan> subPlan;
Reference<IUpdateOp> updateOp;
Reference<IInsertOp> upsertOp;
Reference<Projection> projection;
Optional<bson::BSONObj> ordering;
bool projectNew;
Reference<UnboundCollectionContext> cx;
Reference<FDB::Database> database;
Reference<MetadataManager> mm;
FindAndModifyPlan(Reference<Plan> subPlan,
Reference<IUpdateOp> updateOp,
Reference<IInsertOp> upsertOp,
Reference<Projection> projection,
Optional<bson::BSONObj> ordering,
bool projectNew,
Reference<UnboundCollectionContext> cx,
Reference<FDB::Database> database,
Reference<MetadataManager> mm)
: subPlan(subPlan),
updateOp(updateOp),
upsertOp(upsertOp),
projection(projection),
projectNew(projectNew),
ordering(ordering),
cx(cx),
database(database),
mm(mm) {}
bson::BSONObj describe() override {
return BSON(
// clang-format off
"type" << "findAndModify" <<
"projection" << projection->debugString() <<
"updateOp" << updateOp->describe() <<
"upsertOp" << (upsertOp ? upsertOp->describe() : "none") <<
"source_plan" << subPlan->describe()
// clang-format on
);
}
PlanType getType() override { return PlanType::FindAndModify; }
FutureStream<Reference<ScanReturnedContext>> execute(PlanCheckpoint* checkpoint,
Reference<DocTransaction> tr) override;
bool hasScanOfType(PlanType type) override { return subPlan->hasScanOfType(type); }
bool wasMetadataChangeOkay(Reference<UnboundCollectionContext> cx) override { return false; }
};
struct SkipPlan : ConcretePlan<SkipPlan> {
int64_t skip;
Reference<Plan> subPlan;
SkipPlan(int64_t skip, Reference<Plan> subPlan) : skip(skip), subPlan(subPlan) {}
bson::BSONObj describe() override {
return BSON(
// clang-format off
"type" << "skip" <<
"number" << (long long)skip <<
"source_plan" << subPlan->describe()
// clang-format on
);
}
PlanType getType() override { return PlanType::Skip; }
FutureStream<Reference<ScanReturnedContext>> execute(PlanCheckpoint* checkpoint,
Reference<DocTransaction> tr) override;
bool hasScanOfType(PlanType type) override { return subPlan->hasScanOfType(type); }
bool wasMetadataChangeOkay(Reference<UnboundCollectionContext> cx) override {
return subPlan->wasMetadataChangeOkay(cx);
}
};
struct InsertPlan : ConcretePlan<InsertPlan> {
InsertPlan(std::vector<Reference<IInsertOp>> docs, Reference<MetadataManager> mm, Namespace ns)
: docs(docs), mm(mm), ns(ns) {}
bson::BSONObj describe() override {
return BSON(
// clang-format off
"type" << "insert" <<
"numDocs" << (int)docs.size()
// clang-format on
);
}
PlanType getType() override { return PlanType::Insert; }
FutureStream<Reference<ScanReturnedContext>> execute(PlanCheckpoint* checkpoint,
Reference<DocTransaction> tr) override;
private:
std::vector<Reference<IInsertOp>> docs;
Reference<MetadataManager> mm;
Namespace ns;
};
struct SortPlan : ConcretePlan<SortPlan> {
Reference<Plan> subPlan;
bson::BSONObj orderObj; // FIXME: Belongs in sort key
SortPlan(Reference<Plan> subPlan, bson::BSONObj orderObj) : subPlan(subPlan), orderObj(orderObj) {}
bson::BSONObj describe() override {
return BSON(
// clang-format off
"type" << "sort" <<
"source_plan" << subPlan->describe()
// clang-format on
);
}
PlanType getType() override { return PlanType::Sort; }
bool hasScanOfType(PlanType type) override { return subPlan->hasScanOfType(type); }
FutureStream<Reference<ScanReturnedContext>> execute(PlanCheckpoint* checkpoint,
Reference<DocTransaction> tr) override;
};
struct IndexInsertPlan : ConcretePlan<IndexInsertPlan> {
Reference<IInsertOp> indexInsert;
bson::BSONObj indexObj;
Namespace ns;
Reference<MetadataManager> mm;
IndexInsertPlan(Reference<IInsertOp> indexInsert,
bson::BSONObj indexObj,
Namespace ns,
Reference<MetadataManager> mm)
: indexInsert(indexInsert), indexObj(indexObj), ns(ns), mm(mm) {}
bson::BSONObj describe() override {
return BSON("type"
<< "index insert");
}
PlanType getType() override { return PlanType::IndexInsert; }
FutureStream<Reference<ScanReturnedContext>> execute(PlanCheckpoint* checkpoint,
Reference<DocTransaction> tr) override;
};
struct BuildIndexPlan : ConcretePlan<BuildIndexPlan> {
Reference<Plan> scan;
Reference<IndexInfo> index;
std::string dbName;
Standalone<StringRef> encodedIndexId;
Reference<MetadataManager> mm;
BuildIndexPlan(Reference<Plan> scan,
Reference<IndexInfo> index,
std::string const& dbName,
Standalone<StringRef> encodedIndexId,
Reference<MetadataManager> mm)
: scan(scan), index(index), dbName(dbName), encodedIndexId(encodedIndexId), mm(mm) {}
bson::BSONObj describe() override {
return BSON("type"
<< "build index");
}
PlanType getType() override { return PlanType::BuildIndex; }
FutureStream<Reference<ScanReturnedContext>> execute(PlanCheckpoint* checkpoint,
Reference<DocTransaction> tr) override;
bool wasMetadataChangeOkay(Reference<UnboundCollectionContext> cx) override;
};
struct UpdateIndexStatusPlan : ConcretePlan<UpdateIndexStatusPlan> {
Namespace ns;
Standalone<StringRef> encodedIndexId;
Reference<MetadataManager> mm;
std::string newStatus;
UID buildId;
UpdateIndexStatusPlan(Namespace const& ns,
Standalone<StringRef> encodedIndexId,
Reference<MetadataManager> mm,
std::string newStatus,
UID buildId)
: ns(ns), encodedIndexId(encodedIndexId), mm(mm), newStatus(newStatus), buildId(buildId) {}
bson::BSONObj describe() override {
return BSON("type"
<< "update index status");
}
PlanType getType() override { return PlanType::UpdateIndexStatus; }
FutureStream<Reference<ScanReturnedContext>> execute(PlanCheckpoint* checkpoint,
Reference<DocTransaction> tr) override;
};
struct FlushChangesPlan : ConcretePlan<FlushChangesPlan> {
Reference<Plan> subPlan;
explicit FlushChangesPlan(Reference<Plan> subPlan) : subPlan(subPlan) {}
bson::BSONObj describe() override {
return BSON(
// clang-format off
"type" << "flush changes" <<
"source_plan" << subPlan->describe()
// clang-format on
);
}
PlanType getType() override { return PlanType::FlushChanges; }
bool hasScanOfType(PlanType type) override { return subPlan->hasScanOfType(type); }
FutureStream<Reference<ScanReturnedContext>> execute(PlanCheckpoint* checkpoint,
Reference<DocTransaction> tr) override;
};
// Like executeUntilCompletion(), but uses the transaction you gave it.
ACTOR Future<int64_t> executeUntilCompletionTransactionally(Reference<Plan> plan, Reference<DocTransaction> tr);
// Like executeUntilCompletionTransactionally(), but also returns the last thing returned by the plan (if any).
ACTOR Future<std::pair<int64_t, Reference<ScanReturnedContext>>> executeUntilCompletionAndReturnLastTransactionally(
Reference<Plan> plan,
Reference<DocTransaction> tr);
Reference<Plan> deletePlan(Reference<Plan> subPlan, Reference<UnboundCollectionContext> cx, int64_t limit);
Reference<Plan> flushChanges(Reference<Plan> subPlan);
#endif /* _QL_PLAN_ACTOR_H_ */