@@ -164,16 +164,20 @@ public Exception getTragicException() {
164
164
return tragedy ;
165
165
}
166
166
167
- private synchronized void closeWithTragicEvent (Exception exception ) throws IOException {
168
- assert exception != null ;
167
+ private synchronized void closeWithTragicEvent (final Exception ex ) {
168
+ assert ex != null ;
169
169
if (tragedy == null ) {
170
- tragedy = exception ;
171
- } else if (tragedy != exception ) {
170
+ tragedy = ex ;
171
+ } else if (tragedy != ex ) {
172
172
// it should be safe to call closeWithTragicEvents on multiple layers without
173
173
// worrying about self suppression.
174
- tragedy .addSuppressed (exception );
174
+ tragedy .addSuppressed (ex );
175
+ }
176
+ try {
177
+ close ();
178
+ } catch (final IOException | RuntimeException e ) {
179
+ ex .addSuppressed (e );
175
180
}
176
- close ();
177
181
}
178
182
179
183
/**
@@ -194,11 +198,7 @@ public synchronized Translog.Location add(final BytesReference data, final long
194
198
try {
195
199
data .writeTo (outputStream );
196
200
} catch (final Exception ex ) {
197
- try {
198
- closeWithTragicEvent (ex );
199
- } catch (final Exception inner ) {
200
- ex .addSuppressed (inner );
201
- }
201
+ closeWithTragicEvent (ex );
202
202
throw ex ;
203
203
}
204
204
totalOffset += data .length ();
@@ -290,13 +290,9 @@ public TranslogReader closeIntoReader() throws IOException {
290
290
synchronized (this ) {
291
291
try {
292
292
sync (); // sync before we close..
293
- } catch (IOException e ) {
294
- try {
295
- closeWithTragicEvent (e );
296
- } catch (Exception inner ) {
297
- e .addSuppressed (inner );
298
- }
299
- throw e ;
293
+ } catch (final Exception ex ) {
294
+ closeWithTragicEvent (ex );
295
+ throw ex ;
300
296
}
301
297
if (closed .compareAndSet (false , true )) {
302
298
return new TranslogReader (getLastSyncedCheckpoint (), channel , path , getFirstOperationOffset ());
@@ -346,12 +342,8 @@ public boolean syncUpTo(long offset) throws IOException {
346
342
try {
347
343
outputStream .flush ();
348
344
checkpointToSync = getCheckpoint ();
349
- } catch (Exception ex ) {
350
- try {
351
- closeWithTragicEvent (ex );
352
- } catch (Exception inner ) {
353
- ex .addSuppressed (inner );
354
- }
345
+ } catch (final Exception ex ) {
346
+ closeWithTragicEvent (ex );
355
347
throw ex ;
356
348
}
357
349
}
@@ -360,12 +352,8 @@ public boolean syncUpTo(long offset) throws IOException {
360
352
try {
361
353
channel .force (false );
362
354
writeCheckpoint (channelFactory , path .getParent (), checkpointToSync );
363
- } catch (Exception ex ) {
364
- try {
365
- closeWithTragicEvent (ex );
366
- } catch (Exception inner ) {
367
- ex .addSuppressed (inner );
368
- }
355
+ } catch (final Exception ex ) {
356
+ closeWithTragicEvent (ex );
369
357
throw ex ;
370
358
}
371
359
assert lastSyncedCheckpoint .offset <= checkpointToSync .offset :
@@ -392,13 +380,9 @@ protected void readBytes(ByteBuffer targetBuffer, long position) throws IOExcept
392
380
}
393
381
}
394
382
}
395
- } catch (final IOException e ) {
396
- try {
397
- closeWithTragicEvent (e );
398
- } catch (final IOException inner ) {
399
- e .addSuppressed (inner );
400
- }
401
- throw e ;
383
+ } catch (final Exception ex ) {
384
+ closeWithTragicEvent (ex );
385
+ throw ex ;
402
386
}
403
387
// we don't have to have a lock here because we only write ahead to the file, so all writes has been complete
404
388
// for the requested location.
@@ -451,12 +435,8 @@ public synchronized void flush() throws IOException {
451
435
try {
452
436
ensureOpen ();
453
437
super .flush ();
454
- } catch (Exception ex ) {
455
- try {
456
- closeWithTragicEvent (ex );
457
- } catch (Exception inner ) {
458
- ex .addSuppressed (inner );
459
- }
438
+ } catch (final Exception ex ) {
439
+ closeWithTragicEvent (ex );
460
440
throw ex ;
461
441
}
462
442
}
0 commit comments