Search in sources :

Example 1 with BlockDeletingService

use of org.apache.hadoop.ozone.container.keyvalue.statemachine.background.BlockDeletingService in project ozone by apache.

the class TestContainerDeletionChoosingPolicy method getBlockDeletingService.

private BlockDeletingService getBlockDeletingService() {
    ozoneContainer = Mockito.mock(OzoneContainer.class);
    Mockito.when(ozoneContainer.getContainerSet()).thenReturn(containerSet);
    Mockito.when(ozoneContainer.getWriteChannel()).thenReturn(null);
    blockDeletingService = new BlockDeletingService(ozoneContainer, SERVICE_INTERVAL_IN_MILLISECONDS, SERVICE_TIMEOUT_IN_MILLISECONDS, TimeUnit.MILLISECONDS, 10, conf);
    return blockDeletingService;
}
Also used : BlockDeletingService(org.apache.hadoop.ozone.container.keyvalue.statemachine.background.BlockDeletingService) OzoneContainer(org.apache.hadoop.ozone.container.ozoneimpl.OzoneContainer)

Example 2 with BlockDeletingService

use of org.apache.hadoop.ozone.container.keyvalue.statemachine.background.BlockDeletingService in project ozone by apache.

the class TestBlockDeletingService method testBlockDeletionTimeout.

@Test
public void testBlockDeletionTimeout() throws Exception {
    DatanodeConfiguration dnConf = conf.getObject(DatanodeConfiguration.class);
    dnConf.setBlockDeletionLimit(3);
    blockLimitPerInterval = dnConf.getBlockDeletionLimit();
    conf.setFromObject(dnConf);
    ContainerSet containerSet = new ContainerSet();
    createToDeleteBlocks(containerSet, 1, 3, 1);
    ContainerMetrics metrics = ContainerMetrics.create(conf);
    KeyValueHandler keyValueHandler = new KeyValueHandler(conf, datanodeUuid, containerSet, volumeSet, metrics, c -> {
    });
    // set timeout value as 1ns to trigger timeout behavior
    long timeout = 1;
    OzoneContainer ozoneContainer = mockDependencies(containerSet, keyValueHandler);
    BlockDeletingService svc = new BlockDeletingService(ozoneContainer, TimeUnit.MILLISECONDS.toNanos(1000), timeout, TimeUnit.NANOSECONDS, 10, conf);
    svc.start();
    LogCapturer log = LogCapturer.captureLogs(BackgroundService.LOG);
    GenericTestUtils.waitFor(() -> {
        if (log.getOutput().contains("Background task execution took")) {
            log.stopCapturing();
            return true;
        }
        return false;
    }, 100, 1000);
    log.stopCapturing();
    svc.shutdown();
    // test for normal case that doesn't have timeout limitation
    createToDeleteBlocks(containerSet, 1, 3, 1);
    timeout = 0;
    svc = new BlockDeletingService(ozoneContainer, TimeUnit.MILLISECONDS.toNanos(1000), timeout, TimeUnit.MILLISECONDS, 10, conf);
    svc.start();
    // get container meta data
    KeyValueContainer container = (KeyValueContainer) containerSet.getContainerIterator().next();
    KeyValueContainerData data = container.getContainerData();
    try (ReferenceCountedDB meta = BlockUtils.getDB(data, conf)) {
        LogCapturer newLog = LogCapturer.captureLogs(BackgroundService.LOG);
        GenericTestUtils.waitFor(() -> {
            try {
                return getUnderDeletionBlocksCount(meta, data) == 0;
            } catch (IOException ignored) {
            }
            return false;
        }, 100, 1000);
        newLog.stopCapturing();
        // The block deleting successfully and shouldn't catch timed
        // out warning log.
        Assert.assertFalse(newLog.getOutput().contains("Background task executes timed out, retrying in next interval"));
    }
    svc.shutdown();
}
Also used : KeyValueHandler(org.apache.hadoop.ozone.container.keyvalue.KeyValueHandler) ContainerSet(org.apache.hadoop.ozone.container.common.impl.ContainerSet) BlockDeletingService(org.apache.hadoop.ozone.container.keyvalue.statemachine.background.BlockDeletingService) DatanodeConfiguration(org.apache.hadoop.ozone.container.common.statemachine.DatanodeConfiguration) LogCapturer(org.apache.ozone.test.GenericTestUtils.LogCapturer) IOException(java.io.IOException) ContainerMetrics(org.apache.hadoop.ozone.container.common.helpers.ContainerMetrics) OzoneContainer(org.apache.hadoop.ozone.container.ozoneimpl.OzoneContainer) KeyValueContainer(org.apache.hadoop.ozone.container.keyvalue.KeyValueContainer) KeyValueContainerData(org.apache.hadoop.ozone.container.keyvalue.KeyValueContainerData) ReferenceCountedDB(org.apache.hadoop.ozone.container.common.utils.ReferenceCountedDB) Test(org.junit.Test)

Aggregations

BlockDeletingService (org.apache.hadoop.ozone.container.keyvalue.statemachine.background.BlockDeletingService)2 OzoneContainer (org.apache.hadoop.ozone.container.ozoneimpl.OzoneContainer)2 IOException (java.io.IOException)1 ContainerMetrics (org.apache.hadoop.ozone.container.common.helpers.ContainerMetrics)1 ContainerSet (org.apache.hadoop.ozone.container.common.impl.ContainerSet)1 DatanodeConfiguration (org.apache.hadoop.ozone.container.common.statemachine.DatanodeConfiguration)1 ReferenceCountedDB (org.apache.hadoop.ozone.container.common.utils.ReferenceCountedDB)1 KeyValueContainer (org.apache.hadoop.ozone.container.keyvalue.KeyValueContainer)1 KeyValueContainerData (org.apache.hadoop.ozone.container.keyvalue.KeyValueContainerData)1 KeyValueHandler (org.apache.hadoop.ozone.container.keyvalue.KeyValueHandler)1 LogCapturer (org.apache.ozone.test.GenericTestUtils.LogCapturer)1 Test (org.junit.Test)1