Search in sources :

Example 6 with RPCProtoMessage

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

the class NettyPacketWriter method sendEOF.

/**
   * Sends an empty packet to signify the EOF.
   */
private void sendEOF() {
    final long pos;
    mLock.lock();
    try {
        if (mEOFSent) {
            return;
        }
        mEOFSent = true;
        pos = mPosToQueue;
    } finally {
        mLock.unlock();
    }
    // Write the last packet.
    Protocol.WriteRequest writeRequest = Protocol.WriteRequest.newBuilder().setId(mId).setOffset(pos).setSessionId(mSessionId).setTier(mTier).setType(mRequestType).build();
    mChannel.writeAndFlush(new RPCProtoMessage(new ProtoMessage(writeRequest), null)).addListener(ChannelFutureListener.CLOSE_ON_FAILURE);
}
Also used : ProtoMessage(alluxio.util.proto.ProtoMessage) RPCProtoMessage(alluxio.network.protocol.RPCProtoMessage) RPCProtoMessage(alluxio.network.protocol.RPCProtoMessage) Protocol(alluxio.proto.dataserver.Protocol)

Example 7 with RPCProtoMessage

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

the class DataServerReadHandlerTest method checkReadResponse.

/**
   * Checks the read response message given the expected error code.
   *
   * @param readResponse the read response
   * @param codeExpected the expected error code
   * @return the data buffer extracted from the read response
   */
protected DataBuffer checkReadResponse(Object readResponse, Protocol.Status.Code codeExpected) {
    Assert.assertTrue(readResponse instanceof RPCProtoMessage);
    ProtoMessage response = ((RPCProtoMessage) readResponse).getMessage();
    Assert.assertTrue(response.getType() == ProtoMessage.Type.RESPONSE);
    Assert.assertEquals(codeExpected, response.<Protocol.Response>getMessage().getStatus().getCode());
    return ((RPCProtoMessage) readResponse).getPayloadDataBuffer();
}
Also used : RPCProtoMessage(alluxio.network.protocol.RPCProtoMessage) ProtoMessage(alluxio.util.proto.ProtoMessage) RPCProtoMessage(alluxio.network.protocol.RPCProtoMessage) Protocol(alluxio.proto.dataserver.Protocol)

Example 8 with RPCProtoMessage

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

the class DataServerUFSFileWriteHandlerTest method buildWriteRequest.

@Override
protected RPCProtoMessage buildWriteRequest(long offset, int len) {
    Protocol.WriteRequest writeRequest = Protocol.WriteRequest.newBuilder().setId(1L).setOffset(offset).setType(Protocol.RequestType.UFS_FILE).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 9 with RPCProtoMessage

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

the class DataServerWriteHandlerTest method checkWriteResponse.

/**
   * Checks the given write response is expected and matches the given error code.
   *
   * @param writeResponse the write response
   * @param codeExpected the expected error code
   */
protected void checkWriteResponse(Object writeResponse, Protocol.Status.Code codeExpected) {
    Assert.assertTrue(writeResponse instanceof RPCProtoMessage);
    ProtoMessage response = ((RPCProtoMessage) writeResponse).getMessage();
    Assert.assertTrue(response.getType() == ProtoMessage.Type.RESPONSE);
    Assert.assertEquals(codeExpected, response.<Protocol.Response>getMessage().getStatus().getCode());
}
Also used : RPCProtoMessage(alluxio.network.protocol.RPCProtoMessage) ProtoMessage(alluxio.util.proto.ProtoMessage) RPCProtoMessage(alluxio.network.protocol.RPCProtoMessage) Protocol(alluxio.proto.dataserver.Protocol)

Example 10 with RPCProtoMessage

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

the class DataServerReadHandlerTest method cancelRequest.

/**
   * Cancels the read request immediately after the read request is sent.
   */
@Test
public void cancelRequest() throws Exception {
    long fileSize = PACKET_SIZE * 10 + 1;
    populateInputFile(fileSize, 0, fileSize - 1);
    RPCProtoMessage readRequest = buildReadRequest(0, fileSize);
    Protocol.ReadRequest request = readRequest.getMessage().getMessage();
    RPCProtoMessage cancelRequest = new RPCProtoMessage(new ProtoMessage(request.toBuilder().setCancel(true).build()), null);
    mChannel.writeInbound(readRequest);
    mChannel.writeInbound(cancelRequest);
    // Make sure we can still get EOF after cancelling though the read request is not necessarily
    // fulfilled.
    boolean eof = false;
    long maxIterations = 100;
    while (maxIterations > 0) {
        Object response = waitForOneResponse(mChannel);
        DataBuffer buffer = checkReadResponse(response, Protocol.Status.Code.OK);
        if (buffer == null) {
            eof = true;
            break;
        }
        buffer.release();
        maxIterations--;
        Assert.assertTrue(mChannel.isOpen());
    }
    Assert.assertTrue(eof);
}
Also used : RPCProtoMessage(alluxio.network.protocol.RPCProtoMessage) ProtoMessage(alluxio.util.proto.ProtoMessage) RPCProtoMessage(alluxio.network.protocol.RPCProtoMessage) Protocol(alluxio.proto.dataserver.Protocol) DataBuffer(alluxio.network.protocol.databuffer.DataBuffer) Test(org.junit.Test)

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