tomvanbussel commented on a change in pull request #29785:
URL: https://github.com/apache/spark/pull/29785#discussion_r490214568



##########
File path: 
core/src/main/java/org/apache/spark/util/collection/unsafe/sort/UnsafeExternalSorter.java
##########
@@ -339,29 +342,43 @@ public void cleanupResources() {
   private void growPointerArrayIfNecessary() throws IOException {
     assert(inMemSorter != null);
     if (!inMemSorter.hasSpaceForAnotherRecord()) {
+      if (inMemSorter.numRecords() <= 0) {

Review comment:
       We won't hit this block with the preallocated memory. Initially 
`inMemSorter.hasSpaceForAnotherRecord()` will be true, which can only become 
false after records have been inserted, at which point 
`inMemSorter.numRecords() <= 0` won't be true anymore.
   
   We could just check whether `inMemSorter` has memory allocated, but I tried 
to somewhat abstract the internals of `inMemSorter`. Not sure if that was the 
right decision though, given how tightly coupled `UnsafeExternalSorter` and 
`UnsafeInMemorySorter` currently are.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to