Search in sources :

Example 1 with RPCProtoMessage

use of alluxio.network.protocol.RPCProtoMessage 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 2 with RPCProtoMessage

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

the class DataServerBlockWriteHandlerTest method buildWriteRequest.

@Override
protected RPCProtoMessage buildWriteRequest(long offset, int len) {
    Protocol.WriteRequest writeRequest = Protocol.WriteRequest.newBuilder().setId(1L).setOffset(offset).setSessionId(1L).setType(Protocol.RequestType.ALLUXIO_BLOCK).build();
    DataBuffer buffer = null;
    if (len > 0) {
        ByteBuf buf = PooledByteBufAllocator.DEFAULT.buffer(len);
        for (int i = 0; i < len; i++) {
            byte value = (byte) (mRandom.nextInt() % Byte.MAX_VALUE);
            buf.writeByte(value);
            mChecksum += BufferUtils.byteToInt(value);
        }
        buffer = new DataNettyBufferV2(buf);
    }
    return new RPCProtoMessage(new ProtoMessage(writeRequest), buffer);
}
Also used : RPCProtoMessage(alluxio.network.protocol.RPCProtoMessage) ProtoMessage(alluxio.util.proto.ProtoMessage) RPCProtoMessage(alluxio.network.protocol.RPCProtoMessage) DataNettyBufferV2(alluxio.network.protocol.databuffer.DataNettyBufferV2) Protocol(alluxio.proto.dataserver.Protocol) ByteBuf(io.netty.buffer.ByteBuf) DataBuffer(alluxio.network.protocol.databuffer.DataBuffer)

Example 3 with RPCProtoMessage

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

the class DataServerWriteHandler method channelRead.

@Override
public void channelRead(ChannelHandlerContext ctx, Object object) throws Exception {
    if (!acceptMessage(object)) {
        ctx.fireChannelRead(object);
        return;
    }
    RPCProtoMessage msg = (RPCProtoMessage) object;
    initializeRequest(msg);
    // Validate msg and return error if invalid. Init variables if necessary.
    String error = validateRequest(msg);
    if (!error.isEmpty()) {
        replyError(ctx.channel(), Protocol.Status.Code.INVALID_ARGUMENT, error, null);
        return;
    }
    mLock.lock();
    try {
        DataBuffer dataBuffer = msg.getPayloadDataBuffer();
        ByteBuf buf;
        if (dataBuffer == null) {
            buf = ctx.alloc().buffer(0, 0);
        } else {
            Preconditions.checkState(dataBuffer.getLength() > 0);
            assert dataBuffer.getNettyOutput() instanceof ByteBuf;
            buf = (ByteBuf) dataBuffer.getNettyOutput();
        }
        mPosToQueue += buf.readableBytes();
        mPackets.offer(buf);
        if (!mPacketWriterActive) {
            mPacketWriterExecutor.submit(new PacketWriter(ctx));
            mPacketWriterActive = true;
        }
        if (tooManyPacketsInFlight()) {
            ctx.channel().config().setAutoRead(false);
        }
    } finally {
        mLock.unlock();
    }
}
Also used : RPCProtoMessage(alluxio.network.protocol.RPCProtoMessage) ByteBuf(io.netty.buffer.ByteBuf) DataBuffer(alluxio.network.protocol.databuffer.DataBuffer)

Example 4 with RPCProtoMessage

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

the class NettyPacketReader method close.

@Override
public void close() {
    try {
        if (mDone) {
            return;
        }
        if (!mChannel.isOpen()) {
            return;
        }
        try {
            if (!CANCEL_ENABLED) {
                mChannel.close().sync();
                return;
            }
            if (remaining() > 0) {
                Protocol.ReadRequest cancelRequest = Protocol.ReadRequest.newBuilder().setId(mId).setCancel(true).setType(mRequestType).setNoCache(mNoCache).build();
                mChannel.writeAndFlush(new RPCProtoMessage(new ProtoMessage(cancelRequest))).addListener(ChannelFutureListener.CLOSE_ON_FAILURE);
            }
        } catch (InterruptedException e) {
            mChannel.close();
            throw Throwables.propagate(e);
        }
        while (true) {
            try {
                DataBuffer buf = readPacket();
                // A null packet indicates the end of the stream.
                if (buf == null) {
                    return;
                }
                buf.release();
            } catch (IOException e) {
                LOG.warn("Failed to close the NettyBlockReader (block: {}, address: {}).", mId, mAddress, e);
                try {
                    mChannel.close().sync();
                } catch (InterruptedException ee) {
                    throw Throwables.propagate(ee);
                }
                return;
            }
        }
    } finally {
        if (mChannel.isOpen()) {
            mChannel.pipeline().removeLast();
            // Make sure "autoread" is on before realsing the channel.
            resume();
        }
        mContext.releaseNettyChannel(mAddress, mChannel);
        mClosed = true;
    }
}
Also used : ProtoMessage(alluxio.util.proto.ProtoMessage) RPCProtoMessage(alluxio.network.protocol.RPCProtoMessage) RPCProtoMessage(alluxio.network.protocol.RPCProtoMessage) IOException(java.io.IOException) Protocol(alluxio.proto.dataserver.Protocol) DataBuffer(alluxio.network.protocol.databuffer.DataBuffer)

Example 5 with RPCProtoMessage

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

the class NettyPacketWriter method writePacket.

@Override
public void writePacket(final ByteBuf buf) throws IOException {
    final long len;
    final long offset;
    mLock.lock();
    try {
        Preconditions.checkState(!mClosed && !mEOFSent);
        Preconditions.checkArgument(buf.readableBytes() <= PACKET_SIZE);
        while (true) {
            if (mPacketWriteException != null) {
                throw new IOException(mPacketWriteException);
            }
            if (!tooManyPacketsInFlight()) {
                offset = mPosToQueue;
                mPosToQueue += buf.readableBytes();
                len = buf.readableBytes();
                break;
            }
            try {
                if (!mBufferNotFullOrFailed.await(WRITE_TIMEOUT_MS, TimeUnit.MILLISECONDS)) {
                    throw new IOException(String.format("Timeout to write packet to %d @ %s.", mId, mAddress));
                }
            } catch (InterruptedException e) {
                throw Throwables.propagate(e);
            }
        }
    } catch (Throwable e) {
        buf.release();
        throw e;
    } finally {
        mLock.unlock();
    }
    Protocol.WriteRequest writeRequest = Protocol.WriteRequest.newBuilder().setId(mId).setOffset(offset).setSessionId(mSessionId).setTier(mTier).setType(mRequestType).build();
    DataBuffer dataBuffer = new DataNettyBufferV2(buf);
    mChannel.writeAndFlush(new RPCProtoMessage(new ProtoMessage(writeRequest), dataBuffer)).addListener(new WriteListener(offset + len));
}
Also used : ProtoMessage(alluxio.util.proto.ProtoMessage) RPCProtoMessage(alluxio.network.protocol.RPCProtoMessage) RPCProtoMessage(alluxio.network.protocol.RPCProtoMessage) DataNettyBufferV2(alluxio.network.protocol.databuffer.DataNettyBufferV2) IOException(java.io.IOException) Protocol(alluxio.proto.dataserver.Protocol) DataBuffer(alluxio.network.protocol.databuffer.DataBuffer)

Aggregations

RPCProtoMessage (alluxio.network.protocol.RPCProtoMessage)10 Protocol (alluxio.proto.dataserver.Protocol)8 ProtoMessage (alluxio.util.proto.ProtoMessage)8 DataBuffer (alluxio.network.protocol.databuffer.DataBuffer)6 DataNettyBufferV2 (alluxio.network.protocol.databuffer.DataNettyBufferV2)3 ByteBuf (io.netty.buffer.ByteBuf)3 IOException (java.io.IOException)3 RPCBlockReadRequest (alluxio.network.protocol.RPCBlockReadRequest)1 RPCBlockWriteRequest (alluxio.network.protocol.RPCBlockWriteRequest)1 RPCErrorResponse (alluxio.network.protocol.RPCErrorResponse)1 RPCFileReadRequest (alluxio.network.protocol.RPCFileReadRequest)1 RPCFileWriteRequest (alluxio.network.protocol.RPCFileWriteRequest)1 RPCUnderFileSystemBlockReadRequest (alluxio.network.protocol.RPCUnderFileSystemBlockReadRequest)1 Test (org.junit.Test)1