@@ -322,7 +322,7 @@ public void doRun() throws Exception {
322322 // OK to ignore. This is what Lucene's ConcurrentMergeScheduler does
323323 } else if (t instanceof Exception == false ) {
324324 // onFailure and onAfter should better be called for Errors too
325- throw new RuntimeException (t );
325+ throw new ExceptionWrappingError (t );
326326 } else {
327327 throw t ;
328328 }
@@ -331,8 +331,10 @@ public void doRun() throws Exception {
331331
332332 @ Override
333333 public void onAfter () {
334- assert isAutoThrottle == false || activeThrottledMergeTasksAcrossSchedulersSet .contains (this )
335- : "onAfter should always be invoked on active (and run) merges" ;
334+ assert onGoingMerge .getMerge ().isAborted ()
335+ || isAutoThrottle == false
336+ || activeThrottledMergeTasksAcrossSchedulersSet .contains (this )
337+ : "onAfter should always be invoked on aborted or active (and run) merges" ;
336338 assert this .mergeStartTimeNS .get () != null : "onAfter should always be invoked after doRun" ;
337339 try {
338340 if (verbose ()) {
@@ -376,7 +378,7 @@ public void onFailure(Exception e) {
376378 // but keep this in case something believes calling `MergeTask#onFailure` is a sane way to abort a merge
377379 abortOnGoingMerge ();
378380 mergeDone (this );
379- handleMergeException (e );
381+ handleMergeException (ExceptionWrappingError . maybeUnwrapCause ( e ) );
380382 }
381383
382384 @ Override
@@ -446,4 +448,17 @@ private static String rateToString(double mbPerSec) {
446448 return String .format (Locale .ROOT , "%.1f MB/sec" , mbPerSec );
447449 }
448450 }
451+
452+ private static class ExceptionWrappingError extends RuntimeException {
453+ private static Throwable maybeUnwrapCause (Exception e ) {
454+ if (e instanceof ExceptionWrappingError exceptionWrappingError ) {
455+ return exceptionWrappingError .getCause ();
456+ }
457+ return e ;
458+ }
459+
460+ private ExceptionWrappingError (Throwable errorCause ) {
461+ super (errorCause );
462+ }
463+ }
449464}
0 commit comments