Skip to content

Commit 25828f2

Browse files
committed
fix mridulm comments
1 parent 9f5afd4 commit 25828f2

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

core/src/main/java/org/apache/spark/shuffle/sort/BypassMergeSortShuffleWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ public Option<MapStatus> stop(boolean success) {
289289
try {
290290
for (DiskBlockObjectWriter writer : partitionWriters) {
291291
// This method explicitly does _not_ throw exceptions:
292-
writer.deleteHeldFile();
292+
writer.closeAndDelete();
293293
}
294294
} finally {
295295
partitionWriters = null;

core/src/main/scala/org/apache/spark/storage/DiskBlockObjectWriter.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package org.apache.spark.storage
1919

2020
import java.io.{BufferedOutputStream, File, FileOutputStream, OutputStream}
2121
import java.nio.channels.{ClosedByInterruptException, FileChannel}
22+
import java.nio.file.Files
2223
import java.util.zip.Checksum
2324

2425
import org.apache.spark.internal.Logging
@@ -28,6 +29,7 @@ import org.apache.spark.shuffle.ShuffleWriteMetricsReporter
2829
import org.apache.spark.util.Utils
2930
import org.apache.spark.util.collection.PairsWriter
3031

32+
3133
/**
3234
* A class for writing JVM objects directly to a file on disk. This class allows data to be appended
3335
* to an existing block. For efficiency, it retains the underlying file channel across
@@ -267,18 +269,16 @@ private[spark] class DiskBlockObjectWriter(
267269
* by current `DiskBlockObjectWriter`. Callers should invoke this function when there
268270
* are runtime exceptions in file writing process and the file is no longer needed.
269271
*/
270-
def deleteHeldFile(): Unit = {
272+
def closeAndDelete(): Unit = {
271273
Utils.tryWithSafeFinally {
272274
if (initialized) {
273275
writeMetrics.decBytesWritten(reportedPosition - committedPosition)
274276
writeMetrics.decRecordsWritten(numRecordsWritten)
275277
closeResources()
276278
}
277279
} {
278-
if (file.exists()) {
279-
if (!file.delete()) {
280-
logWarning(s"Error deleting $file")
281-
}
280+
if (!Files.deleteIfExists(file.toPath)) {
281+
logWarning(s"Error deleting $file")
282282
}
283283
}
284284
}

core/src/main/scala/org/apache/spark/util/collection/ExternalAppendOnlyMap.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ class ExternalAppendOnlyMap[K, V, C](
250250
if (!success) {
251251
// This code path only happens if an exception was thrown above before we set success;
252252
// close our stuff and let the exception be thrown further
253-
writer.deleteHeldFile()
253+
writer.closeAndDelete()
254254
}
255255
}
256256

core/src/main/scala/org/apache/spark/util/collection/ExternalSorter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ private[spark] class ExternalSorter[K, V, C](
321321
if (!success) {
322322
// This code path only happens if an exception was thrown above before we set success;
323323
// close our stuff and let the exception be thrown further
324-
writer.deleteHeldFile()
324+
writer.closeAndDelete()
325325
}
326326
}
327327

0 commit comments

Comments
 (0)