/** * Ensure that the local node is in a healthy state, and thus * eligible for graceful failover. * @throws ServiceFailedException if the node is unhealthy */ private synchronized void checkEligibleForFailover() throws ServiceFailedException { // Check health if (this.getLastHealthState() != State.SERVICE_HEALTHY) { throw new ServiceFailedException( localTarget + " is not currently healthy. " + "Cannot be failover target"); } }
throw new ServiceFailedException( "No other node is currently active."); throw new ServiceFailedException("Unable to become active. " + "Service became unhealthy while trying to failover."); throw new ServiceFailedException("Unable to become active. " + "Local node did not get an opportunity to do so from ZooKeeper, " + "or the local node took too long to transition to active."); throw new ServiceFailedException(msg);
throw (ServiceFailedException)t; } else { throw new ServiceFailedException("Couldn't transition to active", t);
/** * Move from the existing state to a new state * @param context HA context * @param s new state * @throws ServiceFailedException on failure to transition to new state. */ public void setState(HAContext context, HAState s) throws ServiceFailedException { if (this == s) { // Aleady in the new state return; } throw new ServiceFailedException("Transtion from state " + this + " to " + s + " is not allowed."); }
@Override public void exitState(HAContext context) throws ServiceFailedException { try { context.stopActiveServices(); } catch (IOException e) { throw new ServiceFailedException("Failed to stop active services", e); } }
@Override public void exitState(HAContext context) throws ServiceFailedException { try { context.stopStandbyServices(); } catch (IOException e) { throw new ServiceFailedException("Failed to stop standby services", e); } }
@Override public void enterState(HAContext context) throws ServiceFailedException { try { context.startActiveServices(); } catch (IOException e) { throw new ServiceFailedException("Failed to start active services", e); } }
@Override // HAState public void enterState(HAContext context) throws ServiceFailedException { try { context.startActiveServices(); } catch (IOException e) { throw new ServiceFailedException("Failed to start backup services", e); } }
@Override // HAState public void exitState(HAContext context) throws ServiceFailedException { try { context.stopActiveServices(); } catch (IOException e) { throw new ServiceFailedException("Failed to stop backup services", e); } }
@Override public void enterState(HAContext context) throws ServiceFailedException { try { context.startStandbyServices(); } catch (IOException e) { throw new ServiceFailedException("Failed to start standby services", e); } }
synchronized void transitionToStandby() throws ServiceFailedException, AccessControlException { namesystem.checkSuperuserPrivilege(); if (!haEnabled) { throw new ServiceFailedException("HA for namenode is not enabled"); } state.setState(haContext, STANDBY_STATE); }
synchronized void transitionToActive() throws ServiceFailedException, AccessControlException { namesystem.checkSuperuserPrivilege(); if (!haEnabled) { throw new ServiceFailedException("HA for namenode is not enabled"); } state.setState(haContext, ACTIVE_STATE); }
synchronized HAServiceStatus getServiceStatus() throws ServiceFailedException, AccessControlException { 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) { if (namesystem.isInSafeMode()) { ret.setNotReadyToBecomeActive("The NameNode is in safemode. " + namesystem.getSafeModeTip()); } else { ret.setReadyToBecomeActive(); } } else if (retState == HAServiceState.ACTIVE) { ret.setReadyToBecomeActive(); } else { ret.setNotReadyToBecomeActive("State is " + state); } return ret; }
@Override public void exitState(HAContext context) throws ServiceFailedException { try { context.stopStandbyServices(); } catch (IOException e) { throw new ServiceFailedException("Failed to stop standby services", e); } }
@Override public void exitState(HAContext context) throws ServiceFailedException { try { context.stopStandbyServices(); } catch (IOException e) { throw new ServiceFailedException("Failed to stop standby services", e); } }
synchronized void transitionToStandby() throws ServiceFailedException, AccessControlException { namesystem.checkSuperuserPrivilege(); if (!haEnabled) { throw new ServiceFailedException("HA for namenode is not enabled"); } state.setState(haContext, STANDBY_STATE); }
@Override public void becomeActive() throws ServiceFailedException { try { rmContext.getRMAdminService().transitionToActive(req); } catch (Exception e) { throw new ServiceFailedException("RM could not transition to Active", e); } }
synchronized void transitionToStandby() throws ServiceFailedException, AccessControlException { namesystem.checkSuperuserPrivilege(); if (!haEnabled) { throw new ServiceFailedException("HA for namenode is not enabled"); } state.setState(haContext, STANDBY_STATE); }
@Override public void becomeActive() throws ServiceFailedException { cancelDisconnectTimer(); try { rm.getRMContext().getRMAdminService().transitionToActive(req); } catch (Exception e) { throw new ServiceFailedException("RM could not transition to Active", e); } }
@Override public void transitionToStandby(StateChangeRequestInfo req) throws ServiceFailedException, AccessControlException, IOException { checkUnreachable(); if (failToBecomeStandby) { throw new ServiceFailedException("injected failure"); } if (sharedResource != null) { sharedResource.release(DummyHAService.this); } state = HAServiceState.STANDBY; }