gpt4 book ai didi

org.apache.hadoop.ha.ZKFCProtocol.gracefulFailover()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-14 02:58:49 26 4
gpt4 key购买 nike

本文整理了Java中org.apache.hadoop.ha.ZKFCProtocol.gracefulFailover()方法的一些代码示例,展示了ZKFCProtocol.gracefulFailover()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZKFCProtocol.gracefulFailover()方法的具体详情如下:
包路径:org.apache.hadoop.ha.ZKFCProtocol
类名称:ZKFCProtocol
方法名:gracefulFailover

ZKFCProtocol.gracefulFailover介绍

[英]Request that this node try to become active through a graceful failover. If the node is already active, this is a no-op and simply returns success without taking any further action. If the node is not healthy, it will throw an exception indicating that it is not able to become active. If the node is healthy and not active, it will try to initiate a graceful failover to become active, returning only when it has successfully become active. See ZKFailoverController#gracefulFailoverToYou() for the implementation details. If the node fails to successfully coordinate the failover, throws an exception indicating the reason for failure.
[中]请求此节点尝试通过优雅的故障切换变为活动状态。如果节点已经处于活动状态,则这是一个不操作,只返回success而不采取任何进一步的操作。如果节点不健康,它将抛出一个异常,指示它无法变为活动状态。如果节点运行正常且未处于活动状态,它将尝试启动正常的故障切换以变为活动状态,仅当节点成功变为活动状态时才会返回。有关实现的详细信息,请参见ZKFailoverController#gracefulFailoverToYou()。如果节点未能成功协调故障转移,将引发一个异常,指明故障原因。

代码示例

代码示例来源:origin: org.apache.hadoop/hadoop-common

@Override
public GracefulFailoverResponseProto gracefulFailover(
  RpcController controller, GracefulFailoverRequestProto request)
  throws ServiceException {
 try {
  server.gracefulFailover();
  return GracefulFailoverResponseProto.getDefaultInstance();
 } catch (IOException e) {
  throw new ServiceException(e);
 }
}

代码示例来源:origin: org.apache.hadoop/hadoop-common

/**
 * Initiate a graceful failover by talking to the target node's ZKFC.
 * This sends an RPC to the ZKFC, which coordinates the failover.
 * 
 * @param toNode the node to fail to
 * @return status code (0 for success)
 * @throws IOException if failover does not succeed
 */
private int gracefulFailoverThroughZKFCs(HAServiceTarget toNode)
  throws IOException {
 int timeout = FailoverController.getRpcTimeoutToNewActive(getConf());
 ZKFCProtocol proxy = toNode.getZKFCProxy(getConf(), timeout);
 try {
  proxy.gracefulFailover();
  out.println("Failover to " + toNode + " successful");
 } catch (ServiceFailedException sfe) {
  errOut.println("Failover failed: " + sfe.getLocalizedMessage());
  return -1;
 }
 return 0;
}

代码示例来源:origin: ch.cern.hadoop/hadoop-common

@Override
public GracefulFailoverResponseProto gracefulFailover(
  RpcController controller, GracefulFailoverRequestProto request)
  throws ServiceException {
 try {
  server.gracefulFailover();
  return GracefulFailoverResponseProto.getDefaultInstance();
 } catch (IOException e) {
  throw new ServiceException(e);
 }
}

代码示例来源:origin: io.hops/hadoop-common

@Override
public GracefulFailoverResponseProto gracefulFailover(
  RpcController controller, GracefulFailoverRequestProto request)
  throws ServiceException {
 try {
  server.gracefulFailover();
  return GracefulFailoverResponseProto.getDefaultInstance();
 } catch (IOException e) {
  throw new ServiceException(e);
 }
}

代码示例来源:origin: io.prestosql.hadoop/hadoop-apache

@Override
public GracefulFailoverResponseProto gracefulFailover(
  RpcController controller, GracefulFailoverRequestProto request)
  throws ServiceException {
 try {
  server.gracefulFailover();
  return GracefulFailoverResponseProto.getDefaultInstance();
 } catch (IOException e) {
  throw new ServiceException(e);
 }
}

代码示例来源:origin: com.github.jiayuhan-it/hadoop-common

@Override
public GracefulFailoverResponseProto gracefulFailover(
  RpcController controller, GracefulFailoverRequestProto request)
  throws ServiceException {
 try {
  server.gracefulFailover();
  return GracefulFailoverResponseProto.getDefaultInstance();
 } catch (IOException e) {
  throw new ServiceException(e);
 }
}

代码示例来源:origin: io.prestosql.hadoop/hadoop-apache

/**
 * Initiate a graceful failover by talking to the target node's ZKFC.
 * This sends an RPC to the ZKFC, which coordinates the failover.
 * 
 * @param toNode the node to fail to
 * @return status code (0 for success)
 * @throws IOException if failover does not succeed
 */
private int gracefulFailoverThroughZKFCs(HAServiceTarget toNode)
  throws IOException {
 int timeout = FailoverController.getRpcTimeoutToNewActive(getConf());
 ZKFCProtocol proxy = toNode.getZKFCProxy(getConf(), timeout);
 try {
  proxy.gracefulFailover();
  out.println("Failover to " + toNode + " successful");
 } catch (ServiceFailedException sfe) {
  errOut.println("Failover failed: " + sfe.getLocalizedMessage());
  return -1;
 }
 return 0;
}

代码示例来源:origin: io.hops/hadoop-common

/**
 * Initiate a graceful failover by talking to the target node's ZKFC.
 * This sends an RPC to the ZKFC, which coordinates the failover.
 * 
 * @param toNode the node to fail to
 * @return status code (0 for success)
 * @throws IOException if failover does not succeed
 */
private int gracefulFailoverThroughZKFCs(HAServiceTarget toNode)
  throws IOException {
 int timeout = FailoverController.getRpcTimeoutToNewActive(getConf());
 ZKFCProtocol proxy = toNode.getZKFCProxy(getConf(), timeout);
 try {
  proxy.gracefulFailover();
  out.println("Failover to " + toNode + " successful");
 } catch (ServiceFailedException sfe) {
  errOut.println("Failover failed: " + sfe.getLocalizedMessage());
  return -1;
 }
 return 0;
}

代码示例来源:origin: ch.cern.hadoop/hadoop-common

/**
 * Initiate a graceful failover by talking to the target node's ZKFC.
 * This sends an RPC to the ZKFC, which coordinates the failover.
 * 
 * @param toNode the node to fail to
 * @return status code (0 for success)
 * @throws IOException if failover does not succeed
 */
private int gracefulFailoverThroughZKFCs(HAServiceTarget toNode)
  throws IOException {
 int timeout = FailoverController.getRpcTimeoutToNewActive(getConf());
 ZKFCProtocol proxy = toNode.getZKFCProxy(getConf(), timeout);
 try {
  proxy.gracefulFailover();
  out.println("Failover to " + toNode + " successful");
 } catch (ServiceFailedException sfe) {
  errOut.println("Failover failed: " + sfe.getLocalizedMessage());
  return -1;
 }
 return 0;
}

代码示例来源:origin: com.github.jiayuhan-it/hadoop-common

/**
 * Initiate a graceful failover by talking to the target node's ZKFC.
 * This sends an RPC to the ZKFC, which coordinates the failover.
 * 
 * @param toNode the node to fail to
 * @return status code (0 for success)
 * @throws IOException if failover does not succeed
 */
private int gracefulFailoverThroughZKFCs(HAServiceTarget toNode)
  throws IOException {
 int timeout = FailoverController.getRpcTimeoutToNewActive(getConf());
 ZKFCProtocol proxy = toNode.getZKFCProxy(getConf(), timeout);
 try {
  proxy.gracefulFailover();
  out.println("Failover to " + toNode + " successful");
 } catch (ServiceFailedException sfe) {
  errOut.println("Failover failed: " + sfe.getLocalizedMessage());
  return -1;
 }
 return 0;
}

代码示例来源:origin: ch.cern.hadoop/hadoop-hdfs

@Test
public void testFailoverWithAutoHa() throws Exception {
 Mockito.doReturn(STANDBY_READY_RESULT).when(mockProtocol).getServiceStatus();
 // Turn on auto-HA in the config
 HdfsConfiguration conf = getHAConf();
 conf.setBoolean(DFSConfigKeys.DFS_HA_AUTO_FAILOVER_ENABLED_KEY, true);
 conf.set(DFSConfigKeys.DFS_HA_FENCE_METHODS_KEY, getFencerTrueCommand());
 tool.setConf(conf);
 assertEquals(0, runTool("-failover", "nn1", "nn2"));
 Mockito.verify(mockZkfcProtocol).gracefulFailover();
}

代码示例来源:origin: ch.cern.hadoop/hadoop-hdfs

@Test(timeout=30000)
public void testManualFailover() throws Exception {
 thr2.zkfc.getLocalTarget().getZKFCProxy(conf, 15000).gracefulFailover();
 waitForHAState(0, HAServiceState.STANDBY);
 waitForHAState(1, HAServiceState.ACTIVE);
 thr1.zkfc.getLocalTarget().getZKFCProxy(conf, 15000).gracefulFailover();
 waitForHAState(0, HAServiceState.ACTIVE);
 waitForHAState(1, HAServiceState.STANDBY);
}

代码示例来源:origin: ch.cern.hadoop/hadoop-common

@Test
public void testGracefulFailover() throws Exception {
 cluster.start();
 cluster.waitForActiveLockHolder(0);
 cluster.getService(1).getZKFCProxy(conf, 5000).gracefulFailover();
 cluster.waitForActiveLockHolder(1);
 cluster.getService(0).getZKFCProxy(conf, 5000).gracefulFailover();
 cluster.waitForActiveLockHolder(0);
 Thread.sleep(10000); // allow to quiesce
 assertEquals(0, cluster.getService(0).fenceCount);
 assertEquals(0, cluster.getService(1).fenceCount);
 assertEquals(2, cluster.getService(0).activeTransitionCount);
 assertEquals(1, cluster.getService(1).activeTransitionCount);
}

代码示例来源:origin: ch.cern.hadoop/hadoop-common

@Test
public void testGracefulFailoverFailBecomingStandby() throws Exception {
 cluster.start();
 cluster.waitForActiveLockHolder(0);
 // Ask for failover when old node fails to transition to standby.
 // This should trigger fencing, since the cedeActive() command
 // still works, but leaves the breadcrumb in place.
 cluster.setFailToBecomeStandby(0, true);
 cluster.getService(1).getZKFCProxy(conf, 5000).gracefulFailover();
 // Check that the old node was fenced
 assertEquals(1, cluster.getService(0).fenceCount);
}

代码示例来源:origin: com.github.jiayuhan-it/hadoop-common

@Test(timeout=25000)
public void testGracefulFailover() throws Exception {
 try {
  cluster.start();
  cluster.waitForActiveLockHolder(0);
  cluster.getService(1).getZKFCProxy(conf, 5000).gracefulFailover();
  cluster.waitForActiveLockHolder(1);
  cluster.getService(0).getZKFCProxy(conf, 5000).gracefulFailover();
  cluster.waitForActiveLockHolder(0);
  Thread.sleep(10000); // allow to quiesce
  assertEquals(0, cluster.getService(0).fenceCount);
  assertEquals(0, cluster.getService(1).fenceCount);
  assertEquals(2, cluster.getService(0).activeTransitionCount);
  assertEquals(1, cluster.getService(1).activeTransitionCount);
 } finally {
  cluster.stop();
 }
}

代码示例来源:origin: com.github.jiayuhan-it/hadoop-common

@Test(timeout=15000)
public void testGracefulFailoverFailBecomingStandby() throws Exception {
 try {
  cluster.start();
  cluster.waitForActiveLockHolder(0);
  
  // Ask for failover when old node fails to transition to standby.
  // This should trigger fencing, since the cedeActive() command
  // still works, but leaves the breadcrumb in place.
  cluster.setFailToBecomeStandby(0, true);
  cluster.getService(1).getZKFCProxy(conf, 5000).gracefulFailover();
  // Check that the old node was fenced
  assertEquals(1, cluster.getService(0).fenceCount);
 } finally {
  cluster.stop();
 }
}

代码示例来源:origin: ch.cern.hadoop/hadoop-common

@Test
public void testGracefulFailoverFailBecomingStandbyAndFailFence()
 throws Exception {
 cluster.start();
 cluster.waitForActiveLockHolder(0);
 // Ask for failover when old node fails to transition to standby.
 // This should trigger fencing, since the cedeActive() command
 // still works, but leaves the breadcrumb in place.
 cluster.setFailToBecomeStandby(0, true);
 cluster.setFailToFence(0, true);
 try {
  cluster.getService(1).getZKFCProxy(conf, 5000).gracefulFailover();
  fail("Failover should have failed when old node wont fence");
 } catch (ServiceFailedException sfe) {
  GenericTestUtils.assertExceptionContains(
    "Unable to fence " + cluster.getService(0), sfe);
 }
}

代码示例来源:origin: ch.cern.hadoop/hadoop-common

@Test
public void testGracefulFailoverToUnhealthy() throws Exception {
 cluster.start();
 cluster.waitForActiveLockHolder(0);
 // Mark it unhealthy, wait for it to exit election
 cluster.setHealthy(1, false);
 cluster.waitForElectorState(1, ActiveStandbyElector.State.INIT);
 // Ask for failover, it should fail, because it's unhealthy
 try {
  cluster.getService(1).getZKFCProxy(conf, 5000).gracefulFailover();
  fail("Did not fail to graceful failover to unhealthy service!");
 } catch (ServiceFailedException sfe) {
  GenericTestUtils.assertExceptionContains(
    cluster.getService(1).toString() +
    " is not currently healthy.", sfe);
 }
}

代码示例来源:origin: com.github.jiayuhan-it/hadoop-common

@Test(timeout=15000)
public void testGracefulFailoverToUnhealthy() throws Exception {
 try {
  cluster.start();
  cluster.waitForActiveLockHolder(0);
  // Mark it unhealthy, wait for it to exit election
  cluster.setHealthy(1, false);
  cluster.waitForElectorState(1, ActiveStandbyElector.State.INIT);
  
  // Ask for failover, it should fail, because it's unhealthy
  try {
   cluster.getService(1).getZKFCProxy(conf, 5000).gracefulFailover();
   fail("Did not fail to graceful failover to unhealthy service!");
  } catch (ServiceFailedException sfe) {
   GenericTestUtils.assertExceptionContains(
     cluster.getService(1).toString() + 
     " is not currently healthy.", sfe);
  }
 } finally {
  cluster.stop();
 }
}

代码示例来源:origin: ch.cern.hadoop/hadoop-common

@Test
public void testGracefulFailoverFailBecomingActive() throws Exception {
 cluster.start();
 cluster.waitForActiveLockHolder(0);
 cluster.setFailToBecomeActive(1, true);
 // Ask for failover, it should fail and report back to user.
 try {
  cluster.getService(1).getZKFCProxy(conf, 5000).gracefulFailover();
  fail("Did not fail to graceful failover when target failed " +
    "to become active!");
 } catch (ServiceFailedException sfe) {
  GenericTestUtils.assertExceptionContains(
    "Couldn't make " + cluster.getService(1) + " active", sfe);
  GenericTestUtils.assertExceptionContains(
    "injected failure", sfe);
 }
 // No fencing
 assertEquals(0, cluster.getService(0).fenceCount);
 assertEquals(0, cluster.getService(1).fenceCount);
 // Service 0 should go back to being active after the failed failover
 cluster.waitForActiveLockHolder(0);
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com