Search in sources :

Example 1 with TestStorageContainerManagerHelper

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());
}
Also used : ContainerManager(org.apache.hadoop.hdds.scm.container.ContainerManager) StorageContainerManager(org.apache.hadoop.hdds.scm.server.StorageContainerManager) StorageContainerManager(org.apache.hadoop.hdds.scm.server.StorageContainerManager) InvalidStateTransitionException(org.apache.hadoop.ozone.common.statemachine.InvalidStateTransitionException) GenericTestUtils(org.apache.ozone.test.GenericTestUtils) HddsDatanodeService(org.apache.hadoop.ozone.HddsDatanodeService) IOException(java.io.IOException) TestStorageContainerManagerHelper(org.apache.hadoop.ozone.TestStorageContainerManagerHelper) EventQueue(org.apache.hadoop.hdds.server.events.EventQueue) OmKeyInfo(org.apache.hadoop.ozone.om.helpers.OmKeyInfo) ContainerInfo(org.apache.hadoop.hdds.scm.container.ContainerInfo) Test(org.junit.Test)

Example 2 with TestStorageContainerManagerHelper

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<>()));
}
Also used : ObjectStore(org.apache.hadoop.ozone.client.ObjectStore) StorageContainerManager(org.apache.hadoop.hdds.scm.server.StorageContainerManager) HashMap(java.util.HashMap) TestStorageContainerManagerHelper(org.apache.hadoop.ozone.TestStorageContainerManagerHelper) IOException(java.io.IOException) OzoneVolume(org.apache.hadoop.ozone.client.OzoneVolume) OzoneBucket(org.apache.hadoop.ozone.client.OzoneBucket) OmKeyInfo(org.apache.hadoop.ozone.om.helpers.OmKeyInfo) ContainerInfo(org.apache.hadoop.hdds.scm.container.ContainerInfo) Test(org.junit.Test)

Example 3 with TestStorageContainerManagerHelper

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()));
}
Also used : StorageContainerManager(org.apache.hadoop.hdds.scm.server.StorageContainerManager) ContainerInfo(org.apache.hadoop.hdds.scm.container.ContainerInfo) TestStorageContainerManagerHelper(org.apache.hadoop.ozone.TestStorageContainerManagerHelper) SCMClientProtocolServer(org.apache.hadoop.hdds.scm.server.SCMClientProtocolServer) SCMSafeModeManager(org.apache.hadoop.hdds.scm.safemode.SCMSafeModeManager) Test(org.junit.Test)

Aggregations

ContainerInfo (org.apache.hadoop.hdds.scm.container.ContainerInfo)3 StorageContainerManager (org.apache.hadoop.hdds.scm.server.StorageContainerManager)3 TestStorageContainerManagerHelper (org.apache.hadoop.ozone.TestStorageContainerManagerHelper)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 OmKeyInfo (org.apache.hadoop.ozone.om.helpers.OmKeyInfo)2 HashMap (java.util.HashMap)1 ContainerManager (org.apache.hadoop.hdds.scm.container.ContainerManager)1 SCMSafeModeManager (org.apache.hadoop.hdds.scm.safemode.SCMSafeModeManager)1 SCMClientProtocolServer (org.apache.hadoop.hdds.scm.server.SCMClientProtocolServer)1 EventQueue (org.apache.hadoop.hdds.server.events.EventQueue)1 HddsDatanodeService (org.apache.hadoop.ozone.HddsDatanodeService)1 ObjectStore (org.apache.hadoop.ozone.client.ObjectStore)1 OzoneBucket (org.apache.hadoop.ozone.client.OzoneBucket)1 OzoneVolume (org.apache.hadoop.ozone.client.OzoneVolume)1 InvalidStateTransitionException (org.apache.hadoop.ozone.common.statemachine.InvalidStateTransitionException)1 GenericTestUtils (org.apache.ozone.test.GenericTestUtils)1