-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-18827][Core] Fix cannot read broadcast on disk #16252
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -137,6 +137,18 @@ class BroadcastSuite extends SparkFunSuite with LocalSparkContext { | |
| sc.stop() | ||
| } | ||
|
|
||
| test("Cache broadcast to disk") { | ||
| val conf = new SparkConf() | ||
| .setMaster("local") | ||
| .setAppName("test") | ||
| .set("spark.memory.useLegacyMode", "true") | ||
| .set("spark.storage.memoryFraction", "0.0") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| sc = new SparkContext(conf) | ||
| val list = List[Int](1, 2, 3, 4) | ||
| val broadcast = sc.broadcast(list) | ||
| assert(broadcast.value.sum === 10) | ||
| } | ||
|
|
||
| /** | ||
| * Verify the persistence of state associated with a TorrentBroadcast in a local-cluster. | ||
| * | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally, only the null check should be there - with the !hasNext enforced as unrolled = null if false.
This is part of a tight loop, and would be better if the footprint is kept as small as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that's a fair point because it should be fair to put the burden on the caller to check
hasNextbefore callingnextand nowTorrentBroadcastdoes that. However, are there other call sites that need that type of fix too? if all callers are well behaved then I agree we could revert the addedhasNextcall innext.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, next() without hasNext is a valid code flow, and our code should not break due to caller not invoking hasNext (at best throw NoSuchElementException if hasNext == false).
Another option is to add hasNext check here - but that would be worse (since normal flow will then check hasNext twice).
If we cant ensure "require(unrolled == null || unrolled.hasNext)", then current change is best we can do I guess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that next() without hasNext is a valid flow. However, the caller which behaves like that should also aware of the possibility of no element exception.
TorrentBroadcastis problematic because it doesn't call hasNext and doesn't handle this possibility.I'd prefer to revert the added
hasNextcall innext. But not strong option.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isnt this a correctness issue though? If unrolled has no more elements the correct result is to return from the other iterator not throw an exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tested thrice without
!unrolled.hasNexton more than 100 billion data. They all work very well. I will remove!unrolled.hasNextThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not against the final state here without
!unrolled.hasNext, because indeed callers should really checkhasNextand if they don't it should be considered a bug. Do we think we got all the call sites for this though?The thing that concerns me is that
nextwill actually do the wrong thing ifhasNextisn't called andunrolledhas no elements. It will fail rather than just fall back torest. Scala says it's undefined in this case; Java does not.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1. I don't like to expose undefined behavior to the user, either. It's better to throw an exception instead. E.g., Scala's
ConcatIteratoris also implemented in this way: https://github.com/scala/scala/blob/v2.12.1/src/library/scala/collection/Iterator.scala#L216IMO, we should not assume an Iterator follows Java Iterator's contract, but if we are implementing an Iterator, it's better to follow it to avoiding spending a lot of time on debugging misusing Iterator in future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. It is fair to me to add
!unrolled.hasNexttonextfor more predicable behavior.To throw a exception might be a little strange to me, as it still has elements so a no such element exception seems not correct. It just doesn't correctly fall back to
rest.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant when
hasNextreturnsfalse,nextshould throw NoSuchElementException.