use of org.apache.hadoop.ozone.TestStorageContainerManagerHelper in project ozone by apache.
the class TestScmSafeMode method testSCMSafeMode.
@Test(timeout = 300_000)
public void testSCMSafeMode() throws Exception {
// Test1: Test safe mode when there are no containers in system.
cluster.stop();
try {
cluster = builder.build();
} catch (IOException e) {
Assert.fail("Cluster startup failed.");
}
assertTrue(cluster.getStorageContainerManager().isInSafeMode());
cluster.startHddsDatanodes();
cluster.waitForClusterToBeReady();
cluster.waitTobeOutOfSafeMode();
assertFalse(cluster.getStorageContainerManager().isInSafeMode());
// Test2: Test safe mode when containers are there in system.
// Create {numKeys} random names keys.
TestStorageContainerManagerHelper helper = new TestStorageContainerManagerHelper(cluster, conf);
Map<String, OmKeyInfo> keyLocations = helper.createKeys(100 * 2, 4096);
final List<ContainerInfo> containers = cluster.getStorageContainerManager().getContainerManager().getContainers();
GenericTestUtils.waitFor(() -> containers.size() >= 3, 100, 1000 * 30);
// Removing some container to keep them open.
containers.remove(0);
containers.remove(0);
// Close remaining containers
ContainerManager mapping = cluster.getStorageContainerManager().getContainerManager();
containers.forEach(c -> {
try {
mapping.updateContainerState(c.containerID(), HddsProtos.LifeCycleEvent.FINALIZE);
mapping.updateContainerState(c.containerID(), LifeCycleEvent.CLOSE);
} catch (IOException | InvalidStateTransitionException e) {
LOG.info("Failed to change state of open containers.", e);
}
});
cluster.stop();
GenericTestUtils.LogCapturer logCapturer = GenericTestUtils.LogCapturer.captureLogs(SCMSafeModeManager.getLogger());
logCapturer.clearOutput();
try {
cluster = builder.build();
} catch (IOException ex) {
fail("failed");
}
StorageContainerManager scm;
scm = cluster.getStorageContainerManager();
assertTrue(scm.isInSafeMode());
assertFalse(logCapturer.getOutput().contains("SCM exiting safe mode."));
assertTrue(scm.getCurrentContainerThreshold() == 0);
for (HddsDatanodeService dn : cluster.getHddsDatanodes()) {
dn.start();
}
GenericTestUtils.waitFor(() -> scm.getCurrentContainerThreshold() == 1.0, 100, 20000);
EventQueue eventQueue = (EventQueue) cluster.getStorageContainerManager().getEventQueue();
eventQueue.processAll(5000L);
double safeModeCutoff = conf.getDouble(HddsConfigKeys.HDDS_SCM_SAFEMODE_THRESHOLD_PCT, HddsConfigKeys.HDDS_SCM_SAFEMODE_THRESHOLD_PCT_DEFAULT);
assertTrue(scm.getCurrentContainerThreshold() >= safeModeCutoff);
assertTrue(logCapturer.getOutput().contains("SCM exiting safe mode."));
assertFalse(scm.isInSafeMode());
}
use of org.apache.hadoop.ozone.TestStorageContainerManagerHelper in project ozone by apache.
the class TestScmSafeMode method testSafeModeOperations.
@Test(timeout = 300_000)
public void testSafeModeOperations() throws Exception {
// Create {numKeys} random names keys.
TestStorageContainerManagerHelper helper = new TestStorageContainerManagerHelper(cluster, conf);
Map<String, OmKeyInfo> keyLocations = helper.createKeys(100, 4096);
final List<ContainerInfo> containers = cluster.getStorageContainerManager().getContainerManager().getContainers();
GenericTestUtils.waitFor(() -> containers.size() >= 3, 100, 1000);
String volumeName = "volume" + RandomStringUtils.randomNumeric(5);
String bucketName = "bucket" + RandomStringUtils.randomNumeric(5);
String keyName = "key" + RandomStringUtils.randomNumeric(5);
ObjectStore store = cluster.getRpcClient().getObjectStore();
store.createVolume(volumeName);
OzoneVolume volume = store.getVolume(volumeName);
volume.createBucket(bucketName);
OzoneBucket bucket = volume.getBucket(bucketName);
bucket.createKey(keyName, 1000, RATIS, ONE, new HashMap<>());
cluster.stop();
try {
cluster = builder.build();
} catch (IOException e) {
fail("failed");
}
StorageContainerManager scm;
scm = cluster.getStorageContainerManager();
Assert.assertTrue(scm.isInSafeMode());
om = cluster.getOzoneManager();
final OzoneBucket bucket1 = cluster.getRpcClient().getObjectStore().getVolume(volumeName).getBucket(bucketName);
// As cluster is restarted with out datanodes restart
LambdaTestUtils.intercept(IOException.class, "SafeModePrecheck failed for allocateBlock", () -> bucket1.createKey(keyName, 1000, RATIS, ONE, new HashMap<>()));
}
use of org.apache.hadoop.ozone.TestStorageContainerManagerHelper in project ozone by apache.
the class TestScmSafeMode method testSCMSafeModeRestrictedOp.
@Test(timeout = 300_000)
public void testSCMSafeModeRestrictedOp() throws Exception {
cluster.stop();
cluster = builder.build();
StorageContainerManager scm = cluster.getStorageContainerManager();
assertTrue(scm.isInSafeMode());
LambdaTestUtils.intercept(SCMException.class, "SafeModePrecheck failed for allocateContainer", () -> {
scm.getClientProtocolServer().allocateContainer(ReplicationType.STAND_ALONE, ReplicationFactor.ONE, "");
});
cluster.startHddsDatanodes();
cluster.waitForClusterToBeReady();
cluster.waitTobeOutOfSafeMode();
assertFalse(scm.isInSafeMode());
TestStorageContainerManagerHelper helper = new TestStorageContainerManagerHelper(cluster, conf);
helper.createKeys(10, 4096);
SCMClientProtocolServer clientProtocolServer = cluster.getStorageContainerManager().getClientProtocolServer();
assertFalse((scm.getClientProtocolServer()).getSafeModeStatus());
final List<ContainerInfo> containers = scm.getContainerManager().getContainers();
scm.getEventQueue().fireEvent(SCMEvents.SAFE_MODE_STATUS, new SCMSafeModeManager.SafeModeStatus(true, true));
GenericTestUtils.waitFor(() -> {
return clientProtocolServer.getSafeModeStatus();
}, 50, 1000 * 30);
assertTrue(clientProtocolServer.getSafeModeStatus());
cluster.shutdownHddsDatanodes();
Thread.sleep(30000);
LambdaTestUtils.intercept(SCMException.class, "Open container " + containers.get(0).getContainerID() + " " + "doesn't have enough replicas to service this operation in Safe" + " mode.", () -> clientProtocolServer.getContainerWithPipeline(containers.get(0).getContainerID()));
}
Aggregations