Skip to content

Commit 4cf05c9

Browse files
Sumedh Waleymahajan
authored andcommitted
[SNAP-1233] clear InMemorySorter before calling its reset (#35)
This is done so that any spill call (due to no EVICTION_DOWN) from within the spill call will return without doing anything, else it results in NPE trying to read page tables which have already been cleared.
1 parent 9447d24 commit 4cf05c9

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

core/src/main/java/org/apache/spark/util/collection/unsafe/sort/UnsafeExternalSorter.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,17 @@ public long spill(long size, MemoryConsumer trigger) throws IOException {
226226
// Note that this is more-or-less going to be a multiple of the page size, so wasted space in
227227
// pages will currently be counted as memory spilled even though that space isn't actually
228228
// written to disk. This also counts the space needed to store the sorter's pointer array.
229-
inMemSorter.reset();
229+
230+
// temporarily clear inMemorySorter so that a recursive spill call will return
231+
final UnsafeInMemorySorter memSorter = inMemSorter;
232+
if (memSorter != null) {
233+
inMemSorter = null;
234+
try {
235+
memSorter.reset();
236+
} finally {
237+
inMemSorter = memSorter;
238+
}
239+
}
230240
// Reset the in-memory sorter's pointer array only after freeing up the memory pages holding the
231241
// records. Otherwise, if the task is over allocated memory, then without freeing the memory
232242
// pages, we might not be able to get memory for the pointer array.

0 commit comments

Comments
 (0)