java/openmldb-taskmanager/src/main/java/com/_4paradigm/openmldb/taskmanager/zk/FailoverWatcher.java
private void handleMasterNodeChange() {
    try {
      synchronized (hasActiveServer) {
        if (ZooKeeperUtil.watchAndCheckExists(this, masterZnode)) {
          // A master node exists, there is an active master
          if (LOG.isDebugEnabled()) {
            LOG.debug("A master is now available");
          }
          hasActiveServer.set(true);
        } else {
          // Node is no longer there, cluster does not have an active master
          if (LOG.isDebugEnabled()) {
            LOG.debug("No master available. Notifying waiting threads");
          }
          hasActiveServer.set(false);
          // Notify any thread waiting to become the active master
          hasActiveServer.notifyAll();
        }
      }
    } catch (KeeperException ke) {
      LOG.error("Received an unexpected KeeperException, aborting", ke);
    }
  }
/**
   * Implement the logic of leader election.
   */
Implement the logic of leader election.
Implement the logic of leader election .
private void handleMasterNodeChange() {
    try {
      synchronized (hasActiveServer) {
        if (ZooKeeperUtil.watchAndCheckExists(this, masterZnode)) {
          if (LOG.isDebugEnabled()) {
            LOG.debug("A master is now available");
          }
          hasActiveServer.set(true);
        } else {
          if (LOG.isDebugEnabled()) {
            LOG.debug("No master available. Notifying waiting threads");
          }
          hasActiveServer.set(false);
          hasActiveServer.notifyAll();
        }
      }
    } catch (KeeperException ke) {
      LOG.error("Received an unexpected KeeperException, aborting", ke);
    }
  }
private void handleMasterNodeChange ( ) { try { synchronized ( hasActiveServer ) { if ( ZooKeeperUtil . watchAndCheckExists ( this , masterZnode ) ) { if ( LOG . isDebugEnabled ( ) ) { LOG . debug ( "A master is now available" ) ; } hasActiveServer . set ( true ) ; } else { if ( LOG . isDebugEnabled ( ) ) { LOG . debug ( "No master available. Notifying waiting threads" ) ; } hasActiveServer . set ( false ) ; hasActiveServer . notifyAll ( ) ; } } } catch ( KeeperException ke ) { LOG . error ( "Received an unexpected KeeperException, aborting" , ke ) ; } }
Implement the logic of leader election.
Implement the logic of leader election .
// A master node exists, there is an active master // Node is no longer there, cluster does not have an active master // Notify any thread waiting to become the active master