File tree Expand file tree Collapse file tree 1 file changed +24
-17
lines changed
core/src/main/scala/org/apache/spark/storage Expand file tree Collapse file tree 1 file changed +24
-17
lines changed Original file line number Diff line number Diff line change @@ -128,16 +128,19 @@ private[spark] class DiskBlockObjectWriter(
128
128
*/
129
129
private def closeResources (): Unit = {
130
130
if (initialized) {
131
- mcs.manualClose()
132
- channel = null
133
- mcs = null
134
- bs = null
135
- fos = null
136
- ts = null
137
- objOut = null
138
- initialized = false
139
- streamOpen = false
140
- hasBeenClosed = true
131
+ Utils .tryWithSafeFinally {
132
+ mcs.manualClose()
133
+ } {
134
+ channel = null
135
+ mcs = null
136
+ bs = null
137
+ fos = null
138
+ ts = null
139
+ objOut = null
140
+ initialized = false
141
+ streamOpen = false
142
+ hasBeenClosed = true
143
+ }
141
144
}
142
145
}
143
146
@@ -206,18 +209,22 @@ private[spark] class DiskBlockObjectWriter(
206
209
streamOpen = false
207
210
closeResources()
208
211
}
212
+ } catch {
213
+ case e : Exception =>
214
+ logError(" Uncaught exception while closing file " + file, e)
215
+ }
209
216
210
- val truncateStream = new FileOutputStream (file, true )
211
- try {
212
- truncateStream.getChannel.truncate(committedPosition)
213
- file
214
- } finally {
215
- truncateStream.close()
216
- }
217
+ var truncateStream : FileOutputStream = null
218
+ try {
219
+ truncateStream = new FileOutputStream (file, true )
220
+ truncateStream.getChannel.truncate(committedPosition)
221
+ file
217
222
} catch {
218
223
case e : Exception =>
219
224
logError(" Uncaught exception while reverting partial writes to file " + file, e)
220
225
file
226
+ } finally {
227
+ truncateStream.close()
221
228
}
222
229
}
223
230
You can’t perform that action at this time.
0 commit comments