Search in sources :

Example 1 with WriteRequestCommand

use of alluxio.grpc.WriteRequestCommand in project alluxio by Alluxio.

the class AbstractWriteHandler method write.

/**
 * Handles write request.
 *
 * @param writeRequest the request from the client
 */
public void write(WriteRequest writeRequest) {
    if (!tryAcquireSemaphore()) {
        return;
    }
    mSerializingExecutor.execute(() -> {
        try {
            if (mContext == null) {
                LOG.debug("Received write request {}.", RpcSensitiveConfigMask.CREDENTIAL_FIELD_MASKER.maskObjects(LOG, writeRequest));
                try {
                    mContext = createRequestContext(writeRequest);
                } catch (Exception e) {
                    // abort() assumes context is initialized.
                    // Reply with the error in order to prevent clients getting stuck.
                    replyError(new Error(AlluxioStatusException.fromThrowable(e), true));
                    throw e;
                }
            } else {
                Preconditions.checkState(!mContext.isDoneUnsafe(), "invalid request after write request is completed.");
            }
            if (mContext.isDoneUnsafe() || mContext.getError() != null) {
                return;
            }
            validateWriteRequest(writeRequest);
            if (writeRequest.hasCommand()) {
                WriteRequestCommand command = writeRequest.getCommand();
                if (command.getFlush()) {
                    flush();
                } else {
                    handleCommand(command, mContext);
                }
            } else {
                Preconditions.checkState(writeRequest.hasChunk(), "write request is missing data chunk in non-command message");
                ByteString data = writeRequest.getChunk().getData();
                Preconditions.checkState(data != null && data.size() > 0, "invalid data size from write request message");
                writeData(new NioDataBuffer(data.asReadOnlyByteBuffer(), data.size()));
            }
        } catch (Exception e) {
            LogUtils.warnWithException(LOG, "Exception occurred while processing write request {}.", writeRequest, e);
            abort(new Error(AlluxioStatusException.fromThrowable(e), true));
        } finally {
            mSemaphore.release();
        }
    });
}
Also used : WriteRequestCommand(alluxio.grpc.WriteRequestCommand) ByteString(com.google.protobuf.ByteString) NioDataBuffer(alluxio.network.protocol.databuffer.NioDataBuffer) AlluxioStatusException(alluxio.exception.status.AlluxioStatusException) InvalidArgumentException(alluxio.exception.status.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException)

Aggregations

AlluxioStatusException (alluxio.exception.status.AlluxioStatusException)1 InvalidArgumentException (alluxio.exception.status.InvalidArgumentException)1 WriteRequestCommand (alluxio.grpc.WriteRequestCommand)1 NioDataBuffer (alluxio.network.protocol.databuffer.NioDataBuffer)1 ByteString (com.google.protobuf.ByteString)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1