Skip to content

[C++][Acero] Asofjoin respect PauseProducing from downstream. #46140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 51 additions & 2 deletions cpp/src/arrow/acero/asof_join_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,7 @@ class AsofJoinNode : public ExecNode {
EndFromProcessThread();
return;
}
backpressure_future_.Wait();
if (!Process()) {
return;
}
Expand Down Expand Up @@ -1519,8 +1520,51 @@ class AsofJoinNode : public ExecNode {
return Status::OK();
}

void PauseProducing(ExecNode* output, int32_t counter) override {}
void ResumeProducing(ExecNode* output, int32_t counter) override {}
void PauseProducing(ExecNode* output, int32_t counter) override {
std::lock_guard<std::mutex> lg(backpressure_mutex_);
if (counter <= last_backpressure_counter_) {
return;
}
last_backpressure_counter_ = counter;
if (!backpressure_future_.is_finished()) {
// Could happen if we get something like Pause(1) Pause(3) Resume(2)
return;
}
backpressure_future_ = Future<>::Make();
}
void ResumeProducing(ExecNode* output, int32_t counter) override {
Future<> to_finish;
{
std::lock_guard<std::mutex> lg(backpressure_mutex_);
if (counter <= last_backpressure_counter_) {
return;
}
last_backpressure_counter_ = counter;
if (backpressure_future_.is_finished()) {
return;
}
to_finish = backpressure_future_;
backpressure_future_ = Future<>::MakeFinished();
}
to_finish.MarkFinished();
}

Status StopProducing() override {
// GH-35837: ensure node is not paused
Future<> to_finish;
{
std::lock_guard<std::mutex> lg(backpressure_mutex_);
if (!backpressure_future_.is_finished()) {
to_finish = backpressure_future_;
backpressure_future_ = Future<>::MakeFinished();
}
}
if (to_finish.is_valid()) {
to_finish.MarkFinished();
}
// only then stop
return ExecNode::StopProducing();
}

Status StopProducingImpl() override {
#ifdef ARROW_ENABLE_THREADING
Expand Down Expand Up @@ -1548,6 +1592,11 @@ class AsofJoinNode : public ExecNode {
// Each input state corresponds to an input table
std::vector<std::unique_ptr<InputState>> state_;
std::mutex gate_;

std::mutex backpressure_mutex_;
std::atomic<int32_t> last_backpressure_counter_{0};
Future<> backpressure_future_ = Future<>::MakeFinished();

TolType tolerance_;
#ifndef NDEBUG
std::ostream* debug_os_;
Expand Down
Loading