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);
}
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);
}
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());
}
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());
}
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);
}
}
}
Aggregations