private void initHM() { healthMonitor = new HealthMonitor(conf, localTarget); healthMonitor.addCallback(new HealthCallbacks()); healthMonitor.addServiceStateCallback(new ServiceStateCallBacks()); healthMonitor.start(); }
@Override public void reportServiceStatus(HAServiceStatus status) { verifyChangedServiceState(status.getState()); } }
protected void initRPC() throws IOException { InetSocketAddress bindAddr = getRpcAddressToBindTo(); rpcServer = new ZKFCRpcServer(conf, bindAddr, this, getPolicyProvider()); }
private int getServiceState(final CommandLine cmd) throws IOException, ServiceFailedException { String[] argv = cmd.getArgs(); if (argv.length != 1) { errOut.println("getServiceState: incorrect number of arguments"); printUsage(errOut, "-getServiceState"); return -1; } HAServiceProtocol proto = resolveTarget(argv[0]).getProxy( getConf(), rpcTimeoutForChecks); out.println(proto.getServiceStatus().getState()); return 0; }
private synchronized void fenceOldActive(byte[] data) { HAServiceTarget target = dataToTarget(data); try { doFence(target); } catch (Throwable t) { recordActiveAttempt(new ActiveAttemptRecord(false, "Unable to fence old active: " + StringUtils.stringifyException(t))); throw t; } }
/** * 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"); } }
/** * @return a proxy to connect to the target HA Service. */ public HAServiceProtocol getProxy(Configuration conf, int timeoutMs) throws IOException { return getProxyForAddress(conf, timeoutMs, getAddress()); }
@Override public void gracefulFailover() throws IOException, AccessControlException { zkfc.checkRpcAdminAccess(); zkfc.gracefulFailoverToYou(); }
private MonitorDaemon() { super(); setName("Health Monitor for " + targetToMonitor); setUncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) { LOG.error("Health monitor failed", e); enterState(HealthMonitor.State.HEALTH_MONITOR_FAILED); } }); }
@Override public void cedeActive(int millisToCede) throws IOException, AccessControlException { zkfc.checkRpcAdminAccess(); zkfc.cedeActive(millisToCede); }
private byte[] getDataWithRetries(final String path, final boolean watch, final Stat stat) throws InterruptedException, KeeperException { return zkDoWithRetries(new ZKAction<byte[]>() { @Override public byte[] run() throws KeeperException, InterruptedException { return zkClient.getData(path, watch, stat); } }); }
/** * Verify that the argument, if given, in the conf is parseable. */ @Override public void checkArgs(String argStr) throws BadFencingConfigurationException { if (argStr != null) { new Args(argStr); } }
private synchronized void setLastServiceStatus(HAServiceStatus status) { this.lastServiceState = status; for (ServiceStateCallback cb : serviceStateCallbacks) { cb.reportServiceStatus(lastServiceState); } }
/** * We failed to become active. Re-join the election, but * sleep for a few seconds after terminating our existing * session, so that other nodes have a chance to become active. * The failure to become active is already logged inside * becomeActive(). */ private void reJoinElectionAfterFailureToBecomeActive() { reJoinElection(SLEEP_AFTER_FAILURE_TO_BECOME_ACTIVE); }
public String getHAZookeeperConnectionState() { return this.zkConnectionState.name(); } }
@Override public void enteredState(HealthMonitor.State newState) { setLastHealthState(newState); recheckElectability(); } }
/** * Connect to the service to be monitored. Stubbed out for easier testing. */ protected HAServiceProtocol createProxy() throws IOException { return targetToMonitor.getHealthMonitorProxy(conf, rpcTimeout); }
private String createWithRetries(final String path, final byte[] data, final List<ACL> acl, final CreateMode mode) throws InterruptedException, KeeperException { return zkDoWithRetries(new ZKAction<String>() { @Override public String run() throws KeeperException, InterruptedException { return zkClient.create(path, data, acl, mode); } }); }
private Stat setDataWithRetries(final String path, final byte[] data, final int version) throws InterruptedException, KeeperException { return zkDoWithRetries(new ZKAction<Stat>() { @Override public Stat run() throws KeeperException, InterruptedException { return zkClient.setData(path, data, version); } }); }
private void deleteWithRetries(final String path, final int version) throws KeeperException, InterruptedException { zkDoWithRetries(new ZKAction<Void>() { @Override public Void run() throws KeeperException, InterruptedException { zkClient.delete(path, version); return null; } }); }