4747import org .elasticsearch .cluster .routing .allocation .decider .DiskThresholdDecider ;
4848import org .elasticsearch .cluster .service .ClusterApplierService ;
4949import org .elasticsearch .cluster .service .MasterService ;
50+ import org .elasticsearch .common .CheckedBiConsumer ;
5051import org .elasticsearch .common .UUIDs ;
5152import org .elasticsearch .common .io .stream .BytesStreamOutput ;
5253import org .elasticsearch .common .lucene .Lucene ;
@@ -794,18 +795,18 @@ public IndexShardState markAsRecovering(String reason, RecoveryState recoverySta
794795
795796 /**
796797 * Completes the relocation. Operations are blocked and current operations are drained before changing state to relocated. The provided
797- * {@link BiConsumer } is executed after all operations are successfully blocked.
798+ * {@link CheckedBiConsumer } is executed after all operations are successfully blocked.
798799 *
799- * @param consumer a {@link BiConsumer } that is executed after operations are blocked and that consumes the primary context as well as
800- * a listener to resolve once it finished
800+ * @param consumer a {@link CheckedBiConsumer } that is executed after operations are blocked and that consumes the primary context as
801+ * well as a listener to resolve once it finished
801802 * @param listener listener to resolve once this method actions including executing {@code consumer} in the non-failure case complete
802803 * @throws IllegalIndexShardStateException if the shard is not relocating due to concurrent cancellation
803804 * @throws IllegalStateException if the relocation target is no longer part of the replication group
804805 */
805806 public void relocated (
806807 final String targetNodeId ,
807808 final String targetAllocationId ,
808- final BiConsumer <ReplicationTracker .PrimaryContext , ActionListener <Void >> consumer ,
809+ final CheckedBiConsumer <ReplicationTracker .PrimaryContext , ActionListener <Void >, Exception > consumer ,
809810 final ActionListener <Void > listener
810811 ) throws IllegalIndexShardStateException , IllegalStateException {
811812 assert shardRouting .primary () : "only primaries can be marked as relocated: " + shardRouting ;
@@ -4638,12 +4639,14 @@ public void afterRefresh(boolean didRefresh) {
46384639 * @param postResetNewEngineConsumer A consumer that will be called with the newly created engine after the reset
46394640 * is complete, allowing for post-reset operations on the new engine instance.
46404641 * The provided engine reference should not be retained by the consumer.
4642+ * @throws Exception if reset could not be completed or previous engine could not be closed
46414643 */
4642- public void resetEngine (Consumer <Engine > postResetNewEngineConsumer ) {
4644+ public void resetEngine (Consumer <Engine > postResetNewEngineConsumer ) throws Exception {
46434645 assert Thread .holdsLock (mutex ) == false : "resetting engine under mutex" ;
46444646 assert waitForEngineOrClosedShardListeners .isDone ();
46454647 assert assertNoEngineResetLock ();
46464648 Engine previousEngine = null ;
4649+ Exception primaryException = null ;
46474650 try {
46484651 synchronized (engineMutex ) {
46494652 verifyNotClosed ();
@@ -4667,16 +4670,26 @@ public void resetEngine(Consumer<Engine> postResetNewEngineConsumer) {
46674670 } catch (Exception e ) {
46684671 // we want to fail the shard in the case prepareForEngineReset throws
46694672 failShard ("unable to reset engine" , e );
4673+ throw e ;
46704674 }
46714675 }
46724676 onSettingsChanged ();
4677+ } catch (Exception e ) {
4678+ primaryException = e ;
4679+ throw e ;
46734680 } finally {
46744681 if (previousEngine != null ) {
46754682 assert engineResetLock .isReadLockedByCurrentThread ();
46764683 try {
46774684 IOUtils .close (previousEngine );
46784685 } catch (Exception e ) {
46794686 failShard ("unable to close previous engine after reset" , e );
4687+
4688+ if (primaryException != null ) {
4689+ primaryException .addSuppressed (e );
4690+ } else {
4691+ throw e ;
4692+ }
46804693 } finally {
46814694 engineResetLock .readLock ().unlock ();
46824695 }
0 commit comments