You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "JerAguilon (via GitHub)" <gi...@apache.org> on 2023/09/23 02:02:46 UTC
[GitHub] [arrow] JerAguilon opened a new pull request, #37839: GH-37796: [C++][Acero] Fix race condition caused by straggling input.
JerAguilon opened a new pull request, #37839:
URL: https://github.com/apache/arrow/pull/37839
### Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
-->
### What changes are included in this PR?
While asofjoining some large parquet datasets with many row groups, I ran into a deadlock that I described here: https://github.com/apache/arrow/issues/37796. Copy pasting below for convenience:
1. The left hand side of the asofjoin completes, so `InputFinished` proceeds as [expected](https://github.com/apache/arrow/blob/2455bc07e09cd5341d1fabdb293afbd07682f0b2/cpp/src/arrow/acero/asof_join_node.cc#L1323). So far so good
2. The right hand table(s) of the join are a huge dataset scan. They're still streaming and can legally still call `AsofJoinNode::InputReceived` all they want ([doc ref](https://arrow.apache.org/docs/cpp/api/acero.html#_CPPv4N5arrow5acero8ExecNode13InputReceivedEP8ExecNode9ExecBatch))
3. Each input batch is blindly pushed to the `InputState`s, which in turn defer to `BackpressureHandler`s to decide whether to pause inputs. ([code pointer](https://github.com/apache/arrow/blob/2455bc07e09cd5341d1fabdb293afbd07682f0b2/cpp/src/arrow/acero/asof_join_node.cc#L1689))
4. If enough batches come in right after `EndFromProcessThread` is called, then we might exceed the [high_threshold](https://github.com/apache/arrow/blob/2455bc07e09cd5341d1fabdb293afbd07682f0b2/cpp/src/arrow/acero/asof_join_node.cc#L575) and tell the input node to pause via the [BackpressureController](https://github.com/apache/arrow/blob/2455bc07e09cd5341d1fabdb293afbd07682f0b2/cpp/src/arrow/acero/asof_join_node.cc#L540)
5. At this point, the process thread has stopped for the asofjoiner, so the right hand table(s) won't be dequeue'd, meaning `BackpressureController::Resume()` will never be called. This causes a [deadlock](https://arrow.apache.org/docs/cpp/api/acero.html#_CPPv4N5arrow5acero19BackpressureControl5PauseEv)
TLDR this is caused by a straggling input node being paused due to backpressure _after_ the process thread has ended. And since every `PauseInput` needs a corresponding `ResumeInput` to be exit gracefully, we deadlock.
Turns out this is fairly easy to reproduce with small tables, if you make a slow input node composed of 1-row record batches with a synthetic delay. My solution is to:
1. Create a `ForceShutdown` hook that puts the input nodes in a resumed state, and for good measure we call `StopProducing`
2. For good measure, if nodes come after the process thread exits, we short circuit and return OK. This is because `InputReceived` can be called an arbitrary number of times after `StopProducing`, so it makes sense to not enqueue useless batches.
<!--
There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
-->
### Are these changes tested?
Yes, I added a delay to the batches of one of the already-existing asofjoin backpressure tests. Checkout out `main`, we get a timeout failure. With my changes, it passes.
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
3. Serve as another way to document the expected behavior of the code
### Are there any user-facing changes?
No
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] JerAguilon commented on a diff in pull request #37839: GH-37796: [C++][Acero] Fix race condition caused by straggling input in the as-of-join node
Posted by "JerAguilon (via GitHub)" <gi...@apache.org>.
JerAguilon commented on code in PR #37839:
URL: https://github.com/apache/arrow/pull/37839#discussion_r1336515512
##########
cpp/src/arrow/acero/asof_join_node.cc:
##########
@@ -579,7 +581,16 @@ class BackpressureHandler {
}
}
+ Status ForceShutdown() {
+ // It may be unintuitive to call Resume() here, but this is to avoid a deadlock.
+ // Since acero's executor won't terminate if any one node is paused, we need to
+ // force resume the node before stopping production.
+ backpressure_control_->Resume();
+ return input_->StopProducing();
Review Comment:
Yep.
As an aside, I feel like a more invasive change could fix this issue in the general case. If a node (in this example asof join) has:
* Called `output->InputFinished()` AND
* Called `output_->InputReceived` for however many record batches it advertised on `InputFinished`
We should be able to shut down execution, even if the node's inputs:
* are paused or
* not done streaming
* haven't called `InputFinished`
But I think this is a more invasive change to `exec_plan.h` and might have some hairy issues that I'm not thinking of.
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-37796: [C++][Acero] Fix race condition caused by straggling input in the as-of-join node [arrow]
Posted by "bkietz (via GitHub)" <gi...@apache.org>.
bkietz merged PR #37839:
URL: https://github.com/apache/arrow/pull/37839
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] westonpace commented on a diff in pull request #37839: GH-37796: [C++][Acero] Fix race condition caused by straggling input in the as-of-join node
Posted by "westonpace (via GitHub)" <gi...@apache.org>.
westonpace commented on code in PR #37839:
URL: https://github.com/apache/arrow/pull/37839#discussion_r1336267984
##########
cpp/src/arrow/acero/asof_join_node_test.cc:
##########
@@ -1474,9 +1477,16 @@ void TestBackpressure(BatchesMaker maker, int num_batches, int batch_size) {
std::vector<Declaration::Input> bp_decls;
for (size_t i = 0; i < source_configs.size(); i++) {
const auto& config = source_configs[i];
-
- src_decls.emplace_back("source",
- SourceNodeOptions(config.schema, GetGen(config.batches)));
+ if (config.is_delayed) {
Review Comment:
I assume this new option triggers the deadlock on the unfixed code?
##########
cpp/src/arrow/acero/asof_join_node.cc:
##########
@@ -579,7 +581,16 @@ class BackpressureHandler {
}
}
+ Status ForceShutdown() {
+ // It may be unintuitive to call Resume() here, but this is to avoid a deadlock.
+ // Since acero's executor won't terminate if any one node is paused, we need to
+ // force resume the node before stopping production.
+ backpressure_control_->Resume();
+ return input_->StopProducing();
Review Comment:
So if I understand correctly this means we will call `StopProducing` on all right hand side nodes once:
* The left hand side has finished
* The right hand side has caught up
If so, then I agree this is a valid thing to do.
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-37796: [C++][Acero] Fix race condition caused by straggling input in the as-of-join node [arrow]
Posted by "raulcd (via GitHub)" <gi...@apache.org>.
raulcd commented on PR #37839:
URL: https://github.com/apache/arrow/pull/37839#issuecomment-1890975872
Closes: https://github.com/apache/arrow/issues/37796
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-37796: [C++][Acero] Fix race condition caused by straggling input in the as-of-join node [arrow]
Posted by "bkietz (via GitHub)" <gi...@apache.org>.
bkietz commented on PR #37839:
URL: https://github.com/apache/arrow/pull/37839#issuecomment-1777189019
CI failures seem unrelated. I'll merge. Thanks for working on this!
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] JerAguilon commented on a diff in pull request #37839: GH-37796: [C++][Acero] Fix race condition caused by straggling input in the as-of-join node
Posted by "JerAguilon (via GitHub)" <gi...@apache.org>.
JerAguilon commented on code in PR #37839:
URL: https://github.com/apache/arrow/pull/37839#discussion_r1342077527
##########
cpp/src/arrow/acero/asof_join_node.cc:
##########
@@ -1679,6 +1704,15 @@ class AsofJoinNode : public ExecNode {
const Ordering& ordering() const override { return ordering_; }
Status InputReceived(ExecNode* input, ExecBatch batch) override {
+ // InputReceived may be called after execution was finished. Pushing it to the
+ // InputState may cause the BackPressureController to pause the input, causing a
+ // deadlock
Review Comment:
Yes, the `forceShutdown` is still necessary. there's nothing stopping this order of events:
1. We receive enough data to finish the as of join.
2. Right before we finish processing and shut down the worker thread, lots of batches come in from input A. Input A pauses
3. We shut down the thread, and input A can't be unpaused
But your comment change suggestions sound good to me
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] JerAguilon commented on pull request #37839: GH-37796: [C++][Acero] Fix race condition caused by straggling input in the as-of-join node
Posted by "JerAguilon (via GitHub)" <gi...@apache.org>.
JerAguilon commented on PR #37839:
URL: https://github.com/apache/arrow/pull/37839#issuecomment-1741964937
Clarifying comment for @bkietz added. Ready for more thoughts
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] icexelloss commented on pull request #37839: GH-37796: [C++][Acero] Fix race condition caused by straggling input in the as-of-join node
Posted by "icexelloss (via GitHub)" <gi...@apache.org>.
icexelloss commented on PR #37839:
URL: https://github.com/apache/arrow/pull/37839#issuecomment-1737544540
This looks reasonable to me. Free feel to merge.
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] JerAguilon commented on a diff in pull request #37839: GH-37796: [C++][Acero] Fix race condition caused by straggling input in the as-of-join node
Posted by "JerAguilon (via GitHub)" <gi...@apache.org>.
JerAguilon commented on code in PR #37839:
URL: https://github.com/apache/arrow/pull/37839#discussion_r1335950532
##########
cpp/src/arrow/acero/asof_join_node.cc:
##########
@@ -19,6 +19,7 @@
#include <atomic>
#include <condition_variable>
+#include <iostream>
Review Comment:
Oops... Will remove
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-37796: [C++][Acero] Fix race condition caused by straggling input in the as-of-join node [arrow]
Posted by "JerAguilon (via GitHub)" <gi...@apache.org>.
JerAguilon commented on PR #37839:
URL: https://github.com/apache/arrow/pull/37839#issuecomment-1775816550
Sadly there are some unrelated failures: `TestS3FS.GetFileInfoGeneratorStress` and `arrow-threading-utility-test`
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] JerAguilon commented on a diff in pull request #37839: GH-37796: [C++][Acero] Fix race condition caused by straggling input in the as-of-join node
Posted by "JerAguilon (via GitHub)" <gi...@apache.org>.
JerAguilon commented on code in PR #37839:
URL: https://github.com/apache/arrow/pull/37839#discussion_r1342077527
##########
cpp/src/arrow/acero/asof_join_node.cc:
##########
@@ -1679,6 +1704,15 @@ class AsofJoinNode : public ExecNode {
const Ordering& ordering() const override { return ordering_; }
Status InputReceived(ExecNode* input, ExecBatch batch) override {
+ // InputReceived may be called after execution was finished. Pushing it to the
+ // InputState may cause the BackPressureController to pause the input, causing a
+ // deadlock
Review Comment:
Yes, the `forceShutdown` is still necessary. there's nothing stopping this order of events:
1. We receive enough data to finish the as of join.
2. Right before we finish processing and shut down the worker thread, lots of unneeded batches come in from input A. Input A pauses
3. We shut down the thread, and input A can't be unpaused
Put another way, `forceShutdown` keeps us from deadlocking when we ingest unneeded data before the worker thread exits. And this block keeps us from deadlocking when we ingest unneeded data after the worker thread exits.
But your comment change suggestions sound good to me
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-37796: [C++][Acero] Fix race condition caused by straggling input in the as-of-join node [arrow]
Posted by "bkietz (via GitHub)" <gi...@apache.org>.
bkietz commented on PR #37839:
URL: https://github.com/apache/arrow/pull/37839#issuecomment-1775184712
Could you rebase to pick up the fix https://github.com/apache/arrow/pull/37867 ? I think CI should be green after that
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] JerAguilon commented on a diff in pull request #37839: GH-37796: [C++][Acero] Fix race condition caused by straggling input in the as-of-join node
Posted by "JerAguilon (via GitHub)" <gi...@apache.org>.
JerAguilon commented on code in PR #37839:
URL: https://github.com/apache/arrow/pull/37839#discussion_r1342077527
##########
cpp/src/arrow/acero/asof_join_node.cc:
##########
@@ -1679,6 +1704,15 @@ class AsofJoinNode : public ExecNode {
const Ordering& ordering() const override { return ordering_; }
Status InputReceived(ExecNode* input, ExecBatch batch) override {
+ // InputReceived may be called after execution was finished. Pushing it to the
+ // InputState may cause the BackPressureController to pause the input, causing a
+ // deadlock
Review Comment:
Yes, the `forceShutdown` is still necessary. there's nothing stopping this order of events:
1. We receive enough data to finish the as of join.
2. Right before we finish processing and shut down the worker thread, lots of batches come in from input A. Input A pauses
3. We shut down the thread, and input A can't be unpaused
Put another way, `forceShutdown` keeps us from deadlocking when we ingest unneeded data before the worker thread exits. And this block keeps us from deadlocking when we ingest unneeded data after the worker thread exits.
But your comment change suggestions sound good to me
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-37796: [C++][Acero] Fix race condition caused by straggling input in the as-of-join node [arrow]
Posted by "conbench-apache-arrow[bot] (via GitHub)" <gi...@apache.org>.
conbench-apache-arrow[bot] commented on PR #37839:
URL: https://github.com/apache/arrow/pull/37839#issuecomment-1779216926
After merging your PR, Conbench analyzed the 6 benchmarking runs that have been run so far on merge-commit e3d6b9beac6924fd6914940eb74b248a5167f05b.
There were no benchmark performance regressions. 🎉
The [full Conbench report](https://github.com/apache/arrow/runs/18041629148) has more details. It also includes information about 1 possible false positive for unstable benchmarks that are known to sometimes produce them.
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] bkietz commented on a diff in pull request #37839: GH-37796: [C++][Acero] Fix race condition caused by straggling input in the as-of-join node
Posted by "bkietz (via GitHub)" <gi...@apache.org>.
bkietz commented on code in PR #37839:
URL: https://github.com/apache/arrow/pull/37839#discussion_r1339193790
##########
cpp/src/arrow/acero/asof_join_node.cc:
##########
@@ -1323,6 +1342,12 @@ class AsofJoinNode : public ExecNode {
if (st.ok()) {
st = output_->InputFinished(this, batches_produced_);
}
+ for (const auto& s : state_) {
+ auto shutdownResult = s->ForceShutdown();
+ if (!shutdownResult.ok()) {
+ st = shutdownResult;
+ }
Review Comment:
```suggestion
st &= s->ForceShutdown();
```
##########
cpp/src/arrow/acero/asof_join_node.cc:
##########
@@ -1679,6 +1704,15 @@ class AsofJoinNode : public ExecNode {
const Ordering& ordering() const override { return ordering_; }
Status InputReceived(ExecNode* input, ExecBatch batch) override {
+ // InputReceived may be called after execution was finished. Pushing it to the
+ // InputState may cause the BackPressureController to pause the input, causing a
+ // deadlock
Review Comment:
```suggestion
// InputReceived may be called after execution was finished. Pushing it to the
// InputState is unnecessary since we're done (and anyway may cause the
// BackPressureController to pause the input, causing a deadlock), so drop it.
```
Do we still deadlock *with* this short circuit but *without* ForceShutdown etc?
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-37796: [C++][Acero] Fix race condition caused by straggling input in the as-of-join node [arrow]
Posted by "JerAguilon (via GitHub)" <gi...@apache.org>.
JerAguilon commented on PR #37839:
URL: https://github.com/apache/arrow/pull/37839#issuecomment-1773332408
Forgive the ignorance - first time making a PR on arrow. There's no further action needed from me to merge, correct?
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] JerAguilon commented on a diff in pull request #37839: GH-37796: [C++][Acero] Fix race condition caused by straggling input in the as-of-join node
Posted by "JerAguilon (via GitHub)" <gi...@apache.org>.
JerAguilon commented on code in PR #37839:
URL: https://github.com/apache/arrow/pull/37839#discussion_r1335950532
##########
cpp/src/arrow/acero/asof_join_node.cc:
##########
@@ -19,6 +19,7 @@
#include <atomic>
#include <condition_variable>
+#include <iostream>
Review Comment:
Will remove
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] JerAguilon commented on a diff in pull request #37839: GH-37796: [C++][Acero] Fix race condition caused by straggling input in the as-of-join node
Posted by "JerAguilon (via GitHub)" <gi...@apache.org>.
JerAguilon commented on code in PR #37839:
URL: https://github.com/apache/arrow/pull/37839#discussion_r1336513709
##########
cpp/src/arrow/acero/asof_join_node_test.cc:
##########
@@ -1474,9 +1477,16 @@ void TestBackpressure(BatchesMaker maker, int num_batches, int batch_size) {
std::vector<Declaration::Input> bp_decls;
for (size_t i = 0; i < source_configs.size(); i++) {
const auto& config = source_configs[i];
-
- src_decls.emplace_back("source",
- SourceNodeOptions(config.schema, GetGen(config.batches)));
+ if (config.is_delayed) {
Review Comment:
Correct
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] JerAguilon commented on a diff in pull request #37839: GH-37796: [C++][Acero] Fix race condition caused by straggling input in the as-of-join node
Posted by "JerAguilon (via GitHub)" <gi...@apache.org>.
JerAguilon commented on code in PR #37839:
URL: https://github.com/apache/arrow/pull/37839#discussion_r1334905168
##########
cpp/src/arrow/acero/asof_join_node.cc:
##########
@@ -579,7 +581,16 @@ class BackpressureHandler {
}
}
+ Status ForceShutdown() {
+ // It may be unintuitive to call Resume() here, but this is to avoid a deadlock.
+ // Since acero's executor won't terminate if any one node is paused, we need to
+ // force resume the node before stopping production.
+ backpressure_control_->Resume();
Review Comment:
Perhaps one thing to clarify is whether `ResumeInput` behaves idempotently? I.e., is it OK to always call resume, even though only some inputs hit this `PauseInput` race condition?
My perusal of `source_node.cc` tells me this is OK, but LMK if this is a poor assumption to make.
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org