protected boolean checkAllNodesAgreeToPowerOff(boolean forceSet){
  while (true) {
    try {
      publishNodePowerOffState(PowerOffState.State.NOTICED);
      poweroffAgreementsKeeper=new HashSet<>();
      if (!waitClusterPowerOffStateNotLessThan(PowerOffState.State.NOTICED,!forceSet)) {
        log.error("Failed to get {} signal from all other nodes",PowerOffState.State.NOTICED);
        return false;
      }
      publishNodePowerOffState(PowerOffState.State.ACKNOWLEDGED);
      if (!waitClusterPowerOffStateNotLessThan(PowerOffState.State.ACKNOWLEDGED,!forceSet)) {
        log.error("Failed to get {} signal from all other nodes",PowerOffState.State.ACKNOWLEDGED);
        return false;
      }
      publishNodePowerOffState(PowerOffState.State.POWEROFF);
      if (!waitClusterPowerOffStateNotLessThan(PowerOffState.State.POWEROFF,!forceSet)) {
        log.error("Failed to get {} signal from all other nodes",PowerOffState.State.POWEROFF);
        return false;
      }
      return true;
    }
 catch (    Exception e) {
      log.error("Step2: checkAllNodesAgreeToPowerOff failed: {} ",e);
    }
  }
}

protected boolean checkAllNodesAgreeToPowerOff ( boolean forceSet ) { while ( true ) { try { publishNodePowerOffState ( PowerOffState . State . NOTICED ) ; poweroffAgreementsKeeper = new HashSet < > ( ) ; if ( ! waitClusterPowerOffStateNotLessThan ( PowerOffState . State . NOTICED , ! forceSet ) ) { log . error ( "Failed to get {} signal from all other nodes" , PowerOffState . State . NOTICED ) ; return false ; } publishNodePowerOffState ( PowerOffState . State . ACKNOWLEDGED ) ; if ( ! waitClusterPowerOffStateNotLessThan ( PowerOffState . State . ACKNOWLEDGED , ! forceSet ) ) { log . error ( "Failed to get {} signal from all other nodes" , PowerOffState . State . ACKNOWLEDGED ) ; return false ; } publishNodePowerOffState ( PowerOffState . State . POWEROFF ) ; if ( ! waitClusterPowerOffStateNotLessThan ( PowerOffState . State . POWEROFF , ! forceSet ) ) { log . error ( "Failed to get {} signal from all other nodes" , PowerOffState . State . POWEROFF ) ; return false ; } return true ; } catch ( Exception e ) { log . error ( "Step2: checkAllNodesAgreeToPowerOff failed: {} " , e ) ; } } }
check all nodes agree to power off work flow : each node publishes noticed , then wait to see if all other nodes got the noticed . if true , continue to publish acknowledged ; if false , return false immediately . poweroff will fail . same for acknowledged . after a node see others have the acknowledged published , it can power off . if we let the node which first succeeded to see all acknowledged to power off first , other nodes may fail to see the acknowledged signal since the 1st node is shutting down . so we defined an extra state . poweroff state , which won ' t check the count of control nodes . nodes in poweroff state are free to poweroff .
