zanmato1984 commented on code in PR #47392:
URL: https://github.com/apache/arrow/pull/47392#discussion_r2395963549


##########
cpp/src/arrow/acero/backpressure.h:
##########
@@ -0,0 +1,96 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you 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.
+
+#pragma once
+
+#include <mutex>
+
+#include "arrow/acero/options.h"
+
+namespace arrow::acero {
+
+// Generic backpressure controller for ExecNode
+class ARROW_ACERO_EXPORT BackpressureController : public BackpressureControl {
+ public:
+  BackpressureController(ExecNode* node, ExecNode* output,
+                         std::atomic<int32_t>& backpressure_counter);
+
+  void Pause() override;
+  void Resume() override;
+
+ private:
+  ExecNode* node_;
+  ExecNode* output_;
+  std::atomic<int32_t>& backpressure_counter_;
+};
+
+template <typename T>
+class BackpressureControlWrapper : public BackpressureControl {
+ public:
+  explicit BackpressureControlWrapper(T* obj) : obj_(obj) {}
+
+  void Pause() override { obj_->Pause(); }
+  void Resume() override { obj_->Resume(); }
+
+ private:
+  T* obj_;
+};
+
+// Provides infrastructure of combining multiple backpressure sources and 
propagate the
+// result into BackpressureControl There are two logic scheme of backpressure:
+// 1. Default pause_on_any=true - pause on any source is propagated - OR logic
+// 2. pause_on_any=false - pause is propagated only when all sources are 
paused - AND
+// logic
+class ARROW_ACERO_EXPORT BackpressureCombiner {

Review Comment:
   I think I get the idea of bridging multiple backpressure sources and 
propagating the backpressure between, in an implicit and automatic manner. But 
before we introduce this as a public API, I'd like to see a more concrete use 
case, e.g. a plan tree (possibly a hypothetical one with some new node types 
you are about to add in the future), to showcase some unclear things such as:
   1. Who owns the life span of the combiner and the combiner sources?
   2. When and where to establish the bridge between a combiner source and a 
particular combiner?
   3. When and where to trigger a combiner source's `Pause()` or `Resume()`?
   
   Current `BackpressureCombiner` exposes too much implementation detail as a 
public interface, e.g. we even know it uses `std::mutex` to manage 
synchronization. But this is another topic that we may talk about later.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to