@@ -688,24 +688,13 @@ protected void doStop(@Nullable Runnable onReleaseLeadership,
688688 logger .info ("Stopped the worker threads" );
689689
690690 try {
691- if (logWatcher != null ) {
692- logger .info ("Closing the log watcher" );
693- // Wait for an in-flight replay: close() cancels its tasks with an interrupt.
694- // Releasing is safe because listenerInfo is null, so a new replay returns immediately.
695- synchronized (this ) {
696- logger .info ("Drained the log watcher; last replayed revision: {}" , lastReplayedRevision );
697- }
698- logWatcher .close ();
699- interrupted |= shutdown (logWatcherExecutor );
700- logger .info ("Closed the log watcher" );
691+ // A replay holds this monitor until it records its progress; close() would interrupt it.
692+ logger .info ("Waiting for an in-flight replay to finish" );
693+ synchronized (this ) {
694+ logger .info ("No replay in flight; last replayed revision: {}" , lastReplayedRevision );
695+ logger .info ("Stopping the delegate command executor" );
696+ delegate .stop ();
701697 }
702- } catch (Exception e ) {
703- logger .warn ("Failed to close the log watcher: {}" , e .getMessage (), e );
704- }
705-
706- try {
707- logger .info ("Stopping the delegate command executor" );
708- delegate .stop ();
709698 logger .info ("Stopped the delegate command executor" );
710699 } catch (Exception e ) {
711700 logger .warn ("Failed to stop the delegate command executor {}: {}" , delegate , e .getMessage (), e );
@@ -732,26 +721,37 @@ protected void doStop(@Nullable Runnable onReleaseLeadership,
732721 logger .warn ("Failed to close the zone {} leader selector: {}" , zone , e .getMessage (), e );
733722 } finally {
734723 try {
735- if (curator != null ) {
736- logger .info ("Closing the Curator framework" );
737- curator .close ();
738- logger .info ("Closed the Curator framework" );
724+ if (logWatcher != null ) {
725+ logger .info ("Closing the log watcher" );
726+ logWatcher .close ();
727+ interrupted |= shutdown (logWatcherExecutor );
728+ logger .info ("Closed the log watcher" );
739729 }
740730 } catch (Exception e ) {
741- logger .warn ("Failed to close the Curator framework : {}" , e .getMessage (), e );
731+ logger .warn ("Failed to close the log watcher : {}" , e .getMessage (), e );
742732 } finally {
743733 try {
744- if (quorumPeer != null ) {
745- final long peerId = quorumPeer .getId ();
746- logger .info ("Shutting down the ZooKeeper peer ({})" , peerId );
747- quorumPeer .shutdown ();
748- logger .info ("Shut down the ZooKeeper peer ({})" , peerId );
734+ if (curator != null ) {
735+ logger .info ("Closing the Curator framework" );
736+ curator .close ();
737+ logger .info ("Closed the Curator framework" );
749738 }
750739 } catch (Exception e ) {
751- logger .warn ("Failed to shut down the ZooKeeper peer : {}" , e .getMessage (), e );
740+ logger .warn ("Failed to close the Curator framework : {}" , e .getMessage (), e );
752741 } finally {
753- if (interrupted ) {
754- Thread .currentThread ().interrupt ();
742+ try {
743+ if (quorumPeer != null ) {
744+ final long peerId = quorumPeer .getId ();
745+ logger .info ("Shutting down the ZooKeeper peer ({})" , peerId );
746+ quorumPeer .shutdown ();
747+ logger .info ("Shut down the ZooKeeper peer ({})" , peerId );
748+ }
749+ } catch (Exception e ) {
750+ logger .warn ("Failed to shut down the ZooKeeper peer: {}" , e .getMessage (), e );
751+ } finally {
752+ if (interrupted ) {
753+ Thread .currentThread ().interrupt ();
754+ }
755755 }
756756 }
757757 }
0 commit comments