Search in sources :

Example 1 with DataFileChannel

use of alluxio.network.protocol.databuffer.DataFileChannel in project alluxio by Alluxio.

the class RPCMessageIntegrationTest method RPCBlockReadResponseFileChannel.

@Test
public void RPCBlockReadResponseFileChannel() throws IOException {
    try (FileInputStream inputStream = getTempFileInputStream()) {
        FileChannel payload = inputStream.getChannel();
        RPCBlockReadResponse msg = new RPCBlockReadResponse(BLOCK_ID, OFFSET, LENGTH, new DataFileChannel(payload, OFFSET, LENGTH), RPCResponse.Status.SUCCESS);
        RPCBlockReadResponse decoded = (RPCBlockReadResponse) encodeThenDecode(msg);
        assertValid(msg, decoded);
    }
}
Also used : DataFileChannel(alluxio.network.protocol.databuffer.DataFileChannel) FileChannel(java.nio.channels.FileChannel) FileInputStream(java.io.FileInputStream) DataFileChannel(alluxio.network.protocol.databuffer.DataFileChannel) Test(org.junit.Test)

Example 2 with DataFileChannel

use of alluxio.network.protocol.databuffer.DataFileChannel in project alluxio by Alluxio.

the class DataServerBlockReadHandler method getDataBuffer.

@Override
protected DataBuffer getDataBuffer(Channel channel, long offset, int len) throws IOException {
    BlockReader blockReader = ((BlockReadRequestInternal) mRequest).mBlockReader;
    Preconditions.checkArgument(blockReader.getChannel() instanceof FileChannel, "Only FileChannel is supported!");
    switch(mTransferType) {
        case MAPPED:
            ByteBuf buf = channel.alloc().buffer(len, len);
            try {
                FileChannel fileChannel = (FileChannel) blockReader.getChannel();
                Preconditions.checkState(fileChannel.position() == offset);
                while (buf.writableBytes() > 0 && buf.writeBytes(fileChannel, buf.writableBytes()) != -1) {
                }
                return new DataNettyBufferV2(buf);
            } catch (Throwable e) {
                buf.release();
                throw e;
            }
        // intend to fall through as TRANSFER is the default type.
        case TRANSFER:
        default:
            return new DataFileChannel((FileChannel) blockReader.getChannel(), offset, len);
    }
}
Also used : DataFileChannel(alluxio.network.protocol.databuffer.DataFileChannel) FileChannel(java.nio.channels.FileChannel) BlockReader(alluxio.worker.block.io.BlockReader) DataNettyBufferV2(alluxio.network.protocol.databuffer.DataNettyBufferV2) ByteBuf(io.netty.buffer.ByteBuf) DataFileChannel(alluxio.network.protocol.databuffer.DataFileChannel)

Example 3 with DataFileChannel

use of alluxio.network.protocol.databuffer.DataFileChannel in project alluxio by Alluxio.

the class DataServerReadHandlerTest method checkAllReadResponses.

/**
   * Checks all the read responses.
   */
protected void checkAllReadResponses(EmbeddedChannel channel, long checksumExpected) {
    boolean eof = false;
    long checksumActual = 0;
    while (!eof) {
        Object readResponse = waitForOneResponse(channel);
        if (readResponse == null) {
            Assert.fail();
            break;
        }
        DataBuffer buffer = checkReadResponse(readResponse, Protocol.Status.Code.OK);
        eof = buffer == null;
        if (buffer != null) {
            if (buffer instanceof DataNettyBufferV2) {
                ByteBuf buf = (ByteBuf) buffer.getNettyOutput();
                while (buf.readableBytes() > 0) {
                    checksumActual += BufferUtils.byteToInt(buf.readByte());
                }
                buf.release();
            } else {
                Assert.assertTrue(buffer instanceof DataFileChannel);
                ByteBuffer buf = buffer.getReadOnlyByteBuffer();
                byte[] array = new byte[buf.remaining()];
                buf.get(array);
                for (int i = 0; i < array.length; i++) {
                    checksumActual += BufferUtils.byteToInt(array[i]);
                }
            }
        }
    }
    Assert.assertEquals(checksumExpected, checksumActual);
    Assert.assertTrue(eof);
}
Also used : DataNettyBufferV2(alluxio.network.protocol.databuffer.DataNettyBufferV2) ByteBuf(io.netty.buffer.ByteBuf) ByteBuffer(java.nio.ByteBuffer) DataBuffer(alluxio.network.protocol.databuffer.DataBuffer) DataFileChannel(alluxio.network.protocol.databuffer.DataFileChannel)

Aggregations

DataFileChannel (alluxio.network.protocol.databuffer.DataFileChannel)3 DataNettyBufferV2 (alluxio.network.protocol.databuffer.DataNettyBufferV2)2 ByteBuf (io.netty.buffer.ByteBuf)2 FileChannel (java.nio.channels.FileChannel)2 DataBuffer (alluxio.network.protocol.databuffer.DataBuffer)1 BlockReader (alluxio.worker.block.io.BlockReader)1 FileInputStream (java.io.FileInputStream)1 ByteBuffer (java.nio.ByteBuffer)1 Test (org.junit.Test)1