Skip to content
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

[SPARK-31511][SQL][2.4] Make BytesToBytesMap iterators thread-safe #29605

Closed
wants to merge 5 commits into from

Conversation

cxzl25
Copy link
Contributor

@cxzl25 cxzl25 commented Sep 1, 2020

What changes were proposed in this pull request?

This PR increases the thread safety of the BytesToBytesMap:

  • It makes the iterator() and destructiveIterator() methods used their own Location object. This used to be shared, and this was causing issues when the map was being iterated over in two threads by two different iterators.
  • Removes the safeIterator() function. This is not needed anymore.
  • Improves the documentation of a couple of methods w.r.t. thread-safety.

Why are the changes needed?

It is unexpected an iterator shares the object it is returning with all other iterators. This is a violation of the iterator contract, and it causes issues with iterators over a map that are consumed in different threads.

Does this PR introduce any user-facing change?

No

How was this patch tested?

add ut

hvanhovell and others added 2 commits September 1, 2020 12:12
### What changes were proposed in this pull request?
This PR increases the thread safety of the `BytesToBytesMap`:
- It makes the `iterator()` and `destructiveIterator()` methods used their own `Location` object. This used to be shared, and this was causing issues when the map was being iterated over in two threads by two different iterators.
- Removes the `safeIterator()` function. This is not needed anymore.
- Improves the documentation of a couple of methods w.r.t. thread-safety.

### Why are the changes needed?
It is unexpected an iterator shares the object it is returning with all other iterators. This is a violation of the iterator contract, and it causes issues with iterators over a map that are consumed in different threads.

### Does this PR introduce any user-facing change?
No

### How was this patch tested?
Existing tests.

Closes apache#28286 from hvanhovell/SPARK-31511.

Authored-by: herman <herman@databricks.com>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>

(cherry picked from commit cf60384)
@dongjoon-hyun
Copy link
Member

ok to test

@dongjoon-hyun
Copy link
Member

dongjoon-hyun commented Sep 1, 2020

Thank you so much, @cxzl25 .

cc @hvanhovell and @cloud-fan

@dongjoon-hyun
Copy link
Member

Also, cc @ScrapCodes for Apache Spark 2.4.7 since this is a correctness fix.

@SparkQA
Copy link

SparkQA commented Sep 1, 2020

Test build #128154 has finished for PR 29605 at commit 6492259.

  • This patch fails build dependency tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

Copy link
Contributor

@cloud-fan cloud-fan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM if tests pass

@ScrapCodes
Copy link
Member

Please correct, if I am wrong, currently there are no blockers for 2.4.7 release, but we are still waiting for this one to be merged.

@SparkQA
Copy link

SparkQA commented Sep 2, 2020

Test build #128180 has finished for PR 29605 at commit 49b4925.

  • This patch fails due to an unknown error code, -9.
  • This patch merges cleanly.
  • This patch adds no public classes.

@cloud-fan
Copy link
Contributor

I don't think it's a blocker. But if the RC is not started, it's probably better to wait a bit for this patch.

@SparkQA
Copy link

SparkQA commented Sep 2, 2020

Test build #128199 has finished for PR 29605 at commit 5ed2f28.

  • This patch fails build dependency tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@cloud-fan
Copy link
Contributor

retest this please

@SparkQA
Copy link

SparkQA commented Sep 2, 2020

Test build #128200 has finished for PR 29605 at commit 5ed2f28.

  • This patch fails build dependency tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@cloud-fan
Copy link
Contributor

jenkins is unstable now, let's wait for the github action results.

@cxzl25
Copy link
Contributor Author

cxzl25 commented Sep 2, 2020

I saw the last backport to the pr of 2.4, and the log of the github action result also reported a similar error pyspark ArrowTest.
https://github.com/apache/spark/runs/1044010610

The java arrow version of the master branch is 0.15.1, and the version of the 2.4 branch is 0.10.0.

Build_and_test.yml did not specify the pyarrow version when pip was installed, so the version that may be installed is the latest 1.0.1 version.

I am not sure if the incompatibility between 0.10 and 1.0.1 caused the check to fail.

I see that the pyspark test on jenkins is passed.

I try to submit and trigger another jenkins test.

@cloud-fan
Copy link
Contributor

retest this please

@dongjoon-hyun
Copy link
Member

It's really weird because both Jenkins and GitHub Action are flaky irrelevantly.

@dongjoon-hyun
Copy link
Member

Retest this please.

@SparkQA
Copy link

SparkQA commented Sep 2, 2020

Test build #128210 has finished for PR 29605 at commit 30eed99.

  • This patch fails Java style tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Sep 3, 2020

Test build #128224 has finished for PR 29605 at commit cc8d277.

  • This patch fails build dependency tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Sep 3, 2020

Test build #128227 has finished for PR 29605 at commit 5fbcfaf.

  • This patch fails Java style tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Sep 3, 2020

Test build #128232 has finished for PR 29605 at commit 9e689c5.

  • This patch fails Java style tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Sep 4, 2020

Test build #128301 has finished for PR 29605 at commit 2c3ff67.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Sep 4, 2020

Test build #128310 has finished for PR 29605 at commit d4c785d.

  • This patch fails build dependency tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Sep 5, 2020

Test build #128317 has finished for PR 29605 at commit 0e39f7a.

  • This patch fails due to an unknown error code, -9.
  • This patch merges cleanly.
  • This patch adds no public classes.

@cxzl25
Copy link
Contributor Author

cxzl25 commented Sep 7, 2020

I removed the code I changed in the commit (0e39f7a), but the jenkins and github action tests still don't pass, which is very strange.

@cloud-fan
Copy link
Contributor

retest this please

@cloud-fan
Copy link
Contributor

BTW, @cxzl25 you can use empty git commit to trigger test

@SparkQA
Copy link

SparkQA commented Sep 7, 2020

Test build #128336 has finished for PR 29605 at commit 0e39f7a.

  • This patch fails due to an unknown error code, -9.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Sep 7, 2020

Test build #128337 has finished for PR 29605 at commit a508102.

  • This patch fails due to an unknown error code, -9.
  • This patch merges cleanly.
  • This patch adds no public classes.

@cxzl25
Copy link
Contributor Author

cxzl25 commented Sep 7, 2020

Empty commits don't trigger a github action(No test results found!), but the jenkins test is a failure.

@cloud-fan
Copy link
Contributor

retest this please

@SparkQA
Copy link

SparkQA commented Sep 7, 2020

Test build #128355 has finished for PR 29605 at commit a508102.

  • This patch fails build dependency tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@cloud-fan
Copy link
Contributor

@cxzl25 why does this patch become empty? You can add empty commits to trigger tests, but you can't turn the patch into empty...

@cxzl25
Copy link
Contributor Author

cxzl25 commented Sep 7, 2020

@cloud-fan
I just want to verify whether the test of the current branch works normally, the test still seems to fail.
Now i resubmit the code.

@SparkQA
Copy link

SparkQA commented Sep 7, 2020

Test build #128360 has finished for PR 29605 at commit 37465c5.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
  • case class First(child: Expression, ignoreNulls: Boolean)
  • case class Last(child: Expression, ignoreNulls: Boolean)

@cloud-fan
Copy link
Contributor

jenkins is happy finally ...

Thanks, merging to 2.4!

cloud-fan pushed a commit that referenced this pull request Sep 8, 2020
### What changes were proposed in this pull request?
This PR increases the thread safety of the `BytesToBytesMap`:
- It makes the `iterator()` and `destructiveIterator()` methods used their own `Location` object. This used to be shared, and this was causing issues when the map was being iterated over in two threads by two different iterators.
- Removes the `safeIterator()` function. This is not needed anymore.
- Improves the documentation of a couple of methods w.r.t. thread-safety.

### Why are the changes needed?
It is unexpected an iterator shares the object it is returning with all other iterators. This is a violation of the iterator contract, and it causes issues with iterators over a map that are consumed in different threads.

### Does this PR introduce any user-facing change?
No

### How was this patch tested?
add ut

Closes #29605 from cxzl25/SPARK-31511.

Lead-authored-by: sychen <sychen@ctrip.com>
Co-authored-by: herman <herman@databricks.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
@@ -341,6 +341,45 @@ class HashedRelationSuite extends SparkFunSuite with SharedSQLContext {
assert(java.util.Arrays.equals(os.toByteArray, os2.toByteArray))
}

test("SPARK-31511: Make BytesToBytesMap iterators thread-safe") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you open a new PR to add this test for master/3.0?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I submit a pull request to add test.
#29669

@cloud-fan cloud-fan closed this Sep 8, 2020
@dongjoon-hyun
Copy link
Member

Thank you, @cxzl25 and @cloud-fan .

@ScrapCodes
Copy link
Member

Now, I can go ahead and tag the release. Good work. ( A long battle with CI)

@dongjoon-hyun
Copy link
Member

Thank you for the release preparation, @ScrapCodes .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants