Java Code Examples for org.apache.hadoop.ha.HAServiceProtocol.HAServiceState#INITIALIZING

The following examples show how to use org.apache.hadoop.ha.HAServiceProtocol.HAServiceState#INITIALIZING . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MiniZKFCCluster.java    From hadoop with Apache License 2.0 6 votes vote down vote up
public MiniZKFCCluster(Configuration conf, ZooKeeperServer zks) {
  this.conf = conf;
  // Fast check interval so tests run faster
  conf.setInt(CommonConfigurationKeys.HA_HM_CHECK_INTERVAL_KEY, 50);
  conf.setInt(CommonConfigurationKeys.HA_HM_CONNECT_RETRY_INTERVAL_KEY, 50);
  conf.setInt(CommonConfigurationKeys.HA_HM_SLEEP_AFTER_DISCONNECT_KEY, 50);
  svcs = new DummyHAService[2];
  svcs[0] = new DummyHAService(HAServiceState.INITIALIZING,
      new InetSocketAddress("svc1", 1234));
  svcs[0].setSharedResource(sharedResource);
  svcs[1] = new DummyHAService(HAServiceState.INITIALIZING,
      new InetSocketAddress("svc2", 1234));
  svcs[1].setSharedResource(sharedResource);
  
  this.ctx = new TestContext();
  this.zks = zks;
}
 
Example 2
Source File: MiniZKFCCluster.java    From big-c with Apache License 2.0 6 votes vote down vote up
public MiniZKFCCluster(Configuration conf, ZooKeeperServer zks) {
  this.conf = conf;
  // Fast check interval so tests run faster
  conf.setInt(CommonConfigurationKeys.HA_HM_CHECK_INTERVAL_KEY, 50);
  conf.setInt(CommonConfigurationKeys.HA_HM_CONNECT_RETRY_INTERVAL_KEY, 50);
  conf.setInt(CommonConfigurationKeys.HA_HM_SLEEP_AFTER_DISCONNECT_KEY, 50);
  svcs = new DummyHAService[2];
  svcs[0] = new DummyHAService(HAServiceState.INITIALIZING,
      new InetSocketAddress("svc1", 1234));
  svcs[0].setSharedResource(sharedResource);
  svcs[1] = new DummyHAService(HAServiceState.INITIALIZING,
      new InetSocketAddress("svc2", 1234));
  svcs[1].setSharedResource(sharedResource);
  
  this.ctx = new TestContext();
  this.zks = zks;
}
 
Example 3
Source File: NameNode.java    From hadoop with Apache License 2.0 5 votes vote down vote up
synchronized HAServiceStatus getServiceStatus()
    throws ServiceFailedException, AccessControlException {
  namesystem.checkSuperuserPrivilege();
  if (!haEnabled) {
    throw new ServiceFailedException("HA for namenode is not enabled");
  }
  if (state == null) {
    return new HAServiceStatus(HAServiceState.INITIALIZING);
  }
  HAServiceState retState = state.getServiceState();
  HAServiceStatus ret = new HAServiceStatus(retState);
  if (retState == HAServiceState.STANDBY) {
    String safemodeTip = namesystem.getSafeModeTip();
    if (!safemodeTip.isEmpty()) {
      ret.setNotReadyToBecomeActive(
          "The NameNode is in safemode. " +
          safemodeTip);
    } else {
      ret.setReadyToBecomeActive();
    }
  } else if (retState == HAServiceState.ACTIVE) {
    ret.setReadyToBecomeActive();
  } else {
    ret.setNotReadyToBecomeActive("State is " + state);
  }
  return ret;
}
 
Example 4
Source File: ZKFailoverController.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private void doCedeActive(int millisToCede) 
    throws AccessControlException, ServiceFailedException, IOException {
  int timeout = FailoverController.getGracefulFenceTimeout(conf);

  // Lock elector to maintain lock ordering of elector -> ZKFC
  synchronized (elector) {
    synchronized (this) {
      if (millisToCede <= 0) {
        delayJoiningUntilNanotime = 0;
        recheckElectability();
        return;
      }

      LOG.info("Requested by " + UserGroupInformation.getCurrentUser() +
          " at " + Server.getRemoteAddress() + " to cede active role.");
      boolean needFence = false;
      try {
        localTarget.getProxy(conf, timeout).transitionToStandby(createReqInfo());
        LOG.info("Successfully ensured local node is in standby mode");
      } catch (IOException ioe) {
        LOG.warn("Unable to transition local node to standby: " +
            ioe.getLocalizedMessage());
        LOG.warn("Quitting election but indicating that fencing is " +
            "necessary");
        needFence = true;
      }
      delayJoiningUntilNanotime = System.nanoTime() +
          TimeUnit.MILLISECONDS.toNanos(millisToCede);
      elector.quitElection(needFence);
      serviceState = HAServiceState.INITIALIZING;
    }
  }
  recheckElectability();
}
 
Example 5
Source File: ZKFailoverController.java    From hadoop with Apache License 2.0 5 votes vote down vote up
void verifyChangedServiceState(HAServiceState changedState) {
  synchronized (elector) {
    synchronized (this) {
      if (serviceState == HAServiceState.INITIALIZING) {
        if (quitElectionOnBadState) {
          LOG.debug("rechecking for electability from bad state");
          recheckElectability();
        }
        return;
      }
      if (changedState == serviceState) {
        serviceStateMismatchCount = 0;
        return;
      }
      if (serviceStateMismatchCount == 0) {
        // recheck one more time. As this might be due to parallel transition.
        serviceStateMismatchCount++;
        return;
      }
      // quit the election as the expected state and reported state
      // mismatches.
      LOG.error("Local service " + localTarget
          + " has changed the serviceState to " + changedState
          + ". Expected was " + serviceState
          + ". Quitting election marking fencing necessary.");
      delayJoiningUntilNanotime = System.nanoTime()
          + TimeUnit.MILLISECONDS.toNanos(1000);
      elector.quitElection(true);
      quitElectionOnBadState = true;
      serviceStateMismatchCount = 0;
      serviceState = HAServiceState.INITIALIZING;
    }
  }
}
 
Example 6
Source File: NameNode.java    From big-c with Apache License 2.0 5 votes vote down vote up
synchronized HAServiceStatus getServiceStatus()
    throws ServiceFailedException, AccessControlException {
  namesystem.checkSuperuserPrivilege();
  if (!haEnabled) {
    throw new ServiceFailedException("HA for namenode is not enabled");
  }
  if (state == null) {
    return new HAServiceStatus(HAServiceState.INITIALIZING);
  }
  HAServiceState retState = state.getServiceState();
  HAServiceStatus ret = new HAServiceStatus(retState);
  if (retState == HAServiceState.STANDBY) {
    String safemodeTip = namesystem.getSafeModeTip();
    if (!safemodeTip.isEmpty()) {
      ret.setNotReadyToBecomeActive(
          "The NameNode is in safemode. " +
          safemodeTip);
    } else {
      ret.setReadyToBecomeActive();
    }
  } else if (retState == HAServiceState.ACTIVE) {
    ret.setReadyToBecomeActive();
  } else {
    ret.setNotReadyToBecomeActive("State is " + state);
  }
  return ret;
}
 
Example 7
Source File: ZKFailoverController.java    From big-c with Apache License 2.0 5 votes vote down vote up
private void doCedeActive(int millisToCede) 
    throws AccessControlException, ServiceFailedException, IOException {
  int timeout = FailoverController.getGracefulFenceTimeout(conf);

  // Lock elector to maintain lock ordering of elector -> ZKFC
  synchronized (elector) {
    synchronized (this) {
      if (millisToCede <= 0) {
        delayJoiningUntilNanotime = 0;
        recheckElectability();
        return;
      }

      LOG.info("Requested by " + UserGroupInformation.getCurrentUser() +
          " at " + Server.getRemoteAddress() + " to cede active role.");
      boolean needFence = false;
      try {
        localTarget.getProxy(conf, timeout).transitionToStandby(createReqInfo());
        LOG.info("Successfully ensured local node is in standby mode");
      } catch (IOException ioe) {
        LOG.warn("Unable to transition local node to standby: " +
            ioe.getLocalizedMessage());
        LOG.warn("Quitting election but indicating that fencing is " +
            "necessary");
        needFence = true;
      }
      delayJoiningUntilNanotime = System.nanoTime() +
          TimeUnit.MILLISECONDS.toNanos(millisToCede);
      elector.quitElection(needFence);
      serviceState = HAServiceState.INITIALIZING;
    }
  }
  recheckElectability();
}
 
Example 8
Source File: ZKFailoverController.java    From big-c with Apache License 2.0 5 votes vote down vote up
void verifyChangedServiceState(HAServiceState changedState) {
  synchronized (elector) {
    synchronized (this) {
      if (serviceState == HAServiceState.INITIALIZING) {
        if (quitElectionOnBadState) {
          LOG.debug("rechecking for electability from bad state");
          recheckElectability();
        }
        return;
      }
      if (changedState == serviceState) {
        serviceStateMismatchCount = 0;
        return;
      }
      if (serviceStateMismatchCount == 0) {
        // recheck one more time. As this might be due to parallel transition.
        serviceStateMismatchCount++;
        return;
      }
      // quit the election as the expected state and reported state
      // mismatches.
      LOG.error("Local service " + localTarget
          + " has changed the serviceState to " + changedState
          + ". Expected was " + serviceState
          + ". Quitting election marking fencing necessary.");
      delayJoiningUntilNanotime = System.nanoTime()
          + TimeUnit.MILLISECONDS.toNanos(1000);
      elector.quitElection(true);
      quitElectionOnBadState = true;
      serviceStateMismatchCount = 0;
      serviceState = HAServiceState.INITIALIZING;
    }
  }
}
 
Example 9
Source File: NameNode.java    From hadoop with Apache License 2.0 4 votes vote down vote up
synchronized HAServiceState getServiceState() {
  if (state == null) {
    return HAServiceState.INITIALIZING;
  }
  return state.getServiceState();
}
 
Example 10
Source File: ZKFailoverController.java    From hadoop with Apache License 2.0 4 votes vote down vote up
/**
 * Check the current state of the service, and join the election
 * if it should be in the election.
 */
private void recheckElectability() {
  // Maintain lock ordering of elector -> ZKFC
  synchronized (elector) {
    synchronized (this) {
      boolean healthy = lastHealthState == State.SERVICE_HEALTHY;
  
      long remainingDelay = delayJoiningUntilNanotime - System.nanoTime(); 
      if (remainingDelay > 0) {
        if (healthy) {
          LOG.info("Would have joined master election, but this node is " +
              "prohibited from doing so for " +
              TimeUnit.NANOSECONDS.toMillis(remainingDelay) + " more ms");
        }
        scheduleRecheck(remainingDelay);
        return;
      }
  
      switch (lastHealthState) {
      case SERVICE_HEALTHY:
        elector.joinElection(targetToData(localTarget));
        if (quitElectionOnBadState) {
          quitElectionOnBadState = false;
        }
        break;
        
      case INITIALIZING:
        LOG.info("Ensuring that " + localTarget + " does not " +
            "participate in active master election");
        elector.quitElection(false);
        serviceState = HAServiceState.INITIALIZING;
        break;
  
      case SERVICE_UNHEALTHY:
      case SERVICE_NOT_RESPONDING:
        LOG.info("Quitting master election for " + localTarget +
            " and marking that fencing is necessary");
        elector.quitElection(true);
        serviceState = HAServiceState.INITIALIZING;
        break;
        
      case HEALTH_MONITOR_FAILED:
        fatalError("Health monitor failed!");
        break;
        
      default:
        throw new IllegalArgumentException("Unhandled state:" + lastHealthState);
      }
    }
  }
}
 
Example 11
Source File: NameNode.java    From big-c with Apache License 2.0 4 votes vote down vote up
synchronized HAServiceState getServiceState() {
  if (state == null) {
    return HAServiceState.INITIALIZING;
  }
  return state.getServiceState();
}
 
Example 12
Source File: ZKFailoverController.java    From big-c with Apache License 2.0 4 votes vote down vote up
/**
 * Check the current state of the service, and join the election
 * if it should be in the election.
 */
private void recheckElectability() {
  // Maintain lock ordering of elector -> ZKFC
  synchronized (elector) {
    synchronized (this) {
      boolean healthy = lastHealthState == State.SERVICE_HEALTHY;
  
      long remainingDelay = delayJoiningUntilNanotime - System.nanoTime(); 
      if (remainingDelay > 0) {
        if (healthy) {
          LOG.info("Would have joined master election, but this node is " +
              "prohibited from doing so for " +
              TimeUnit.NANOSECONDS.toMillis(remainingDelay) + " more ms");
        }
        scheduleRecheck(remainingDelay);
        return;
      }
  
      switch (lastHealthState) {
      case SERVICE_HEALTHY:
        elector.joinElection(targetToData(localTarget));
        if (quitElectionOnBadState) {
          quitElectionOnBadState = false;
        }
        break;
        
      case INITIALIZING:
        LOG.info("Ensuring that " + localTarget + " does not " +
            "participate in active master election");
        elector.quitElection(false);
        serviceState = HAServiceState.INITIALIZING;
        break;
  
      case SERVICE_UNHEALTHY:
      case SERVICE_NOT_RESPONDING:
        LOG.info("Quitting master election for " + localTarget +
            " and marking that fencing is necessary");
        elector.quitElection(true);
        serviceState = HAServiceState.INITIALIZING;
        break;
        
      case HEALTH_MONITOR_FAILED:
        fatalError("Health monitor failed!");
        break;
        
      default:
        throw new IllegalArgumentException("Unhandled state:" + lastHealthState);
      }
    }
  }
}