Search in sources :

Example 1 with RPCBlockReadRequest

use of alluxio.network.protocol.RPCBlockReadRequest in project alluxio by Alluxio.

the class ClientHandlerTest method channelRead0ThrowsException.

/**
   * Makes sure that an {@link IllegalArgumentException} is thrown when the message is
   * not a {@link alluxio.network.protocol.RPCResponse}.
   */
@Test
public void channelRead0ThrowsException() throws IOException {
    final RPCMessage message = new RPCBlockReadRequest(0, 0, 0, 0, 0);
    mThrown.expect(IllegalArgumentException.class);
    mThrown.expectMessage(ExceptionMessage.NO_RPC_HANDLER.getMessage(message.getType()));
    mHandler.channelRead0(mContext, message);
}
Also used : RPCBlockReadRequest(alluxio.network.protocol.RPCBlockReadRequest) RPCMessage(alluxio.network.protocol.RPCMessage) Test(org.junit.Test)

Example 2 with RPCBlockReadRequest

use of alluxio.network.protocol.RPCBlockReadRequest in project alluxio by Alluxio.

the class DataServerHandler method channelRead0.

@Override
public void channelRead0(final ChannelHandlerContext ctx, final RPCMessage msg) throws IOException {
    LOG.debug("Enter: {}", msg);
    try {
        switch(msg.getType()) {
            case RPC_BLOCK_READ_REQUEST:
                assert msg instanceof RPCBlockReadRequest;
                mBlockHandler.handleBlockReadRequest(ctx, (RPCBlockReadRequest) msg);
                break;
            case RPC_BLOCK_WRITE_REQUEST:
                assert msg instanceof RPCBlockWriteRequest;
                mBlockHandler.handleBlockWriteRequest(ctx, (RPCBlockWriteRequest) msg);
                break;
            case RPC_FILE_READ_REQUEST:
                assert msg instanceof RPCFileReadRequest;
                mUnderFileSystemHandler.handleFileReadRequest(ctx, (RPCFileReadRequest) msg);
                break;
            case RPC_FILE_WRITE_REQUEST:
                assert msg instanceof RPCFileWriteRequest;
                mUnderFileSystemHandler.handleFileWriteRequest(ctx, (RPCFileWriteRequest) msg);
                break;
            case RPC_UFS_BLOCK_READ_REQUEST:
                assert msg instanceof RPCUnderFileSystemBlockReadRequest;
                mBlockHandler.handleUnderFileSystemBlockReadRequest(ctx, (RPCUnderFileSystemBlockReadRequest) msg);
                break;
            case RPC_ERROR_RESPONSE:
                assert msg instanceof RPCErrorResponse;
                LOG.error("Received an error response from the client: " + msg.toString());
                break;
            case RPC_READ_REQUEST:
            case RPC_WRITE_REQUEST:
            case RPC_RESPONSE:
                assert msg instanceof RPCProtoMessage;
                ctx.fireChannelRead(msg);
                break;
            default:
                RPCErrorResponse resp = new RPCErrorResponse(RPCResponse.Status.UNKNOWN_MESSAGE_ERROR);
                ctx.writeAndFlush(resp);
                // TODO(peis): Fix this. We should not throw an exception here.
                throw new IllegalArgumentException("No handler implementation for " + msg.getType());
        }
    } catch (IllegalArgumentException | IOException e) {
        LOG.warn("{}, Error={}", msg, e.getMessage());
        LOG.debug("{}", msg, e);
        LOG.debug("Exit (Error): {}, Error={}", msg, e.getMessage());
        // Rethrow the exception to use Netty's control flow.
        throw e;
    }
    LOG.debug("Exit (OK): {}", msg);
}
Also used : RPCUnderFileSystemBlockReadRequest(alluxio.network.protocol.RPCUnderFileSystemBlockReadRequest) RPCBlockWriteRequest(alluxio.network.protocol.RPCBlockWriteRequest) RPCBlockReadRequest(alluxio.network.protocol.RPCBlockReadRequest) RPCFileWriteRequest(alluxio.network.protocol.RPCFileWriteRequest) RPCErrorResponse(alluxio.network.protocol.RPCErrorResponse) RPCProtoMessage(alluxio.network.protocol.RPCProtoMessage) IOException(java.io.IOException) RPCFileReadRequest(alluxio.network.protocol.RPCFileReadRequest)

Example 3 with RPCBlockReadRequest

use of alluxio.network.protocol.RPCBlockReadRequest in project alluxio by Alluxio.

the class NettyDataServerTest method readBlock.

@Test
public void readBlock() throws Exception {
    long sessionId = 0;
    long blockId = 1;
    long offset = 2;
    long length = 3;
    long lockId = 4;
    when(mBlockWorker.readBlockRemote(sessionId, blockId, lockId)).thenReturn(new MockBlockReader("abcdefg".getBytes(Charsets.UTF_8)));
    RPCResponse response = request(new RPCBlockReadRequest(blockId, offset, length, lockId, sessionId));
    // Verify that the 3 bytes were read at offset 2.
    assertEquals("cde", Charsets.UTF_8.decode(response.getPayloadDataBuffer().getReadOnlyByteBuffer()).toString());
}
Also used : RPCBlockReadRequest(alluxio.network.protocol.RPCBlockReadRequest) RPCResponse(alluxio.network.protocol.RPCResponse) MockBlockReader(alluxio.worker.block.io.MockBlockReader) Test(org.junit.Test)

Example 4 with RPCBlockReadRequest

use of alluxio.network.protocol.RPCBlockReadRequest in project alluxio by Alluxio.

the class NettyDataServerTest method blockWorkerBlockDoesNotExistExceptionCausesFileDneStatus.

@Test
public void blockWorkerBlockDoesNotExistExceptionCausesFileDneStatus() throws Exception {
    when(mBlockWorker.readBlockRemote(anyLong(), anyLong(), anyLong())).thenThrow(new BlockDoesNotExistException(""));
    RPCResponse response = request(new RPCBlockReadRequest(1, 2, 3, 4, 0));
    // Verify that the read request failed with a FILE_DNE status.
    assertEquals(RPCResponse.Status.FILE_DNE, response.getStatus());
}
Also used : RPCBlockReadRequest(alluxio.network.protocol.RPCBlockReadRequest) RPCResponse(alluxio.network.protocol.RPCResponse) BlockDoesNotExistException(alluxio.exception.BlockDoesNotExistException) Test(org.junit.Test)

Example 5 with RPCBlockReadRequest

use of alluxio.network.protocol.RPCBlockReadRequest in project alluxio by Alluxio.

the class NettyRemoteBlockReader method readRemoteBlock.

@Override
public ByteBuffer readRemoteBlock(InetSocketAddress address, long blockId, long offset, long length, long lockId, long sessionId) throws IOException {
    Channel channel = null;
    ClientHandler clientHandler = null;
    Metrics.NETTY_BLOCK_READ_OPS.inc();
    try {
        channel = mContext.acquireNettyChannel(address);
        if (!(channel.pipeline().last() instanceof ClientHandler)) {
            channel.pipeline().addLast(new ClientHandler());
        }
        clientHandler = (ClientHandler) channel.pipeline().last();
        SingleResponseListener listener = new SingleResponseListener();
        clientHandler.addListener(listener);
        ChannelFuture channelFuture = channel.writeAndFlush(new RPCBlockReadRequest(blockId, offset, length, lockId, sessionId));
        channelFuture = channelFuture.sync();
        if (channelFuture.isDone() && !channelFuture.isSuccess()) {
            LOG.error("Failed to write to %s for block %d with error %s.", address.toString(), blockId, channelFuture.cause());
            throw new IOException(channelFuture.cause());
        }
        RPCResponse response = listener.get(NettyClient.TIMEOUT_MS, TimeUnit.MILLISECONDS);
        switch(response.getType()) {
            case RPC_BLOCK_READ_RESPONSE:
                RPCBlockReadResponse blockResponse = (RPCBlockReadResponse) response;
                LOG.debug("Data {} from remote machine {} received", blockId, address);
                RPCResponse.Status status = blockResponse.getStatus();
                if (status == RPCResponse.Status.SUCCESS) {
                    // always clear the previous response before reading another one
                    close();
                    mReadResponse = blockResponse;
                    return blockResponse.getPayloadDataBuffer().getReadOnlyByteBuffer();
                }
                throw new IOException(status.getMessage() + " response: " + blockResponse);
            case RPC_ERROR_RESPONSE:
                RPCErrorResponse error = (RPCErrorResponse) response;
                throw new IOException(error.getStatus().getMessage());
            default:
                throw new IOException(ExceptionMessage.UNEXPECTED_RPC_RESPONSE.getMessage(response.getType(), RPCMessage.Type.RPC_BLOCK_READ_RESPONSE));
        }
    } catch (Exception e) {
        Metrics.NETTY_BLOCK_READ_FAILURES.inc();
        try {
            if (channel != null) {
                channel.close().sync();
            }
        } catch (InterruptedException ee) {
            throw Throwables.propagate(ee);
        }
        throw new IOException(e);
    } finally {
        if (clientHandler != null) {
            clientHandler.removeListeners();
        }
        if (channel != null) {
            mContext.releaseNettyChannel(address, channel);
        }
    }
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) RPCBlockReadRequest(alluxio.network.protocol.RPCBlockReadRequest) Channel(io.netty.channel.Channel) RPCErrorResponse(alluxio.network.protocol.RPCErrorResponse) RPCResponse(alluxio.network.protocol.RPCResponse) RPCBlockReadResponse(alluxio.network.protocol.RPCBlockReadResponse) IOException(java.io.IOException) IOException(java.io.IOException)

Aggregations

RPCBlockReadRequest (alluxio.network.protocol.RPCBlockReadRequest)7 RPCResponse (alluxio.network.protocol.RPCResponse)5 Test (org.junit.Test)5 RPCErrorResponse (alluxio.network.protocol.RPCErrorResponse)2 IOException (java.io.IOException)2 BlockDoesNotExistException (alluxio.exception.BlockDoesNotExistException)1 RPCBlockReadResponse (alluxio.network.protocol.RPCBlockReadResponse)1 RPCBlockWriteRequest (alluxio.network.protocol.RPCBlockWriteRequest)1 RPCFileReadRequest (alluxio.network.protocol.RPCFileReadRequest)1 RPCFileWriteRequest (alluxio.network.protocol.RPCFileWriteRequest)1 RPCMessage (alluxio.network.protocol.RPCMessage)1 RPCProtoMessage (alluxio.network.protocol.RPCProtoMessage)1 RPCUnderFileSystemBlockReadRequest (alluxio.network.protocol.RPCUnderFileSystemBlockReadRequest)1 MockBlockReader (alluxio.worker.block.io.MockBlockReader)1 Channel (io.netty.channel.Channel)1 ChannelFuture (io.netty.channel.ChannelFuture)1