@@ -532,7 +532,11 @@ public void close() {
532532 }
533533
534534 void close (Throwable cause , boolean allServers ) {
535- notifyServerShutdownInitiated (allServers );
535+ // A division closed before its role is initialized has no role info to report.
536+ if (role .getCurrentRole () != null && shutdownInitiatedNotified .compareAndSet (false , true )) {
537+ getStateMachine ().event ().notifyServerShutdown (getRoleInfoProto (), allServers ,
538+ StateMachine .EventStatus .INITIATED );
539+ }
536540
537541 final State newState = lifeCycle .transition (current -> current .isClosingOrClosed () ? current
538542 : current == State .NEW ? State .CLOSED : State .CLOSING );
@@ -761,26 +765,6 @@ RoleInfoProto getRoleInfoProto() {
761765 return role .buildRoleInfoProto (this );
762766 }
763767
764- /**
765- * Notify the {@link StateMachine} that this division is about to be closed, before {@link #close()} starts
766- * releasing any resources. Note that {@link #close()} waits for the committed entries to be applied,
767- * which is unbounded in time, so this is the only shutdown notification with a bounded delay.
768- * <p>
769- * {@link #close()} may be invoked more than once; the {@link StateMachine} is notified only once.
770- */
771- private void notifyServerShutdownInitiated (boolean allServers ) {
772- // A division closed before its role is initialized has no role info to report.
773- if (role .getCurrentRole () == null || !shutdownInitiatedNotified .compareAndSet (false , true )) {
774- return ;
775- }
776- try {
777- stateMachine .event ().notifyServerShutdown (getRoleInfoProto (), allServers , StateMachine .EventStatus .INITIATED );
778- } catch (Throwable t ) {
779- LOG .warn ("{}: Failed to notify {} that the shutdown has been initiated" ,
780- getMemberId (), JavaUtils .getClassSimpleName (stateMachine .getClass ()), t );
781- }
782- }
783-
784768 synchronized void changeToCandidate (boolean forceStartLeaderElection ) {
785769 Preconditions .assertTrue (getInfo ().isFollower ());
786770 role .shutdownFollowerState ();
0 commit comments