You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "zanmato1984 (via GitHub)" <gi...@apache.org> on 2024/05/10 05:53:39 UTC

[PR] Test to repro [arrow]

zanmato1984 opened a new pull request, #41614:
URL: https://github.com/apache/arrow/pull/41614

   <!--
   Thanks for opening a pull request!
   If this is your first pull request you can find detailed information on how 
   to contribute here:
     * [New Contributor's Guide](https://arrow.apache.org/docs/dev/developers/guide/step_by_step/pr_lifecycle.html#reviews-and-merge-of-the-pull-request)
     * [Contributing Overview](https://arrow.apache.org/docs/dev/developers/overview.html)
   
   
   If this is not a [minor PR](https://github.com/apache/arrow/blob/main/CONTRIBUTING.md#Minor-Fixes). Could you open an issue for this pull request on GitHub? https://github.com/apache/arrow/issues/new/choose
   
   Opening GitHub issues ahead of time contributes to the [Openness](http://theapacheway.com/open/#:~:text=Openness%20allows%20new%20users%20the,must%20happen%20in%20the%20open.) of the Apache Arrow project.
   
   Then could you also rename the pull request title in the following format?
   
       GH-${GITHUB_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}
   
   or
   
       MINOR: [${COMPONENT}] ${SUMMARY}
   
   In the case of PARQUET issues on JIRA the title also supports:
   
       PARQUET-${JIRA_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}
   
   -->
   
   ### 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?
   
   <!--
   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?
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
   -->
   
   ### Are there any user-facing changes?
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!--
   If there are any breaking changes to public APIs, please uncomment the line below and explain which changes are breaking.
   -->
   <!-- **This PR includes breaking changes to public APIs.** -->
   
   <!--
   Please uncomment the line below (and provide explanation) if the changes fix either (a) a security vulnerability, (b) a bug that caused incorrect or invalid data to be produced, or (c) a bug that causes a crash (even when the API contract is upheld). We use this to highlight fixes to issues that may affect users without their knowledge. For this reason, fixing bugs that cause errors don't count, since those are usually obvious.
   -->
   <!-- **This PR contains a "Critical Fix".** -->


-- 
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] Test to repro [arrow]

Posted by "zanmato1984 (via GitHub)" <gi...@apache.org>.
zanmato1984 commented on PR #41614:
URL: https://github.com/apache/arrow/pull/41614#issuecomment-2103919614

   Sorry, filed in the wrong repo.


-- 
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-41149: [C++][Acero] Fix asof join race [arrow]

Posted by "zanmato1984 (via GitHub)" <gi...@apache.org>.
zanmato1984 commented on code in PR #41614:
URL: https://github.com/apache/arrow/pull/41614#discussion_r1598735913


##########
cpp/src/arrow/acero/asof_join_node.cc:
##########
@@ -548,8 +548,10 @@ class InputState {
   // true when the queue is empty and, when memo may have future entries (the case of a
   // positive tolerance), when the memo is empty.
   // used when checking whether RHS is up to date with LHS.
-  bool CurrentEmpty() const {
-    return memo_.no_future_ ? Empty() : memo_.times_.empty() && Empty();
+  // NOTE: The emptiness must be decided by an atomic all to Empty() in caller, due to the

Review Comment:
   Changed to "single call". Thanks for suggesting the new naming.



-- 
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-41149: [C++][Acero] Fix asof join race [arrow]

Posted by "zanmato1984 (via GitHub)" <gi...@apache.org>.
zanmato1984 commented on PR #41614:
URL: https://github.com/apache/arrow/pull/41614#issuecomment-2104852236

   @ursabot please benchmark


-- 
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-41149: [C++][Acero] Fix asof join race [arrow]

Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou merged PR #41614:
URL: https://github.com/apache/arrow/pull/41614


-- 
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-41149: [C++][Acero] Fix asof join race [arrow]

Posted by "zanmato1984 (via GitHub)" <gi...@apache.org>.
zanmato1984 commented on code in PR #41614:
URL: https://github.com/apache/arrow/pull/41614#discussion_r1598735140


##########
cpp/src/arrow/acero/asof_join_node.cc:
##########
@@ -918,34 +922,39 @@ class CompositeTableBuilder {
 // guaranteeing this probability is below 1 in a billion. The fix is 128-bit hashing.
 // See ARROW-17653
 class AsofJoinNode : public ExecNode {
-  // Advances the RHS as far as possible to be up to date for the current LHS timestamp
-  Result<bool> UpdateRhs() {
+  // Advances the RHS as far as possible to be up to date for the current LHS timestamp.
+  // Returns a pair of booleans. The first is if any RHS has advanced. The second is if
+  // all RHS are up to date for LHS.
+  Result<std::pair<bool, bool>> UpdateRhsAndCheckUpToDateWithLhs() {

Review Comment:
   Addressed.



##########
cpp/src/arrow/acero/asof_join_node.cc:
##########
@@ -548,8 +548,10 @@ class InputState {
   // true when the queue is empty and, when memo may have future entries (the case of a
   // positive tolerance), when the memo is empty.
   // used when checking whether RHS is up to date with LHS.
-  bool CurrentEmpty() const {
-    return memo_.no_future_ ? Empty() : memo_.times_.empty() && Empty();
+  // NOTE: The emptiness must be decided by an atomic all to Empty() in caller, due to the
+  // potential race with Push(), see GH-41614.
+  bool CurrentEmpty(bool empty) const {
+    return memo_.no_future_ ? empty : memo_.times_.empty() && empty;

Review Comment:
   Addressed.



-- 
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-41149: [C++][Acero] Fix asof join race [arrow]

Posted by "zanmato1984 (via GitHub)" <gi...@apache.org>.
zanmato1984 commented on code in PR #41614:
URL: https://github.com/apache/arrow/pull/41614#discussion_r1598733725


##########
cpp/src/arrow/acero/asof_join_node_test.cc:
##########
@@ -1678,5 +1678,55 @@ TEST(AsofJoinTest, BackpressureWithBatchesGen) {
                           /*slow_r0=*/false);
 }
 
+TEST(AsofJoinTest, GH40675) {
+  auto left_batch = ExecBatchFromJSON(
+      {int64(), utf8()}, R"([[1, "a"], [1, "b"], [5, "a"], [6, "b"], [7, "f"]])");
+  auto right_batch = ExecBatchFromJSON(
+      {int64(), utf8(), float64()}, R"([[2, "a", 1.0], [9, "b", 3.0], [15, "g", 5.0]])");
+
+  Declaration left{
+      "exec_batch_source",
+      ExecBatchSourceNodeOptions(schema({field("colA", int64()), field("col2", utf8())}),
+                                 {std::move(left_batch)})};
+  Declaration right{
+      "exec_batch_source",
+      ExecBatchSourceNodeOptions(schema({field("colB", int64()), field("col3", utf8()),
+                                         field("colC", float64())}),
+                                 {std::move(right_batch)})};
+  AsofJoinNodeOptions asof_join_opts({{{"colA"}, {{"col2"}}}, {{"colB"}, {{"col3"}}}}, 1);
+  Declaration asof_join{
+      "asofjoin", {std::move(left), std::move(right)}, std::move(asof_join_opts)};
+
+  ASSERT_OK_AND_ASSIGN(auto result, DeclarationToExecBatches(std::move(asof_join)));
+
+  auto exp_batch = ExecBatchFromJSON(
+      {int64(), utf8(), float64()},
+      R"([[1, "a", 1.0], [1, "b", null], [5, "a", null], [6, "b", null], [7, "f", null]])");
+  AssertExecBatchesEqualIgnoringOrder(result.schema, {exp_batch}, result.batches);
+}
+
+TEST(AsofJoinTest, GH41149) {
+  auto left_batch = ExecBatchFromJSON({int64()}, R"([[1], [2], [3]])");

Review Comment:
   Addressed.



-- 
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-41149: [C++][Acero] Fix asof join race [arrow]

Posted by "ursabot (via GitHub)" <gi...@apache.org>.
ursabot commented on PR #41614:
URL: https://github.com/apache/arrow/pull/41614#issuecomment-2104852370

   Benchmark runs are scheduled for commit ade727e68488aad1f34ea635800b1b579c5fe17a. Watch https://buildkite.com/apache-arrow and https://conbench.ursa.dev for updates. A comment will be posted here when the runs are complete.


-- 
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-41149: [C++][Acero] Fix asof join race [arrow]

Posted by "westonpace (via GitHub)" <gi...@apache.org>.
westonpace commented on code in PR #41614:
URL: https://github.com/apache/arrow/pull/41614#discussion_r1598496752


##########
cpp/src/arrow/acero/asof_join_node.cc:
##########
@@ -548,8 +548,10 @@ class InputState {
   // true when the queue is empty and, when memo may have future entries (the case of a
   // positive tolerance), when the memo is empty.
   // used when checking whether RHS is up to date with LHS.
-  bool CurrentEmpty() const {
-    return memo_.no_future_ ? Empty() : memo_.times_.empty() && Empty();
+  // NOTE: The emptiness must be decided by an atomic all to Empty() in caller, due to the
+  // potential race with Push(), see GH-41614.
+  bool CurrentEmpty(bool empty) const {
+    return memo_.no_future_ ? empty : memo_.times_.empty() && empty;

Review Comment:
   Does the `memo_.times_.empty()` value need to be obtained in a single call as well?



##########
cpp/src/arrow/acero/asof_join_node.cc:
##########
@@ -548,8 +548,10 @@ class InputState {
   // true when the queue is empty and, when memo may have future entries (the case of a
   // positive tolerance), when the memo is empty.
   // used when checking whether RHS is up to date with LHS.
-  bool CurrentEmpty() const {
-    return memo_.no_future_ ? Empty() : memo_.times_.empty() && Empty();
+  // NOTE: The emptiness must be decided by an atomic all to Empty() in caller, due to the

Review Comment:
   "single call" might be a better description.



-- 
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-41149: [C++][Acero] Fix asof join race [arrow]

Posted by "zanmato1984 (via GitHub)" <gi...@apache.org>.
zanmato1984 commented on code in PR #41614:
URL: https://github.com/apache/arrow/pull/41614#discussion_r1598668948


##########
cpp/src/arrow/acero/asof_join_node.cc:
##########
@@ -548,8 +548,10 @@ class InputState {
   // true when the queue is empty and, when memo may have future entries (the case of a
   // positive tolerance), when the memo is empty.
   // used when checking whether RHS is up to date with LHS.
-  bool CurrentEmpty() const {
-    return memo_.no_future_ ? Empty() : memo_.times_.empty() && Empty();
+  // NOTE: The emptiness must be decided by an atomic all to Empty() in caller, due to the
+  // potential race with Push(), see GH-41614.
+  bool CurrentEmpty(bool empty) const {
+    return memo_.no_future_ ? empty : memo_.times_.empty() && empty;

Review Comment:
   Honestly I can't tell for 100% sure. But from my understanding of the code so far, we are good. Unlike the race happening on the `queue_`, between one side being `Push` and the other being `Process`, the `memo_` seems only to be manipulated by the `Process` thread which is in good sync with itself.



-- 
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] Test to repro [arrow]

Posted by "ursabot (via GitHub)" <gi...@apache.org>.
ursabot commented on PR #41614:
URL: https://github.com/apache/arrow/pull/41614#issuecomment-2104094464

   Benchmark runs are scheduled for commit 223951e031012e948027ce8d26f1ed3bb37cacf5. Watch https://buildkite.com/apache-arrow and https://conbench.ursa.dev for updates. A comment will be posted here when the runs are complete.


-- 
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] Test to repro [arrow]

Posted by "zanmato1984 (via GitHub)" <gi...@apache.org>.
zanmato1984 commented on PR #41614:
URL: https://github.com/apache/arrow/pull/41614#issuecomment-2104094326

   @ursabot please benchmark


-- 
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] Test to repro [arrow]

Posted by "conbench-apache-arrow[bot] (via GitHub)" <gi...@apache.org>.
conbench-apache-arrow[bot] commented on PR #41614:
URL: https://github.com/apache/arrow/pull/41614#issuecomment-2104414991

   Thanks for your patience. Conbench analyzed the 7 benchmarking runs that have been run so far on PR commit 223951e031012e948027ce8d26f1ed3bb37cacf5.
   
   There were 60 benchmark results indicating a performance regression:
   
   - Pull Request Run on `test-mac-arm` at [2024-05-10 09:19:32Z](https://conbench.ursa.dev/compare/runs/aac0f6ae31a64476a22141247d5c54fe...68fa279d73dd4cb1830464ab4c21785b/)
     - [`CopyEmptyVector` (C++) with params=<SMALL_VECTOR(std::string)>, source=cpp-micro, suite=arrow-small-vector-benchmark](https://conbench.ursa.dev/compare/benchmarks/0662d824a44478bb800000904248db30...0663de1b7ecd7fd080003d299799906f)
     - [`BM_RleDecoding` (C++) with params=65536/16, source=cpp-micro, suite=parquet-column-io-benchmark](https://conbench.ursa.dev/compare/benchmarks/0662d82c889e770d80003be380629002...0663de2612ca79fa8000005ad4f5eea3)
   - and 58 more (see the report linked below)
   
   The [full Conbench report](https://github.com/apache/arrow/runs/24817275830) has more details.


-- 
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-41149: [C++][Acero] Fix asof join race [arrow]

Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on code in PR #41614:
URL: https://github.com/apache/arrow/pull/41614#discussion_r1598463169


##########
cpp/src/arrow/acero/asof_join_node.cc:
##########
@@ -918,34 +922,39 @@ class CompositeTableBuilder {
 // guaranteeing this probability is below 1 in a billion. The fix is 128-bit hashing.
 // See ARROW-17653
 class AsofJoinNode : public ExecNode {
-  // Advances the RHS as far as possible to be up to date for the current LHS timestamp
-  Result<bool> UpdateRhs() {
+  // Advances the RHS as far as possible to be up to date for the current LHS timestamp.
+  // Returns a pair of booleans. The first is if any RHS has advanced. The second is if
+  // all RHS are up to date for LHS.
+  Result<std::pair<bool, bool>> UpdateRhsAndCheckUpToDateWithLhs() {

Review Comment:
   Can you return a struct with explanatory member names instead? 



##########
cpp/src/arrow/acero/asof_join_node.cc:
##########
@@ -548,8 +548,10 @@ class InputState {
   // true when the queue is empty and, when memo may have future entries (the case of a
   // positive tolerance), when the memo is empty.
   // used when checking whether RHS is up to date with LHS.
-  bool CurrentEmpty() const {
-    return memo_.no_future_ ? Empty() : memo_.times_.empty() && Empty();
+  // NOTE: The emptiness must be decided by an atomic all to Empty() in caller, due to the

Review Comment:
   ```suggestion
     // NOTE: The emptiness must be decided by an atomic call to Empty() in caller, due to the
   ```



##########
cpp/src/arrow/acero/asof_join_node.cc:
##########
@@ -548,8 +548,10 @@ class InputState {
   // true when the queue is empty and, when memo may have future entries (the case of a
   // positive tolerance), when the memo is empty.
   // used when checking whether RHS is up to date with LHS.
-  bool CurrentEmpty() const {
-    return memo_.no_future_ ? Empty() : memo_.times_.empty() && Empty();
+  // NOTE: The emptiness must be decided by an atomic all to Empty() in caller, due to the
+  // potential race with Push(), see GH-41614.
+  bool CurrentEmpty(bool empty) const {
+    return memo_.no_future_ ? empty : memo_.times_.empty() && empty;

Review Comment:
   Can you add parentheses to make sure operator precedence is not mistaken?



##########
cpp/src/arrow/acero/asof_join_node.cc:
##########
@@ -548,8 +548,10 @@ class InputState {
   // true when the queue is empty and, when memo may have future entries (the case of a
   // positive tolerance), when the memo is empty.
   // used when checking whether RHS is up to date with LHS.
-  bool CurrentEmpty() const {
-    return memo_.no_future_ ? Empty() : memo_.times_.empty() && Empty();
+  // NOTE: The emptiness must be decided by an atomic all to Empty() in caller, due to the

Review Comment:
   Also, what do you call "atomic" here? I don't see any synchronization around calls to `Empty`.



##########
cpp/src/arrow/acero/asof_join_node_test.cc:
##########
@@ -1678,5 +1678,55 @@ TEST(AsofJoinTest, BackpressureWithBatchesGen) {
                           /*slow_r0=*/false);
 }
 
+TEST(AsofJoinTest, GH40675) {
+  auto left_batch = ExecBatchFromJSON(

Review Comment:
   It's nice to give the GH issue reference, but it would even be a bit better with a comment explaining what specifically this test is doing (without having to decipher all the test code).



##########
cpp/src/arrow/acero/asof_join_node_test.cc:
##########
@@ -1678,5 +1678,55 @@ TEST(AsofJoinTest, BackpressureWithBatchesGen) {
                           /*slow_r0=*/false);
 }
 
+TEST(AsofJoinTest, GH40675) {
+  auto left_batch = ExecBatchFromJSON(
+      {int64(), utf8()}, R"([[1, "a"], [1, "b"], [5, "a"], [6, "b"], [7, "f"]])");
+  auto right_batch = ExecBatchFromJSON(
+      {int64(), utf8(), float64()}, R"([[2, "a", 1.0], [9, "b", 3.0], [15, "g", 5.0]])");
+
+  Declaration left{
+      "exec_batch_source",
+      ExecBatchSourceNodeOptions(schema({field("colA", int64()), field("col2", utf8())}),
+                                 {std::move(left_batch)})};
+  Declaration right{
+      "exec_batch_source",
+      ExecBatchSourceNodeOptions(schema({field("colB", int64()), field("col3", utf8()),
+                                         field("colC", float64())}),
+                                 {std::move(right_batch)})};
+  AsofJoinNodeOptions asof_join_opts({{{"colA"}, {{"col2"}}}, {{"colB"}, {{"col3"}}}}, 1);
+  Declaration asof_join{
+      "asofjoin", {std::move(left), std::move(right)}, std::move(asof_join_opts)};
+
+  ASSERT_OK_AND_ASSIGN(auto result, DeclarationToExecBatches(std::move(asof_join)));
+
+  auto exp_batch = ExecBatchFromJSON(
+      {int64(), utf8(), float64()},
+      R"([[1, "a", 1.0], [1, "b", null], [5, "a", null], [6, "b", null], [7, "f", null]])");
+  AssertExecBatchesEqualIgnoringOrder(result.schema, {exp_batch}, result.batches);
+}
+
+TEST(AsofJoinTest, GH41149) {
+  auto left_batch = ExecBatchFromJSON({int64()}, R"([[1], [2], [3]])");

Review Comment:
   Same here.



-- 
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-41149: [C++][Acero] Fix asof join race [arrow]

Posted by "zanmato1984 (via GitHub)" <gi...@apache.org>.
zanmato1984 commented on code in PR #41614:
URL: https://github.com/apache/arrow/pull/41614#discussion_r1598734434


##########
cpp/src/arrow/acero/asof_join_node_test.cc:
##########
@@ -1678,5 +1678,55 @@ TEST(AsofJoinTest, BackpressureWithBatchesGen) {
                           /*slow_r0=*/false);
 }
 
+TEST(AsofJoinTest, GH40675) {
+  auto left_batch = ExecBatchFromJSON(

Review Comment:
   Addressed.



-- 
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-41149: [C++][Acero] Fix asof join race [arrow]

Posted by "zanmato1984 (via GitHub)" <gi...@apache.org>.
zanmato1984 commented on code in PR #41614:
URL: https://github.com/apache/arrow/pull/41614#discussion_r1598733991


##########
cpp/src/arrow/acero/asof_join_node_test.cc:
##########
@@ -1678,5 +1678,55 @@ TEST(AsofJoinTest, BackpressureWithBatchesGen) {
                           /*slow_r0=*/false);
 }
 
+TEST(AsofJoinTest, GH40675) {
+  auto left_batch = ExecBatchFromJSON(

Review Comment:
   Addressed.



-- 
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-41149: [C++][Acero] Fix asof join race [arrow]

Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on code in PR #41614:
URL: https://github.com/apache/arrow/pull/41614#discussion_r1600349209


##########
cpp/src/arrow/acero/asof_join_node_test.cc:
##########
@@ -1678,5 +1678,55 @@ TEST(AsofJoinTest, BackpressureWithBatchesGen) {
                           /*slow_r0=*/false);
 }
 
+TEST(AsofJoinTest, GH40675) {
+  auto left_batch = ExecBatchFromJSON(
+      {int64(), utf8()}, R"([[1, "a"], [1, "b"], [5, "a"], [6, "b"], [7, "f"]])");
+  auto right_batch = ExecBatchFromJSON(
+      {int64(), utf8(), float64()}, R"([[2, "a", 1.0], [9, "b", 3.0], [15, "g", 5.0]])");
+
+  Declaration left{
+      "exec_batch_source",
+      ExecBatchSourceNodeOptions(schema({field("colA", int64()), field("col2", utf8())}),
+                                 {std::move(left_batch)})};
+  Declaration right{
+      "exec_batch_source",
+      ExecBatchSourceNodeOptions(schema({field("colB", int64()), field("col3", utf8()),
+                                         field("colC", float64())}),
+                                 {std::move(right_batch)})};
+  AsofJoinNodeOptions asof_join_opts({{{"colA"}, {{"col2"}}}, {{"colB"}, {{"col3"}}}}, 1);
+  Declaration asof_join{
+      "asofjoin", {std::move(left), std::move(right)}, std::move(asof_join_opts)};
+
+  ASSERT_OK_AND_ASSIGN(auto result, DeclarationToExecBatches(std::move(asof_join)));
+
+  auto exp_batch = ExecBatchFromJSON(
+      {int64(), utf8(), float64()},
+      R"([[1, "a", 1.0], [1, "b", null], [5, "a", null], [6, "b", null], [7, "f", null]])");
+  AssertExecBatchesEqualIgnoringOrder(result.schema, {exp_batch}, result.batches);
+}
+
+TEST(AsofJoinTest, GH41149) {
+  auto left_batch = ExecBatchFromJSON({int64()}, R"([[1], [2], [3]])");

Review Comment:
   Thanks a lot!



-- 
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-41149: [C++][Acero] Fix asof join race [arrow]

Posted by "zanmato1984 (via GitHub)" <gi...@apache.org>.
zanmato1984 commented on PR #41614:
URL: https://github.com/apache/arrow/pull/41614#issuecomment-2107835094

   > I think if I understand correctly you are saying that the value returned by `rhs.Empty` could change (from true to false I presume?) between the `UpdateRhs` call and the `IsUpToDateWithLhsRow` call and this becomes a logic bug?
   
   Thank you Weston. Your presumption is correct. I've explained the issue in more detail in my previous reply to Antoine.
    
   > It might be easier / simpler to wrap some part of `ProcessInner` in a mutex that is also wrapped around state modification done by the parts of the code that add data. However, I realize that may have performance impact.
   
   Actually I was trying to fix it using mutex, here is a single-mutex version [`223951e` (#41614)](https://github.com/apache/arrow/pull/41614/commits/223951e031012e948027ce8d26f1ed3bb37cacf5) and a double-mutex version [`ade727e` (#41614)](https://github.com/apache/arrow/pull/41614/commits/ade727e68488aad1f34ea635800b1b579c5fe17a), both showing a up to 10% performance regression. This forces me to think of a lockless fix (the current one). But if the performance down is acceptable when code complexity is a consideration, I'm totally fine to go back to the mutex solution (maybe the double-mutex one is a fair tradeoff). Any recommendation?


-- 
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] Test to repro [arrow]

Posted by "zanmato1984 (via GitHub)" <gi...@apache.org>.
zanmato1984 closed pull request #41614: Test to repro
URL: https://github.com/apache/arrow/pull/41614


-- 
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-41149: [C++][Acero] Fix asof join race [arrow]

Posted by "zanmato1984 (via GitHub)" <gi...@apache.org>.
zanmato1984 commented on code in PR #41614:
URL: https://github.com/apache/arrow/pull/41614#discussion_r1598668948


##########
cpp/src/arrow/acero/asof_join_node.cc:
##########
@@ -548,8 +548,10 @@ class InputState {
   // true when the queue is empty and, when memo may have future entries (the case of a
   // positive tolerance), when the memo is empty.
   // used when checking whether RHS is up to date with LHS.
-  bool CurrentEmpty() const {
-    return memo_.no_future_ ? Empty() : memo_.times_.empty() && Empty();
+  // NOTE: The emptiness must be decided by an atomic all to Empty() in caller, due to the
+  // potential race with Push(), see GH-41614.
+  bool CurrentEmpty(bool empty) const {
+    return memo_.no_future_ ? empty : memo_.times_.empty() && empty;

Review Comment:
   Honestly I can't tell for 100% sure. But from my understanding of the code so far, we are good. Unlike the race happening on the `queue_`, between on side being `Push` and the other being `Process`, the `memo_` seems only to be manipulated by the `Process` thread which is in good sync with itself.



-- 
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-41149: [C++][Acero] Fix asof join race [arrow]

Posted by "ursabot (via GitHub)" <gi...@apache.org>.
ursabot commented on PR #41614:
URL: https://github.com/apache/arrow/pull/41614#issuecomment-2105079552

   Benchmark runs are scheduled for commit 606f48c52d49dae3198b4dd93bf431c6916d9115. Watch https://buildkite.com/apache-arrow and https://conbench.ursa.dev for updates. A comment will be posted here when the runs are complete.


-- 
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-41149: [C++][Acero] Fix asof join race [arrow]

Posted by "zanmato1984 (via GitHub)" <gi...@apache.org>.
zanmato1984 commented on PR #41614:
URL: https://github.com/apache/arrow/pull/41614#issuecomment-2105079377

   @ursabot please benchmark


-- 
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-41149: [C++][Acero] Fix asof join race [arrow]

Posted by "zanmato1984 (via GitHub)" <gi...@apache.org>.
zanmato1984 commented on PR #41614:
URL: https://github.com/apache/arrow/pull/41614#issuecomment-2107792835

   > It is hard to understand why this fixes the issue at all. The comments talk about an "atomic call" but I fail to see what is atomic here. This might even work by chance...
   
   Thanks for looking. And sorry about the bad wording - I should've come up with a better name than "atomic call". But the issue this PR is trying to fix is carefully studied and the fix is not by chance. Maybe I should've put this more explicitly than in the PR description, the issue can be 100% reproduced by injecting special delay as shown in this commit
   https://github.com/zanmato1984/arrow/commit/ea3b24c5f7308fe42f60dad41f51dbcbc1a54929, so the reason is clear enough.
   
   I shall explain it more:
   Suppose the left batch is pushed to asof join node at time `100`:
   https://github.com/zanmato1984/arrow/commit/ea3b24c5f7308fe42f60dad41f51dbcbc1a54929#diff-5493b6ae7ea2a4d5cfb581034c076e9c4be7608382168de6d1301ef67b6c01eeL1398
   Then at time `200` the `Process` thread starts and in turn calls `ProcessInner`:
   https://github.com/zanmato1984/arrow/commit/ea3b24c5f7308fe42f60dad41f51dbcbc1a54929#diff-5493b6ae7ea2a4d5cfb581034c076e9c4be7608382168de6d1301ef67b6c01eeL1034
   Within `ProcessInner`, it first advances the right batch (necessary for emitting results) (still time `200`, and it sees empty right batch):
   https://github.com/zanmato1984/arrow/commit/ea3b24c5f7308fe42f60dad41f51dbcbc1a54929#diff-5493b6ae7ea2a4d5cfb581034c076e9c4be7608382168de6d1301ef67b6c01eeL967
   Then at time `300` the right batch is pushed to asof join node:
   https://github.com/zanmato1984/arrow/commit/ea3b24c5f7308fe42f60dad41f51dbcbc1a54929#diff-5493b6ae7ea2a4d5cfb581034c076e9c4be7608382168de6d1301ef67b6c01eeL1398
   At last, time `400`, `ProcessInner` checks if the right batch is up-to-date with the left batch (if yes, emits result):
   https://github.com/zanmato1984/arrow/commit/ea3b24c5f7308fe42f60dad41f51dbcbc1a54929#diff-5493b6ae7ea2a4d5cfb581034c076e9c4be7608382168de6d1301ef67b6c01eeL974
   which it should not be the case because the right batch is not advanced at time `200` (because it is not pushed yet). But in `IsUpToDateWithLhsRow`, it checks for emptiness again:
   https://github.com/zanmato1984/arrow/commit/ea3b24c5f7308fe42f60dad41f51dbcbc1a54929#diff-5493b6ae7ea2a4d5cfb581034c076e9c4be7608382168de6d1301ef67b6c01eeL942
   and
   https://github.com/zanmato1984/arrow/commit/ea3b24c5f7308fe42f60dad41f51dbcbc1a54929#diff-5493b6ae7ea2a4d5cfb581034c076e9c4be7608382168de6d1301ef67b6c01eeL552
   And this time, it's not empty (as the right batch is already pushed) and `ProcessInner` thinks "Great, you're up-to-date and let's emit some results".
   
   As you can see this is a logical race about the right batch's emptiness between `Push` and `ProcessInner`. My original attempt to explain the fix is (improperly) describing it as an "atomic call". But as Weston suggested, maybe "single call" is better. And hope this explanation could give you more confidence on this fix :)


-- 
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] Test to repro [arrow]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #41614:
URL: https://github.com/apache/arrow/pull/41614#issuecomment-2103918636

   <!--
     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.
   -->
   
   Thanks for opening a pull request!
   
   If this is not a [minor PR](https://github.com/apache/arrow/blob/main/CONTRIBUTING.md#Minor-Fixes). Could you open an issue for this pull request on GitHub? https://github.com/apache/arrow/issues/new/choose
   
   Opening GitHub issues ahead of time contributes to the [Openness](http://theapacheway.com/open/#:~:text=Openness%20allows%20new%20users%20the,must%20happen%20in%20the%20open.) of the Apache Arrow project.
   
   Then could you also rename the pull request title in the following format?
   
       GH-${GITHUB_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}
   
   or
   
       MINOR: [${COMPONENT}] ${SUMMARY}
   
   In the case of PARQUET issues on JIRA the title also supports:
   
       PARQUET-${JIRA_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}
   
   See also:
   
     * [Other pull requests](https://github.com/apache/arrow/pulls/)
     * [Contribution Guidelines - Contributing Overview](https://arrow.apache.org/docs/developers/overview.html)
   


-- 
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-41149: [C++][Acero] Fix asof join race [arrow]

Posted by "conbench-apache-arrow[bot] (via GitHub)" <gi...@apache.org>.
conbench-apache-arrow[bot] commented on PR #41614:
URL: https://github.com/apache/arrow/pull/41614#issuecomment-2105154266

   Thanks for your patience. Conbench analyzed the 7 benchmarking runs that have been run so far on PR commit ade727e68488aad1f34ea635800b1b579c5fe17a.
   
   There were 62 benchmark results indicating a performance regression:
   
   - Pull Request Run on `ursa-thinkcentre-m75q` at [2024-05-10 17:58:53Z](https://conbench.ursa.dev/compare/runs/5b436b26dc6b431d9eb710413f01226e...a45a7beaa2084090a703f495f310724e/)
     - [`ValidateSmallAscii` (C++) with source=cpp-micro, suite=arrow-utf8-util-benchmark](https://conbench.ursa.dev/compare/benchmarks/0662d65c3a64780f8000768685bfc704...0663e52662e874048000ddd60d84ac46)
     - [`AsOfJoinOverhead` (C++) with params=left_freq:400/left_cols:20/left_ids:100/batch_size:4000/num_right_tables:1/right_freq:400/right_cols:20/right_ids:100/real_time, source=cpp-micro, suite=arrow-acero-asof-join-benchmark](https://conbench.ursa.dev/compare/benchmarks/0662d661bf4273108000a230c65299de...0663e52fb555781180003e955e72d1b3)
   - and 60 more (see the report linked below)
   
   The [full Conbench report](https://github.com/apache/arrow/runs/24835363256) has more details.


-- 
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-41149: [C++][Acero] Fix asof join race [arrow]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #41614:
URL: https://github.com/apache/arrow/pull/41614#issuecomment-2105083442

   :warning: GitHub issue #41149 **has been automatically assigned in GitHub** to PR creator.


-- 
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-41149: [C++][Acero] Fix asof join race [arrow]

Posted by "conbench-apache-arrow[bot] (via GitHub)" <gi...@apache.org>.
conbench-apache-arrow[bot] commented on PR #41614:
URL: https://github.com/apache/arrow/pull/41614#issuecomment-2105308057

   Thanks for your patience. Conbench analyzed the 7 benchmarking runs that have been run so far on PR commit 606f48c52d49dae3198b4dd93bf431c6916d9115.
   
   There were 64 benchmark results indicating a performance regression:
   
   - Pull Request Run on `test-mac-arm` at [2024-05-10 19:35:34Z](https://conbench.ursa.dev/compare/runs/aac0f6ae31a64476a22141247d5c54fe...c11d1bf9f0194007a6c2561872403acd/)
     - [`BM_RleDecoding` (C++) with params=65536/16, source=cpp-micro, suite=parquet-column-io-benchmark](https://conbench.ursa.dev/compare/benchmarks/0662d82c889e770d80003be380629002...0663e790a3fb786f80004532e7b52160)
     - [`ShortVectorInsertAtEnd` (C++) with params=<STD_VECTOR(int)>, source=cpp-micro, suite=arrow-small-vector-benchmark](https://conbench.ursa.dev/compare/benchmarks/0662d824e68079f5800041e5e66fa26b...0663e789cca97f1280008b00966a0962)
   - and 62 more (see the report linked below)
   
   The [full Conbench report](https://github.com/apache/arrow/runs/24839525250) has more details.


-- 
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-41149: [C++][Acero] Fix asof join race [arrow]

Posted by "zanmato1984 (via GitHub)" <gi...@apache.org>.
zanmato1984 commented on PR #41614:
URL: https://github.com/apache/arrow/pull/41614#issuecomment-2105106874

   Hi @jorisvandenbossche @pitrou @westonpace , would you please help to take a look? This fix can bring python CI peace. Thanks.


-- 
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-41149: [C++][Acero] Fix asof join race [arrow]

Posted by "conbench-apache-arrow[bot] (via GitHub)" <gi...@apache.org>.
conbench-apache-arrow[bot] commented on PR #41614:
URL: https://github.com/apache/arrow/pull/41614#issuecomment-2111456213

   After merging your PR, Conbench analyzed the 7 benchmarking runs that have been run so far on merge-commit 8f27e269cb4c9fc9b593177f30bf9a1ec6ef5cff.
   
   There were no benchmark performance regressions. 🎉
   
   The [full Conbench report](https://github.com/apache/arrow/runs/24979396830) has more details. It also includes information about 9 possible false positives 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