use of org.apache.hadoop.hdds.scm.protocol.ScmBlockLocationProtocol in project ozone by apache.
the class TestFailoverWithSCMHA method testFailover.
@Test
public void testFailover() 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);
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);
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"));
}
use of org.apache.hadoop.hdds.scm.protocol.ScmBlockLocationProtocol in project ozone by apache.
the class TestOMKeyRequest method setup.
@Before
public void setup() throws Exception {
ozoneManager = Mockito.mock(OzoneManager.class);
omMetrics = OMMetrics.create();
OzoneConfiguration ozoneConfiguration = getOzoneConfiguration();
ozoneConfiguration.set(OMConfigKeys.OZONE_OM_DB_DIRS, folder.newFolder().getAbsolutePath());
ozoneConfiguration.set(OzoneConfigKeys.OZONE_METADATA_DIRS, folder.newFolder().getAbsolutePath());
omMetadataManager = new OmMetadataManagerImpl(ozoneConfiguration);
when(ozoneManager.getMetrics()).thenReturn(omMetrics);
when(ozoneManager.getMetadataManager()).thenReturn(omMetadataManager);
when(ozoneManager.getConfiguration()).thenReturn(ozoneConfiguration);
OMLayoutVersionManager lvm = mock(OMLayoutVersionManager.class);
when(lvm.getMetadataLayoutVersion()).thenReturn(0);
when(ozoneManager.getVersionManager()).thenReturn(lvm);
when(ozoneManager.isRatisEnabled()).thenReturn(true);
auditLogger = Mockito.mock(AuditLogger.class);
when(ozoneManager.getAuditLogger()).thenReturn(auditLogger);
when(ozoneManager.isAdmin(any(String.class))).thenReturn(true);
when(ozoneManager.isAdmin(any(UserGroupInformation.class))).thenReturn(true);
Mockito.doNothing().when(auditLogger).logWrite(any(AuditMessage.class));
scmClient = Mockito.mock(ScmClient.class);
ozoneBlockTokenSecretManager = Mockito.mock(OzoneBlockTokenSecretManager.class);
scmBlockLocationProtocol = Mockito.mock(ScmBlockLocationProtocol.class);
keyManager = new KeyManagerImpl(ozoneManager, scmClient, ozoneConfiguration, "");
when(ozoneManager.getScmClient()).thenReturn(scmClient);
when(ozoneManager.getBlockTokenSecretManager()).thenReturn(ozoneBlockTokenSecretManager);
when(ozoneManager.getScmBlockSize()).thenReturn(scmBlockSize);
when(ozoneManager.getPreallocateBlocksMax()).thenReturn(2);
when(ozoneManager.isGrpcBlockTokenEnabled()).thenReturn(false);
when(ozoneManager.getOMNodeId()).thenReturn(UUID.randomUUID().toString());
when(scmClient.getBlockClient()).thenReturn(scmBlockLocationProtocol);
when(ozoneManager.getKeyManager()).thenReturn(keyManager);
prepareState = new OzoneManagerPrepareState(ozoneConfiguration);
when(ozoneManager.getPrepareState()).thenReturn(prepareState);
Pipeline pipeline = Pipeline.newBuilder().setState(Pipeline.PipelineState.OPEN).setId(PipelineID.randomId()).setReplicationConfig(StandaloneReplicationConfig.getInstance(ReplicationFactor.ONE)).setNodes(new ArrayList<>()).build();
AllocatedBlock allocatedBlock = new AllocatedBlock.Builder().setContainerBlockID(new ContainerBlockID(CONTAINER_ID, LOCAL_ID)).setPipeline(pipeline).build();
List<AllocatedBlock> allocatedBlocks = new ArrayList<>();
allocatedBlocks.add(allocatedBlock);
when(scmBlockLocationProtocol.allocateBlock(anyLong(), anyInt(), any(), anyString(), any())).thenReturn(allocatedBlocks);
volumeName = UUID.randomUUID().toString();
bucketName = UUID.randomUUID().toString();
keyName = UUID.randomUUID().toString();
replicationFactor = HddsProtos.ReplicationFactor.ONE;
replicationType = HddsProtos.ReplicationType.RATIS;
clientID = Time.now();
dataSize = 1000L;
random = new Random();
version = 0L;
Pair<String, String> volumeAndBucket = Pair.of(volumeName, bucketName);
when(ozoneManager.resolveBucketLink(any(KeyArgs.class), any(OMClientRequest.class))).thenReturn(new ResolvedBucket(volumeAndBucket, volumeAndBucket));
when(ozoneManager.resolveBucketLink(any(Pair.class), any(OMClientRequest.class))).thenReturn(new ResolvedBucket(volumeAndBucket, volumeAndBucket));
}
use of org.apache.hadoop.hdds.scm.protocol.ScmBlockLocationProtocol in project ozone by apache.
the class TestKeyDeletingService method checkIfDeleteServiceWithFailingSCM.
@Test(timeout = 40000)
public void checkIfDeleteServiceWithFailingSCM() throws IOException, TimeoutException, InterruptedException, AuthenticationException {
OzoneConfiguration conf = createConfAndInitValues();
ScmBlockLocationProtocol blockClient = // failCallsFrequency = 1 , means all calls fail.
new ScmBlockLocationTestingClient(null, null, 1);
OmTestManagers omTestManagers = new OmTestManagers(conf, blockClient, null);
KeyManager keyManager = omTestManagers.getKeyManager();
writeClient = omTestManagers.getWriteClient();
om = omTestManagers.getOzoneManager();
final int keyCount = 100;
createAndDeleteKeys(keyManager, keyCount, 1);
KeyDeletingService keyDeletingService = (KeyDeletingService) keyManager.getDeletingService();
GenericTestUtils.waitFor(() -> {
try {
int numPendingDeletionKeys = keyManager.getPendingDeletionKeys(Integer.MAX_VALUE).size();
if (numPendingDeletionKeys != keyCount) {
LOG.info("Expected {} keys to be pending deletion, but got {}", keyCount, numPendingDeletionKeys);
return false;
}
return true;
} catch (IOException e) {
LOG.error("Error while getting pending deletion keys.", e);
return false;
}
}, 100, 2000);
// Make sure that we have run the background thread 5 times more
GenericTestUtils.waitFor(() -> keyDeletingService.getRunCount().get() >= 5, 100, 1000);
// Since SCM calls are failing, deletedKeyCount should be zero.
Assert.assertEquals(keyDeletingService.getDeletedKeyCount().get(), 0);
Assert.assertEquals(keyManager.getPendingDeletionKeys(Integer.MAX_VALUE).size(), keyCount);
}
use of org.apache.hadoop.hdds.scm.protocol.ScmBlockLocationProtocol in project ozone by apache.
the class TestKeyDeletingService method checkDeletionForEmptyKey.
@Test(timeout = 30000)
public void checkDeletionForEmptyKey() throws IOException, TimeoutException, InterruptedException, AuthenticationException {
OzoneConfiguration conf = createConfAndInitValues();
ScmBlockLocationProtocol blockClient = // failCallsFrequency = 1 , means all calls fail.
new ScmBlockLocationTestingClient(null, null, 1);
OmTestManagers omTestManagers = new OmTestManagers(conf, blockClient, null);
KeyManager keyManager = omTestManagers.getKeyManager();
writeClient = omTestManagers.getWriteClient();
om = omTestManagers.getOzoneManager();
final int keyCount = 100;
createAndDeleteKeys(keyManager, keyCount, 0);
KeyDeletingService keyDeletingService = (KeyDeletingService) keyManager.getDeletingService();
// Since empty keys are directly deleted from db there should be no
// pending deletion keys. Also deletedKeyCount should be zero.
Assert.assertEquals(keyManager.getPendingDeletionKeys(Integer.MAX_VALUE).size(), 0);
// Make sure that we have run the background thread 2 times or more
GenericTestUtils.waitFor(() -> keyDeletingService.getRunCount().get() >= 2, 100, 1000);
Assert.assertEquals(keyDeletingService.getDeletedKeyCount().get(), 0);
}
use of org.apache.hadoop.hdds.scm.protocol.ScmBlockLocationProtocol 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(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));
}
Aggregations