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

    https://github.com/apache/spark/pull/15982#discussion_r90085605
  
    --- Diff: 
core/src/main/java/org/apache/spark/shuffle/sort/UnsafeShuffleWriter.java ---
    @@ -337,42 +340,38 @@ void forceSorterToSpill() throws IOException {
         final int numPartitions = partitioner.numPartitions();
         final long[] partitionLengths = new long[numPartitions];
         final InputStream[] spillInputStreams = new 
FileInputStream[spills.length];
    -    OutputStream mergedFileOutputStream = null;
    +    final CountingOutputStream mergedFileOutputStream = new 
CountingOutputStream(
    +      new FileOutputStream(outputFile));
     
         boolean threwException = true;
         try {
           for (int i = 0; i < spills.length; i++) {
             spillInputStreams[i] = new FileInputStream(spills[i].file);
           }
           for (int partition = 0; partition < numPartitions; partition++) {
    -        final long initialFileLength = outputFile.length();
    -        mergedFileOutputStream =
    -          new TimeTrackingOutputStream(writeMetrics, new 
FileOutputStream(outputFile, true));
    +        final long initialFileLength = 
mergedFileOutputStream.getByteCount();
    +        OutputStream partitionOutput = new 
CloseShieldOutputStream(mergedFileOutputStream);
    +        partitionOutput = 
blockManager.serializerManager().wrapForEncryption(partitionOutput);
             if (compressionCodec != null) {
    -          mergedFileOutputStream = 
compressionCodec.compressedOutputStream(mergedFileOutputStream);
    +          partitionOutput = 
compressionCodec.compressedOutputStream(partitionOutput);
             }
    -
    +        partitionOutput = new TimeTrackingOutputStream(writeMetrics, 
partitionOutput);
             for (int i = 0; i < spills.length; i++) {
               final long partitionLengthInSpill = 
spills[i].partitionLengths[partition];
               if (partitionLengthInSpill > 0) {
    -            InputStream partitionInputStream = null;
    -            boolean innerThrewException = true;
    -            try {
    -              partitionInputStream =
    -                  new LimitedInputStream(spillInputStreams[i], 
partitionLengthInSpill, false);
    -              if (compressionCodec != null) {
    -                partitionInputStream = 
compressionCodec.compressedInputStream(partitionInputStream);
    -              }
    -              ByteStreams.copy(partitionInputStream, 
mergedFileOutputStream);
    -              innerThrewException = false;
    -            } finally {
    -              Closeables.close(partitionInputStream, innerThrewException);
    +            InputStream partitionInputStream = new 
LimitedInputStream(spillInputStreams[i],
    +              partitionLengthInSpill, false);
    +            partitionInputStream = 
blockManager.serializerManager().wrapForEncryption(
    --- End diff --
    
    `partitionInputStream` is not closed



---
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