Skip to content

Commit e6e428f

Browse files
committed
Address comments
1 parent 16a0d27 commit e6e428f

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

network/common/src/main/java/org/apache/spark/network/util/JavaUtils.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,10 @@ public static void deleteRecursively(File file) throws IOException {
122122
}
123123
}
124124

125-
if (!file.delete()) {
126-
// Delete can also fail if the file simply did not exist
127-
if (file.exists()) {
128-
throw new IOException("Failed to delete: " + file.getAbsolutePath());
129-
}
125+
boolean deleted = file.delete();
126+
// Delete can also fail if the file simply did not exist.
127+
if (!deleted && file.exists()) {
128+
throw new IOException("Failed to delete: " + file.getAbsolutePath());
130129
}
131130
}
132131

network/shuffle/src/main/java/org/apache/spark/network/shuffle/ExternalShuffleBlockManager.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.util.Map;
2626
import java.util.concurrent.ConcurrentMap;
2727
import java.util.concurrent.Executor;
28-
import java.util.concurrent.ExecutorService;
2928
import java.util.concurrent.Executors;
3029

3130
import com.google.common.annotations.VisibleForTesting;
@@ -53,8 +52,8 @@ public class ExternalShuffleBlockManager {
5352
// Map containing all registered executors' metadata.
5453
private final ConcurrentMap<AppExecId, ExecutorShuffleInfo> executors;
5554

56-
// Single-threaded executor used to perform expensive recursive directory deletion.
57-
private final Executor directoryCleanupExecutor;
55+
// Single-threaded Java executor used to perform expensive recursive directory deletion.
56+
private final Executor directoryCleaner;
5857

5958
public ExternalShuffleBlockManager() {
6059
// TODO: Give this thread a name.
@@ -63,9 +62,9 @@ public ExternalShuffleBlockManager() {
6362

6463
// Allows tests to have more control over when directories are cleaned up.
6564
@VisibleForTesting
66-
ExternalShuffleBlockManager(Executor directoryCleanupExecutor) {
65+
ExternalShuffleBlockManager(Executor directoryCleaner) {
6766
this.executors = Maps.newConcurrentMap();
68-
this.directoryCleanupExecutor = directoryCleanupExecutor;
67+
this.directoryCleaner = directoryCleaner;
6968
}
7069

7170
/** Registers a new Executor with all the configuration we need to find its shuffle files. */
@@ -134,8 +133,9 @@ public void applicationRemoved(String appId, boolean cleanupLocalDirs) {
134133
logger.info("Cleaning up executor {}'s {} local dirs", fullId, executor.localDirs.length);
135134

136135
// Execute the actual deletion in a different thread, as it may take some time.
137-
directoryCleanupExecutor.execute(new Runnable() {
138-
@Override public void run() {
136+
directoryCleaner.execute(new Runnable() {
137+
@Override
138+
public void run() {
139139
deleteExecutorDirs(executor.localDirs);
140140
}
141141
});

network/shuffle/src/test/java/org/apache/spark/network/shuffle/ExternalShuffleCleanupSuite.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.io.IOException;
2222
import java.util.Random;
2323
import java.util.concurrent.Executor;
24+
import java.util.concurrent.atomic.AtomicBoolean;
2425

2526
import com.google.common.util.concurrent.MoreExecutors;
2627
import org.junit.Test;
@@ -53,16 +54,19 @@ public void noCleanupAndCleanup() throws IOException {
5354
public void cleanupUsesExecutor() throws IOException {
5455
TestShuffleDataContext dataContext = createSomeData();
5556

57+
final AtomicBoolean cleanupCalled = new AtomicBoolean(false);
58+
5659
// Executor which does nothing to ensure we're actually using it.
5760
Executor noThreadExecutor = new Executor() {
58-
@Override public void execute(Runnable runnable) { /* do nothing */ }
61+
@Override public void execute(Runnable runnable) { cleanupCalled.set(true); }
5962
};
6063

6164
ExternalShuffleBlockManager manager = new ExternalShuffleBlockManager(noThreadExecutor);
6265

6366
manager.registerExecutor("app", "exec0", dataContext.createExecutorInfo("shuffleMgr"));
6467
manager.applicationRemoved("app", true);
6568

69+
assertTrue(cleanupCalled.get());
6670
assertStillThere(dataContext);
6771

6872
dataContext.cleanup();

0 commit comments

Comments
 (0)