Skip to content

Commit 30e558d

Browse files
committed
go back to try/finally
1 parent e503b8c commit 30e558d

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

core/src/main/java/org/apache/spark/shuffle/unsafe/UnsafeShuffleWriter.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,22 +139,27 @@ public void write(Iterator<Product2<K, V>> records) throws IOException {
139139

140140
@Override
141141
public void write(scala.collection.Iterator<Product2<K, V>> records) throws IOException {
142+
// Keep track of success so we know if we ecountered an exception
143+
// We do this rather than a standard try/catch/re-throw to handle
144+
// generic throwables.
145+
boolean success = false;
142146
try {
143147
while (records.hasNext()) {
144148
insertRecordIntoSorter(records.next());
145149
}
146-
closeAndWriteOutput();
147-
} catch (Exception e) {
148-
// Trigger a cleanup if we encountered an error
150+
success = true;
151+
} finally {
149152
if (sorter != null) {
150153
try {
151154
sorter.cleanupAfterError();
152-
} catch (Exception e2) {
153-
throw new RuntimeException("Failed to perform cleanup after exception", e);
155+
} catch (Exception e) {
156+
// Only throw this error if we won't be masking another
157+
// error.
158+
if (success) {
159+
throw e;
160+
}
154161
}
155162
}
156-
// re-throw the exception
157-
throw e;
158163
}
159164
}
160165

0 commit comments

Comments
 (0)