use of org.apache.hadoop.hdds.scm.proxy.SCMClientConfig in project ozone by apache.
the class TestFailoverWithSCMHA method testMoveFailover.
@Test
public void testMoveFailover() throws Exception {
SCMClientConfig scmClientConfig = conf.getObject(SCMClientConfig.class);
scmClientConfig.setRetryCount(1);
scmClientConfig.setRetryInterval(100);
scmClientConfig.setMaxRetryTimeout(1500);
Assert.assertEquals(scmClientConfig.getRetryCount(), 15);
conf.setFromObject(scmClientConfig);
StorageContainerManager scm = getLeader(cluster);
Assert.assertNotNull(scm);
final ContainerID id = getContainer(HddsProtos.LifeCycleState.CLOSED).containerID();
DatanodeDetails dn1 = randomDatanodeDetails();
DatanodeDetails dn2 = randomDatanodeDetails();
// here we just want to test whether the new leader will get the same
// inflight move after failover, so no need to create container and datanode,
// just mock them bypassing all the pre checks.
scm.getReplicationManager().getMoveScheduler().startMove(id.getProtobuf(), (new MoveDataNodePair(dn1, dn2)).getProtobufMessage(ClientVersion.CURRENT_VERSION));
SCMBlockLocationFailoverProxyProvider failoverProxyProvider = new SCMBlockLocationFailoverProxyProvider(conf);
failoverProxyProvider.changeCurrentProxy(scm.getSCMNodeId());
ScmBlockLocationProtocolClientSideTranslatorPB scmBlockLocationClient = new ScmBlockLocationProtocolClientSideTranslatorPB(failoverProxyProvider);
GenericTestUtils.setLogLevel(SCMBlockLocationFailoverProxyProvider.LOG, Level.DEBUG);
GenericTestUtils.LogCapturer logCapture = GenericTestUtils.LogCapturer.captureLogs(SCMBlockLocationFailoverProxyProvider.LOG);
ScmBlockLocationProtocol scmBlockLocationProtocol = TracingUtil.createProxy(scmBlockLocationClient, ScmBlockLocationProtocol.class, conf);
scmBlockLocationProtocol.getScmInfo();
Assert.assertTrue(logCapture.getOutput().contains("Performing failover to suggested leader"));
scm = getLeader(cluster);
Assert.assertNotNull(scm);
// switch to the new leader successfully, new leader should
// get the same inflightMove
Map<ContainerID, MoveDataNodePair> inflightMove = scm.getReplicationManager().getMoveScheduler().getInflightMove();
Assert.assertTrue(inflightMove.containsKey(id));
MoveDataNodePair mp = inflightMove.get(id);
Assert.assertTrue(dn2.equals(mp.getTgt()));
Assert.assertTrue(dn1.equals(mp.getSrc()));
// complete move in the new leader
scm.getReplicationManager().getMoveScheduler().completeMove(id.getProtobuf());
SCMContainerLocationFailoverProxyProvider proxyProvider = new SCMContainerLocationFailoverProxyProvider(conf, null);
GenericTestUtils.setLogLevel(SCMContainerLocationFailoverProxyProvider.LOG, Level.DEBUG);
logCapture = GenericTestUtils.LogCapturer.captureLogs(SCMContainerLocationFailoverProxyProvider.LOG);
proxyProvider.changeCurrentProxy(scm.getSCMNodeId());
StorageContainerLocationProtocol scmContainerClient = TracingUtil.createProxy(new StorageContainerLocationProtocolClientSideTranslatorPB(proxyProvider), StorageContainerLocationProtocol.class, conf);
scmContainerClient.allocateContainer(HddsProtos.ReplicationType.RATIS, HddsProtos.ReplicationFactor.ONE, "ozone");
Assert.assertTrue(logCapture.getOutput().contains("Performing failover to suggested leader"));
// switch to the new leader successfully, new leader should
// get the same inflightMove , which should not contains
// that container.
scm = getLeader(cluster);
Assert.assertNotNull(scm);
inflightMove = scm.getReplicationManager().getMoveScheduler().getInflightMove();
Assert.assertFalse(inflightMove.containsKey(id));
}
use of org.apache.hadoop.hdds.scm.proxy.SCMClientConfig in project ozone by apache.
the class HAUtils method getScmInfo.
public static ScmInfo getScmInfo(OzoneConfiguration conf) throws IOException {
OzoneConfiguration configuration = new OzoneConfiguration(conf);
try {
long duration = conf.getTimeDuration(OZONE_SCM_INFO_WAIT_DURATION, OZONE_SCM_INFO_WAIT_DURATION_DEFAULT, TimeUnit.SECONDS);
SCMClientConfig scmClientConfig = configuration.getObject(SCMClientConfig.class);
int retryCount = (int) (duration / (scmClientConfig.getRetryInterval() / 1000));
// retry count.
if (retryCount > scmClientConfig.getRetryCount()) {
scmClientConfig.setRetryCount(retryCount);
configuration.setFromObject(scmClientConfig);
}
return getScmBlockClient(configuration).getScmInfo();
} catch (IOException e) {
throw e;
} catch (Exception e) {
throw new IOException("Failed to get SCM info", e);
}
}
Aggregations