-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-19500] [SQL] Fix off-by-one bug in BytesToBytesMap #16844
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -698,7 +698,7 @@ public boolean append(Object kbase, long koff, int klen, Object vbase, long voff | |
| if (numKeys == MAX_CAPACITY | ||
| // The map could be reused from last spill (because of no enough memory to grow), | ||
| // then we don't try to grow again if hit the `growthThreshold`. | ||
| || !canGrowArray && numKeys > growthThreshold) { | ||
| || !canGrowArray && numKeys >= growthThreshold) { | ||
| return false; | ||
| } | ||
|
|
||
|
|
@@ -742,7 +742,7 @@ public boolean append(Object kbase, long koff, int klen, Object vbase, long voff | |
| longArray.set(pos * 2 + 1, keyHashcode); | ||
| isDefined = true; | ||
|
|
||
| if (numKeys > growthThreshold && longArray.size() < MAX_CAPACITY) { | ||
| if (numKeys >= growthThreshold && longArray.size() < MAX_CAPACITY) { | ||
|
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. The re-allocated space might not be used if no further insertion. Shall we do
Contributor
Author
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. Unfortunately, we can't grow in the beginning, otherwise the
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. OK. LGTM. |
||
| try { | ||
| growAndRehash(); | ||
| } catch (OutOfMemoryError oom) { | ||
|
|
@@ -911,6 +911,7 @@ public void reset() { | |
| freePage(dataPage); | ||
| } | ||
| allocate(initialCapacity); | ||
| canGrowArray = true; | ||
| currentPage = null; | ||
| pageCursor = 0; | ||
| } | ||
|
|
||
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.
This change makes sense to me because
growthThreshold's Scaladoc says "The map will be expanded once the number of keys exceeds this threshold" and here we're considering the impact of adding an additional key (so this could have also been written as(numKeys + 1) > growthThreshold).