Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-17562

I think a little code is unnecessary to exist in ExternalSorter.spillMemoryIteratorToDisk

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Trivial
    • Resolution: Not A Problem
    • 2.0.0
    • None
    • Spark Core
    • Important

    Description

      In ExternalSorter.spillMemoryIteratorToDisk, I think the code below will never be executed, so we can remove them

      else  {
      writer.revertPartialWritersAndClose()
      }
      

      the source code is as below:

      try {
            while (inMemoryIterator.hasNext) {
              val partitionId = inMemoryIterator.nextPartition()
              require(partitionId >= 0 && partitionId < numPartitions,
                s"partition Id: ${partitionId} should be in the range [0, ${numPartitions})")
              inMemoryIterator.writeNext(writer)
              elementsPerPartition(partitionId) += 1
              objectsWritten += 1
      
              if (objectsWritten == serializerBatchSize) {
                flush()
              }
            }
            if (objectsWritten > 0) {
              flush()
            } else {
              writer.revertPartialWritesAndClose()
         }
            success = true
          } finally {
            if (success) {
              writer.close()
            } else {
              // This code path only happens if an exception was thrown above before we set success;
              // close our stuff and let the exception be thrown further
              writer.revertPartialWritesAndClose()
              if (file.exists()) {
                if (!file.delete()) {
                  logWarning(s"Error deleting ${file}")
                }
              }
            }
          }
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            codlife Jianfei Wang
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: