Github user yhuai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/9383#discussion_r43954658
  
    --- Diff: 
core/src/main/java/org/apache/spark/util/collection/unsafe/sort/UnsafeExternalSorter.java
 ---
    @@ -386,24 +388,37 @@ public void insertKVRecord(Object keyBase, long 
keyOffset, int keyLen,
       }
     
       /**
    +   * Merges another UnsafeExternalSorters into this one, the other one 
will be emptied.
    +   *
    +   * @throws IOException
    +   */
    +  public void merge(UnsafeExternalSorter other) throws IOException {
    +    other.spill();
    +    spillWriters.addAll(other.spillWriters);
    +    // remove them from `spillWriters`, or the files will be deleted in 
`cleanupResources`.
    +    other.spillWriters.clear();
    +    other.cleanupResources();
    +  }
    +
    +  /**
        * Returns a sorted iterator. It is the caller's responsibility to call 
`cleanupResources()`
        * after consuming this iterator.
        */
       public UnsafeSorterIterator getSortedIterator() throws IOException {
    -    assert(inMemSorter != null);
    -    readingIterator = new 
SpillableIterator(inMemSorter.getSortedIterator());
    -    int numIteratorsToMerge = spillWriters.size() + 
(readingIterator.hasNext() ? 1 : 0);
         if (spillWriters.isEmpty()) {
    +      assert(inMemSorter != null);
    +      readingIterator = new 
SpillableIterator(inMemSorter.getSortedIterator());
           return readingIterator;
         } else {
           final UnsafeSorterSpillMerger spillMerger =
    -        new UnsafeSorterSpillMerger(recordComparator, prefixComparator, 
numIteratorsToMerge);
    +        new UnsafeSorterSpillMerger(recordComparator, prefixComparator, 
spillWriters.size());
           for (UnsafeSorterSpillWriter spillWriter : spillWriters) {
             
spillMerger.addSpillIfNotEmpty(spillWriter.getReader(blockManager));
           }
    -      spillWriters.clear();
    --- End diff --
    
    just a note, we had a quick discussion. Seems we should not call 
`spillWriters.clear()`. Otherwise those spilled files will not be deleted.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

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

Reply via email to