Search in sources :

Example 21 with ChunkInfo

use of org.apache.hadoop.ozone.container.common.helpers.ChunkInfo in project ozone by apache.

the class CommonChunkManagerTestCases method testWriteChunkIncorrectLength.

@Test
public void testWriteChunkIncorrectLength() {
    // GIVEN
    ChunkManager chunkManager = createTestSubject();
    try {
        long randomLength = 200L;
        BlockID blockID = getBlockID();
        ChunkInfo chunkInfo = new ChunkInfo(String.format("%d.data.%d", blockID.getLocalID(), 0), 0, randomLength);
        chunkManager.writeChunk(getKeyValueContainer(), blockID, chunkInfo, getData(), getDispatcherContext());
        // THEN
        fail("testWriteChunkIncorrectLength failed");
    } catch (StorageContainerException ex) {
        // As we got an exception, writeBytes should be 0.
        checkWriteIOStats(0, 0);
        GenericTestUtils.assertExceptionContains("Unexpected buffer size", ex);
        assertEquals(ContainerProtos.Result.INVALID_WRITE_SIZE, ex.getResult());
    }
}
Also used : ChunkInfo(org.apache.hadoop.ozone.container.common.helpers.ChunkInfo) BlockID(org.apache.hadoop.hdds.client.BlockID) StorageContainerException(org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException) ChunkManager(org.apache.hadoop.ozone.container.keyvalue.interfaces.ChunkManager) Test(org.junit.Test)

Example 22 with ChunkInfo

use of org.apache.hadoop.ozone.container.common.helpers.ChunkInfo in project ozone by apache.

the class CommonChunkManagerTestCases method testDeletePartialChunkUnsupportedRequest.

@Test
public void testDeletePartialChunkUnsupportedRequest() {
    // GIVEN
    ChunkManager chunkManager = createTestSubject();
    try {
        chunkManager.writeChunk(getKeyValueContainer(), getBlockID(), getChunkInfo(), getData(), getDispatcherContext());
        long randomLength = 200L;
        ChunkInfo chunkInfo = new ChunkInfo(String.format("%d.data.%d", getBlockID().getLocalID(), 0), 0, randomLength);
        // WHEN
        chunkManager.deleteChunk(getKeyValueContainer(), getBlockID(), chunkInfo);
        // THEN
        fail("testDeleteChunkUnsupportedRequest");
    } catch (StorageContainerException ex) {
        assertEquals(ContainerProtos.Result.UNSUPPORTED_REQUEST, ex.getResult());
    }
}
Also used : ChunkInfo(org.apache.hadoop.ozone.container.common.helpers.ChunkInfo) StorageContainerException(org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException) ChunkManager(org.apache.hadoop.ozone.container.keyvalue.interfaces.ChunkManager) Test(org.junit.Test)

Example 23 with ChunkInfo

use of org.apache.hadoop.ozone.container.common.helpers.ChunkInfo in project ozone by apache.

the class TestContainerPersistence method testPutBlock.

/**
 * Tests a put block and read block.
 *
 * @throws IOException
 * @throws NoSuchAlgorithmException
 */
@Test
public void testPutBlock() throws IOException, NoSuchAlgorithmException {
    long testContainerID = getTestContainerID();
    Container container = addContainer(containerSet, testContainerID);
    BlockID blockID = ContainerTestHelper.getTestBlockID(testContainerID);
    ChunkInfo info = writeChunkHelper(blockID);
    BlockData blockData = new BlockData(blockID);
    List<ContainerProtos.ChunkInfo> chunkList = new LinkedList<>();
    chunkList.add(info.getProtoBufMessage());
    blockData.setChunks(chunkList);
    blockManager.putBlock(container, blockData);
    BlockData readBlockData = blockManager.getBlock(container, blockData.getBlockID());
    ChunkInfo readChunk = ChunkInfo.getFromProtoBuf(readBlockData.getChunks().get(0));
    Assert.assertEquals(info.getChecksumData(), readChunk.getChecksumData());
}
Also used : KeyValueContainer(org.apache.hadoop.ozone.container.keyvalue.KeyValueContainer) Container(org.apache.hadoop.ozone.container.common.interfaces.Container) ChunkInfo(org.apache.hadoop.ozone.container.common.helpers.ChunkInfo) BlockID(org.apache.hadoop.hdds.client.BlockID) BlockData(org.apache.hadoop.ozone.container.common.helpers.BlockData) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 24 with ChunkInfo

use of org.apache.hadoop.ozone.container.common.helpers.ChunkInfo in project ozone by apache.

the class TestContainerPersistence method writeBlockHelper.

private BlockData writeBlockHelper(BlockID blockID, int i) throws IOException, NoSuchAlgorithmException {
    ChunkInfo info = writeChunkHelper(blockID);
    BlockData blockData = new BlockData(blockID);
    blockData.setBlockCommitSequenceId((long) i);
    List<ContainerProtos.ChunkInfo> chunkList = new LinkedList<>();
    chunkList.add(info.getProtoBufMessage());
    blockData.setChunks(chunkList);
    return blockData;
}
Also used : ChunkInfo(org.apache.hadoop.ozone.container.common.helpers.ChunkInfo) BlockData(org.apache.hadoop.ozone.container.common.helpers.BlockData) LinkedList(java.util.LinkedList)

Example 25 with ChunkInfo

use of org.apache.hadoop.ozone.container.common.helpers.ChunkInfo in project ozone by apache.

the class TestContainerPersistence method testDeleteChunk.

/**
 * Writes a chunk and deletes it, re-reads to make sure it is gone.
 *
 * @throws IOException
 * @throws NoSuchAlgorithmException
 */
@Test
public void testDeleteChunk() throws IOException, NoSuchAlgorithmException {
    final int datalen = 1024;
    long testContainerID = getTestContainerID();
    Container container = addContainer(containerSet, testContainerID);
    BlockID blockID = ContainerTestHelper.getTestBlockID(testContainerID);
    ChunkInfo info = getChunk(blockID.getLocalID(), 1, 0, datalen);
    ChunkBuffer data = getData(datalen);
    setDataChecksum(info, data);
    chunkManager.writeChunk(container, blockID, info, data, getDispatcherContext());
    chunkManager.deleteChunk(container, blockID, info);
    exception.expect(StorageContainerException.class);
    chunkManager.readChunk(container, blockID, info, getDispatcherContext());
}
Also used : KeyValueContainer(org.apache.hadoop.ozone.container.keyvalue.KeyValueContainer) Container(org.apache.hadoop.ozone.container.common.interfaces.Container) ChunkInfo(org.apache.hadoop.ozone.container.common.helpers.ChunkInfo) BlockID(org.apache.hadoop.hdds.client.BlockID) ChunkBuffer(org.apache.hadoop.ozone.common.ChunkBuffer) Test(org.junit.Test)

Aggregations

ChunkInfo (org.apache.hadoop.ozone.container.common.helpers.ChunkInfo)40 BlockID (org.apache.hadoop.hdds.client.BlockID)28 KeyValueContainer (org.apache.hadoop.ozone.container.keyvalue.KeyValueContainer)19 Test (org.junit.Test)19 BlockData (org.apache.hadoop.ozone.container.common.helpers.BlockData)18 ChunkBuffer (org.apache.hadoop.ozone.common.ChunkBuffer)14 StorageContainerException (org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException)11 ArrayList (java.util.ArrayList)10 ContainerProtos (org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos)10 ChunkManager (org.apache.hadoop.ozone.container.keyvalue.interfaces.ChunkManager)10 DispatcherContext (org.apache.hadoop.ozone.container.common.transport.server.ratis.DispatcherContext)8 File (java.io.File)7 IOException (java.io.IOException)7 LinkedList (java.util.LinkedList)6 Container (org.apache.hadoop.ozone.container.common.interfaces.Container)6 ByteBuffer (java.nio.ByteBuffer)5 ReferenceCountedDB (org.apache.hadoop.ozone.container.common.utils.ReferenceCountedDB)5 KeyValueContainerData (org.apache.hadoop.ozone.container.keyvalue.KeyValueContainerData)4 OzoneConfiguration (org.apache.hadoop.hdds.conf.OzoneConfiguration)3 RoundRobinVolumeChoosingPolicy (org.apache.hadoop.ozone.container.common.volume.RoundRobinVolumeChoosingPolicy)3