Search in sources :

Example 6 with ChunkBuffer

use of org.apache.hadoop.ozone.common.ChunkBuffer in project ozone by apache.

the class TestChunkManagerDummyImpl method dummyManagerReadsAnyChunk.

@Test
public void dummyManagerReadsAnyChunk() throws Exception {
    ChunkManager dummy = createTestSubject();
    ChunkBuffer dataRead = dummy.readChunk(getKeyValueContainer(), getBlockID(), getChunkInfo(), getDispatcherContext());
    assertNotNull(dataRead);
}
Also used : ChunkBuffer(org.apache.hadoop.ozone.common.ChunkBuffer) ChunkManager(org.apache.hadoop.ozone.container.keyvalue.interfaces.ChunkManager) Test(org.junit.Test)

Example 7 with ChunkBuffer

use of org.apache.hadoop.ozone.common.ChunkBuffer in project ozone by apache.

the class TestChunkUtils method serialRead.

@Test
public void serialRead() throws Exception {
    String s = "Hello World";
    byte[] array = s.getBytes(UTF_8);
    ChunkBuffer data = ChunkBuffer.wrap(ByteBuffer.wrap(array));
    Path tempFile = Files.createTempFile(PREFIX, "serial");
    try {
        File file = tempFile.toFile();
        long len = data.limit();
        long offset = 0;
        ChunkUtils.writeData(file, data, offset, len, null, true);
        ByteBuffer[] readBuffers = BufferUtils.assignByteBuffers(len, len);
        ChunkUtils.readData(file, readBuffers, offset, len, null);
        // There should be only one element in readBuffers
        Assert.assertEquals(1, readBuffers.length);
        ByteBuffer readBuffer = readBuffers[0];
        assertArrayEquals(array, readBuffer.array());
        assertEquals(len, readBuffer.remaining());
    } catch (Exception e) {
        LOG.error("Failed to read data", e);
    } finally {
        Files.deleteIfExists(tempFile);
    }
}
Also used : Path(java.nio.file.Path) ChunkBuffer(org.apache.hadoop.ozone.common.ChunkBuffer) File(java.io.File) ByteBuffer(java.nio.ByteBuffer) IOException(java.io.IOException) StorageContainerException(org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException) Test(org.junit.Test)

Example 8 with ChunkBuffer

use of org.apache.hadoop.ozone.common.ChunkBuffer in project ozone by apache.

the class BufferPool method releaseBuffer.

void releaseBuffer(ChunkBuffer chunkBuffer) {
    // always remove from head of the list and append at last
    final ChunkBuffer buffer = bufferList.remove(0);
    // Ensure the buffer to be removed is always at the head of the list.
    Preconditions.checkArgument(buffer == chunkBuffer);
    buffer.clear();
    bufferList.add(buffer);
    Preconditions.checkArgument(currentBufferIndex >= 0);
    currentBufferIndex--;
}
Also used : ChunkBuffer(org.apache.hadoop.ozone.common.ChunkBuffer)

Example 9 with ChunkBuffer

use of org.apache.hadoop.ozone.common.ChunkBuffer in project ozone by apache.

the class TestBlockDeletingService method putChunksInBlock.

private void putChunksInBlock(int numOfChunksPerBlock, int i, List<ContainerProtos.ChunkInfo> chunks, ChunkBuffer buffer, ChunkManager chunkManager, KeyValueContainer container, BlockID blockID) {
    long chunkLength = 100;
    try {
        for (int k = 0; k < numOfChunksPerBlock; k++) {
            final String chunkName = String.format("block.%d.chunk.%d", i, k);
            final long offset = k * chunkLength;
            ContainerProtos.ChunkInfo info = ContainerProtos.ChunkInfo.newBuilder().setChunkName(chunkName).setLen(chunkLength).setOffset(offset).setChecksumData(Checksum.getNoChecksumDataProto()).build();
            chunks.add(info);
            ChunkInfo chunkInfo = new ChunkInfo(chunkName, offset, chunkLength);
            ChunkBuffer chunkData = buffer.duplicate(0, (int) chunkLength);
            chunkManager.writeChunk(container, blockID, chunkInfo, chunkData, WRITE_STAGE);
            chunkManager.writeChunk(container, blockID, chunkInfo, chunkData, COMMIT_STAGE);
        }
    } catch (IOException ex) {
        LOG.warn("Putting chunks in blocks was not successful for BlockID: " + blockID);
    }
}
Also used : ContainerProtos(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos) ChunkInfo(org.apache.hadoop.ozone.container.common.helpers.ChunkInfo) ChunkBuffer(org.apache.hadoop.ozone.common.ChunkBuffer) IOException(java.io.IOException)

Example 10 with ChunkBuffer

use of org.apache.hadoop.ozone.common.ChunkBuffer in project ozone by apache.

the class TestContainerPersistence method writeChunkHelper.

private ChunkInfo writeChunkHelper(BlockID blockID) throws IOException {
    final int datalen = 1024;
    long commitBytesBefore = 0;
    long commitBytesAfter = 0;
    long commitDecrement = 0;
    long testContainerID = blockID.getContainerID();
    Container container = containerSet.getContainer(testContainerID);
    if (container == null) {
        container = addContainer(containerSet, testContainerID);
    }
    ChunkInfo info = getChunk(blockID.getLocalID(), 0, 0, datalen);
    ChunkBuffer data = getData(datalen);
    setDataChecksum(info, data);
    commitBytesBefore = container.getContainerData().getVolume().getCommittedBytes();
    chunkManager.writeChunk(container, blockID, info, data, getDispatcherContext());
    commitBytesAfter = container.getContainerData().getVolume().getCommittedBytes();
    commitDecrement = commitBytesBefore - commitBytesAfter;
    // did we decrement commit bytes by the amount of data we wrote?
    Assert.assertTrue(commitDecrement == info.getLen());
    return info;
}
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) ChunkBuffer(org.apache.hadoop.ozone.common.ChunkBuffer)

Aggregations

ChunkBuffer (org.apache.hadoop.ozone.common.ChunkBuffer)30 BlockID (org.apache.hadoop.hdds.client.BlockID)14 ChunkInfo (org.apache.hadoop.ozone.container.common.helpers.ChunkInfo)14 Test (org.junit.Test)13 IOException (java.io.IOException)10 ContainerProtos (org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos)9 StorageContainerException (org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException)8 KeyValueContainer (org.apache.hadoop.ozone.container.keyvalue.KeyValueContainer)8 ArrayList (java.util.ArrayList)6 BlockData (org.apache.hadoop.ozone.container.common.helpers.BlockData)5 CompletableFuture (java.util.concurrent.CompletableFuture)4 ContainerCommandResponseProto (org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandResponseProto)4 XceiverClientReply (org.apache.hadoop.hdds.scm.XceiverClientReply)4 XceiverClientSpi (org.apache.hadoop.hdds.scm.XceiverClientSpi)4 Pipeline (org.apache.hadoop.hdds.scm.pipeline.Pipeline)4 Container (org.apache.hadoop.ozone.container.common.interfaces.Container)4 ChunkManager (org.apache.hadoop.ozone.container.keyvalue.interfaces.ChunkManager)4 ByteBuffer (java.nio.ByteBuffer)3 Path (java.nio.file.Path)3 LinkedList (java.util.LinkedList)3