Skip to content

Commit

Permalink
[SPARK-12089] [SQL] Fix memory corrupt due to freeing a page being re…
Browse files Browse the repository at this point in the history
…ferenced

When the spillable sort iterator was spilled, it was mistakenly keeping
the last page in memory rather than the current page. This causes the
current record to get corrupted.

Author: Nong <nong@cloudera.com>

Closes #10142 from nongli/spark-12089.
  • Loading branch information
Nong authored and davies committed Dec 4, 2015
1 parent 17e4e02 commit 95296d9
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ public long spill() throws IOException {
UnsafeInMemorySorter.SortedIterator inMemIterator =
((UnsafeInMemorySorter.SortedIterator) upstream).clone();

// Iterate over the records that have not been returned and spill them.
final UnsafeSorterSpillWriter spillWriter =
new UnsafeSorterSpillWriter(blockManager, fileBufferSizeBytes, writeMetrics, numRecords);
while (inMemIterator.hasNext()) {
Expand All @@ -458,9 +459,11 @@ public long spill() throws IOException {

long released = 0L;
synchronized (UnsafeExternalSorter.this) {
// release the pages except the one that is used
// release the pages except the one that is used. There can still be a caller that
// is accessing the current record. We free this page in that caller's next loadNext()
// call.
for (MemoryBlock page : allocatedPages) {
if (!loaded || page.getBaseObject() != inMemIterator.getBaseObject()) {
if (!loaded || page.getBaseObject() != upstream.getBaseObject()) {
released += page.size();
freePage(page);
} else {
Expand Down

0 comments on commit 95296d9

Please sign in to comment.