| 104 | util::SerialSequencingQueue::Processor { |
| 105 | public: |
| 106 | SinkNode(ExecPlan* plan, std::vector<ExecNode*> inputs, |
| 107 | AsyncGenerator<std::optional<ExecBatch>>* generator, |
| 108 | std::shared_ptr<Schema>* schema_out, BackpressureOptions backpressure, |
| 109 | BackpressureMonitor** backpressure_monitor_out, |
| 110 | std::optional<bool> sequence_output) |
| 111 | : ExecNode(plan, std::move(inputs), {"collected"}, {}), |
| 112 | TracedNode(this), |
| 113 | backpressure_queue_(backpressure.resume_if_below, backpressure.pause_if_above), |
| 114 | push_gen_(), |
| 115 | producer_(push_gen_.producer()), |
| 116 | node_destroyed_(std::make_shared<bool>(false)) { |
| 117 | if (backpressure_monitor_out) { |
| 118 | *backpressure_monitor_out = &backpressure_queue_; |
| 119 | } |
| 120 | auto node_destroyed_capture = node_destroyed_; |
| 121 | if (schema_out) { |
| 122 | *schema_out = inputs_[0]->output_schema(); |
| 123 | } |
| 124 | *generator = [this, node_destroyed_capture]() -> Future<std::optional<ExecBatch>> { |
| 125 | if (*node_destroyed_capture) { |
| 126 | return Status::Invalid( |
| 127 | "Attempt to consume data after the plan has been destroyed"); |
| 128 | } |
| 129 | return push_gen_().Then([this](const std::optional<ExecBatch>& batch) { |
| 130 | if (batch) { |
| 131 | RecordBackpressureBytesFreed(*batch); |
| 132 | } |
| 133 | return batch; |
| 134 | }); |
| 135 | }; |
| 136 | |
| 137 | bool explicit_sequencing = sequence_output.has_value() && *sequence_output; |
| 138 | bool sequencing_disabled = sequence_output.has_value() && !*sequence_output; |
| 139 | if (explicit_sequencing || |
| 140 | (!sequencing_disabled && !inputs_[0]->ordering().is_unordered())) { |
| 141 | sequencer_ = util::SerialSequencingQueue::Make(this); |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | ~SinkNode() override { *node_destroyed_ = true; } |
| 146 | |