Skip to content
Snippets Groups Projects
Commit 95296d9b authored by Nong's avatar Nong Committed by Davies Liu
Browse files

[SPARK-12089] [SQL] Fix memory corrupt due to freeing a page being referenced

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.
parent 17e4e021
No related branches found
No related tags found
No related merge requests found
......@@ -443,6 +443,7 @@ public final class UnsafeExternalSorter extends MemoryConsumer {
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()) {
......@@ -458,9 +459,11 @@ public final class UnsafeExternalSorter extends MemoryConsumer {
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 {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment