Search in sources :

Example 1 with FilePerBlockStrategy

use of org.apache.hadoop.ozone.container.keyvalue.impl.FilePerBlockStrategy in project ozone by apache.

the class TestSchemaTwoBackwardsCompatibility method setup.

@Before
public void setup() throws Exception {
    testRoot = tempFolder.newFolder();
    conf = new OzoneConfiguration();
    clusterID = UUID.randomUUID().toString();
    datanodeUuid = UUID.randomUUID().toString();
    // turn off schemaV3 first
    ContainerTestUtils.disableSchemaV3(conf);
    conf.set(ScmConfigKeys.HDDS_DATANODE_DIR_KEY, testRoot.getAbsolutePath());
    conf.set(HddsConfigKeys.OZONE_METADATA_DIRS, testRoot.getAbsolutePath());
    volumeSet = new MutableVolumeSet(datanodeUuid, clusterID, conf, null, StorageVolume.VolumeType.DATA_VOLUME, null);
    blockManager = new BlockManagerImpl(conf);
    chunkManager = new FilePerBlockStrategy(true, blockManager, volumeSet);
    containerSet = new ContainerSet();
    keyValueHandler = new KeyValueHandler(conf, datanodeUuid, containerSet, volumeSet, ContainerMetrics.create(conf), c -> {
    });
    ozoneContainer = mock(OzoneContainer.class);
    when(ozoneContainer.getContainerSet()).thenReturn(containerSet);
    when(ozoneContainer.getWriteChannel()).thenReturn(null);
    ContainerDispatcher dispatcher = mock(ContainerDispatcher.class);
    when(ozoneContainer.getDispatcher()).thenReturn(dispatcher);
    when(dispatcher.getHandler(any())).thenReturn(keyValueHandler);
}
Also used : ScmConfigKeys(org.apache.hadoop.hdds.scm.ScmConfigKeys) Arrays(java.util.Arrays) BlockUtils(org.apache.hadoop.ozone.container.keyvalue.helpers.BlockUtils) BLOCK_COUNT(org.apache.hadoop.ozone.OzoneConsts.BLOCK_COUNT) TimeoutException(java.util.concurrent.TimeoutException) ContainerSet(org.apache.hadoop.ozone.container.common.impl.ContainerSet) MutableVolumeSet(org.apache.hadoop.ozone.container.common.volume.MutableVolumeSet) ByteBuffer(java.nio.ByteBuffer) DispatcherContext(org.apache.hadoop.ozone.container.common.transport.server.ratis.DispatcherContext) BlockIterator(org.apache.hadoop.ozone.container.common.interfaces.BlockIterator) KeyValueContainerData(org.apache.hadoop.ozone.container.keyvalue.KeyValueContainerData) After(org.junit.After) HddsConfigKeys(org.apache.hadoop.hdds.HddsConfigKeys) ContainerLayoutVersion(org.apache.hadoop.ozone.container.common.impl.ContainerLayoutVersion) DatanodeStoreSchemaTwoImpl(org.apache.hadoop.ozone.container.metadata.DatanodeStoreSchemaTwoImpl) BatchOperation(org.apache.hadoop.hdds.utils.db.BatchOperation) KeyValueHandler(org.apache.hadoop.ozone.container.keyvalue.KeyValueHandler) ContainerTestHelper(org.apache.hadoop.ozone.container.ContainerTestHelper) UUID(java.util.UUID) PENDING_DELETE_BLOCK_COUNT(org.apache.hadoop.ozone.OzoneConsts.PENDING_DELETE_BLOCK_COUNT) List(java.util.List) RoundRobinVolumeChoosingPolicy(org.apache.hadoop.ozone.container.common.volume.RoundRobinVolumeChoosingPolicy) StorageContainerException(org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException) RandomStringUtils.randomAlphanumeric(org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric) ChunkInfo(org.apache.hadoop.ozone.container.common.helpers.ChunkInfo) OzoneConfigKeys(org.apache.hadoop.ozone.OzoneConfigKeys) FilePerBlockStrategy(org.apache.hadoop.ozone.container.keyvalue.impl.FilePerBlockStrategy) GenericTestUtils(org.apache.ozone.test.GenericTestUtils) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) OzoneConfiguration(org.apache.hadoop.hdds.conf.OzoneConfiguration) BlockID(org.apache.hadoop.hdds.client.BlockID) BlockManager(org.apache.hadoop.ozone.container.keyvalue.interfaces.BlockManager) ContainerProtos(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos) DBHandle(org.apache.hadoop.ozone.container.common.interfaces.DBHandle) CONTAINER_BYTES_USED(org.apache.hadoop.ozone.OzoneConsts.CONTAINER_BYTES_USED) BlockData(org.apache.hadoop.ozone.container.common.helpers.BlockData) BlockDeletingServiceTestImpl(org.apache.hadoop.ozone.container.testutils.BlockDeletingServiceTestImpl) OzoneContainer(org.apache.hadoop.ozone.container.ozoneimpl.OzoneContainer) ContainerDispatcher(org.apache.hadoop.ozone.container.common.interfaces.ContainerDispatcher) Before(org.junit.Before) KeyValueContainer(org.apache.hadoop.ozone.container.keyvalue.KeyValueContainer) UTF_8(java.nio.charset.StandardCharsets.UTF_8) OZONE_BLOCK_DELETING_CONTAINER_LIMIT_PER_INTERVAL(org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_BLOCK_DELETING_CONTAINER_LIMIT_PER_INTERVAL) ContainerMetrics(org.apache.hadoop.ozone.container.common.helpers.ContainerMetrics) Test(org.junit.Test) IOException(java.io.IOException) Container(org.apache.hadoop.ozone.container.common.interfaces.Container) Mockito.when(org.mockito.Mockito.when) DeletedBlocksTransaction(org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.DeletedBlocksTransaction) OzoneConsts(org.apache.hadoop.ozone.OzoneConsts) File(java.io.File) BlockManagerImpl(org.apache.hadoop.ozone.container.keyvalue.impl.BlockManagerImpl) StorageVolume(org.apache.hadoop.ozone.container.common.volume.StorageVolume) Rule(org.junit.Rule) Table(org.apache.hadoop.hdds.utils.db.Table) ChunkBuffer(org.apache.hadoop.ozone.common.ChunkBuffer) ChunkManager(org.apache.hadoop.ozone.container.keyvalue.interfaces.ChunkManager) TemporaryFolder(org.junit.rules.TemporaryFolder) Assert.assertEquals(org.junit.Assert.assertEquals) KeyValueHandler(org.apache.hadoop.ozone.container.keyvalue.KeyValueHandler) ContainerSet(org.apache.hadoop.ozone.container.common.impl.ContainerSet) FilePerBlockStrategy(org.apache.hadoop.ozone.container.keyvalue.impl.FilePerBlockStrategy) ContainerDispatcher(org.apache.hadoop.ozone.container.common.interfaces.ContainerDispatcher) OzoneConfiguration(org.apache.hadoop.hdds.conf.OzoneConfiguration) MutableVolumeSet(org.apache.hadoop.ozone.container.common.volume.MutableVolumeSet) OzoneContainer(org.apache.hadoop.ozone.container.ozoneimpl.OzoneContainer) BlockManagerImpl(org.apache.hadoop.ozone.container.keyvalue.impl.BlockManagerImpl) Before(org.junit.Before)

Example 2 with FilePerBlockStrategy

use of org.apache.hadoop.ozone.container.keyvalue.impl.FilePerBlockStrategy in project ozone by apache.

the class TestBlockDeletingService method createToDeleteBlocks.

/**
 * A helper method to create some blocks and put them under deletion
 * state for testing. This method directly updates container.db and
 * creates some fake chunk files for testing.
 */
private void createToDeleteBlocks(ContainerSet containerSet, int numOfContainers, int numOfBlocksPerContainer, int numOfChunksPerBlock) throws IOException {
    ChunkManager chunkManager;
    if (layout == FILE_PER_BLOCK) {
        chunkManager = new FilePerBlockStrategy(true, null, null);
    } else {
        chunkManager = new FilePerChunkStrategy(true, null, null);
    }
    byte[] arr = randomAlphanumeric(1048576).getBytes(UTF_8);
    ChunkBuffer buffer = ChunkBuffer.wrap(ByteBuffer.wrap(arr));
    int txnID = 0;
    for (int x = 0; x < numOfContainers; x++) {
        long containerID = ContainerTestHelper.getTestContainerID();
        KeyValueContainerData data = new KeyValueContainerData(containerID, layout, ContainerTestHelper.CONTAINER_MAX_SIZE, UUID.randomUUID().toString(), datanodeUuid);
        data.closeContainer();
        data.setSchemaVersion(schemaVersion);
        KeyValueContainer container = new KeyValueContainer(data, conf);
        container.create(volumeSet, new RoundRobinVolumeChoosingPolicy(), scmId);
        containerSet.addContainer(container);
        data = (KeyValueContainerData) containerSet.getContainer(containerID).getContainerData();
        data.setSchemaVersion(schemaVersion);
        if (schemaVersion.equals(SCHEMA_V1)) {
            createPendingDeleteBlocksSchema1(numOfBlocksPerContainer, data, containerID, numOfChunksPerBlock, buffer, chunkManager, container);
        } else if (schemaVersion.equals(SCHEMA_V2) || schemaVersion.equals(SCHEMA_V3)) {
            createPendingDeleteBlocksViaTxn(numOfBlocksPerContainer, txnID, containerID, numOfChunksPerBlock, buffer, chunkManager, container, data);
        } else {
            throw new UnsupportedOperationException("Only schema version 1,2,3 are supported.");
        }
    }
}
Also used : RoundRobinVolumeChoosingPolicy(org.apache.hadoop.ozone.container.common.volume.RoundRobinVolumeChoosingPolicy) FilePerChunkStrategy(org.apache.hadoop.ozone.container.keyvalue.impl.FilePerChunkStrategy) FilePerBlockStrategy(org.apache.hadoop.ozone.container.keyvalue.impl.FilePerBlockStrategy) ChunkBuffer(org.apache.hadoop.ozone.common.ChunkBuffer) ChunkManager(org.apache.hadoop.ozone.container.keyvalue.interfaces.ChunkManager) KeyValueContainerData(org.apache.hadoop.ozone.container.keyvalue.KeyValueContainerData) KeyValueContainer(org.apache.hadoop.ozone.container.keyvalue.KeyValueContainer)

Aggregations

ChunkBuffer (org.apache.hadoop.ozone.common.ChunkBuffer)2 RoundRobinVolumeChoosingPolicy (org.apache.hadoop.ozone.container.common.volume.RoundRobinVolumeChoosingPolicy)2 KeyValueContainer (org.apache.hadoop.ozone.container.keyvalue.KeyValueContainer)2 File (java.io.File)1 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)1 Arrays (java.util.Arrays)1 List (java.util.List)1 UUID (java.util.UUID)1 TimeoutException (java.util.concurrent.TimeoutException)1 RandomStringUtils.randomAlphanumeric (org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric)1 HddsConfigKeys (org.apache.hadoop.hdds.HddsConfigKeys)1 BlockID (org.apache.hadoop.hdds.client.BlockID)1 OzoneConfiguration (org.apache.hadoop.hdds.conf.OzoneConfiguration)1 ContainerProtos (org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos)1 DeletedBlocksTransaction (org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.DeletedBlocksTransaction)1 ScmConfigKeys (org.apache.hadoop.hdds.scm.ScmConfigKeys)1 StorageContainerException (org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException)1 BatchOperation (org.apache.hadoop.hdds.utils.db.BatchOperation)1