Search in sources :

Example 6 with FileStoreRequestProto

use of org.apache.ratis.proto.ExamplesProtos.FileStoreRequestProto in project incubator-ratis by apache.

the class FileStoreClient method getStreamOutput.

public DataStreamOutput getStreamOutput(String path, long dataSize, RoutingTable routingTable) {
    final StreamWriteRequestProto header = StreamWriteRequestProto.newBuilder().setPath(ProtoUtils.toByteString(path)).setLength(dataSize).build();
    final FileStoreRequestProto request = FileStoreRequestProto.newBuilder().setStream(header).build();
    return client.getDataStreamApi().stream(request.toByteString().asReadOnlyByteBuffer(), routingTable);
}
Also used : FileStoreRequestProto(org.apache.ratis.proto.ExamplesProtos.FileStoreRequestProto) StreamWriteRequestProto(org.apache.ratis.proto.ExamplesProtos.StreamWriteRequestProto)

Example 7 with FileStoreRequestProto

use of org.apache.ratis.proto.ExamplesProtos.FileStoreRequestProto in project incubator-ratis by apache.

the class FileStoreClient method writeImpl.

private static <OUTPUT, THROWABLE extends Throwable> OUTPUT writeImpl(CheckedFunction<ByteString, OUTPUT, THROWABLE> sendFunction, String path, long offset, boolean close, ByteBuffer data, boolean sync) throws THROWABLE {
    final WriteRequestHeaderProto.Builder header = WriteRequestHeaderProto.newBuilder().setPath(ProtoUtils.toByteString(path)).setOffset(offset).setLength(data.remaining()).setClose(close).setSync(sync);
    final WriteRequestProto.Builder write = WriteRequestProto.newBuilder().setHeader(header).setData(ByteString.copyFrom(data));
    final FileStoreRequestProto request = FileStoreRequestProto.newBuilder().setWrite(write).build();
    return sendFunction.apply(request.toByteString());
}
Also used : FileStoreRequestProto(org.apache.ratis.proto.ExamplesProtos.FileStoreRequestProto) WriteRequestHeaderProto(org.apache.ratis.proto.ExamplesProtos.WriteRequestHeaderProto) WriteRequestProto(org.apache.ratis.proto.ExamplesProtos.WriteRequestProto) StreamWriteRequestProto(org.apache.ratis.proto.ExamplesProtos.StreamWriteRequestProto)

Example 8 with FileStoreRequestProto

use of org.apache.ratis.proto.ExamplesProtos.FileStoreRequestProto in project incubator-ratis by apache.

the class FileStoreStateMachine method startTransaction.

@Override
public TransactionContext startTransaction(RaftClientRequest request) throws IOException {
    final ByteString content = request.getMessage().getContent();
    final FileStoreRequestProto proto = FileStoreRequestProto.parseFrom(content);
    final TransactionContext.Builder b = TransactionContext.newBuilder().setStateMachine(this).setClientRequest(request);
    if (proto.getRequestCase() == FileStoreRequestProto.RequestCase.WRITE) {
        final WriteRequestProto write = proto.getWrite();
        final FileStoreRequestProto newProto = FileStoreRequestProto.newBuilder().setWriteHeader(write.getHeader()).build();
        b.setLogData(newProto.toByteString()).setStateMachineData(write.getData());
    } else {
        b.setLogData(content);
    }
    return b.build();
}
Also used : FileStoreRequestProto(org.apache.ratis.proto.ExamplesProtos.FileStoreRequestProto) ByteString(org.apache.ratis.thirdparty.com.google.protobuf.ByteString) TransactionContext(org.apache.ratis.statemachine.TransactionContext) WriteRequestProto(org.apache.ratis.proto.ExamplesProtos.WriteRequestProto) StreamWriteRequestProto(org.apache.ratis.proto.ExamplesProtos.StreamWriteRequestProto)

Aggregations

FileStoreRequestProto (org.apache.ratis.proto.ExamplesProtos.FileStoreRequestProto)8 ByteString (org.apache.ratis.thirdparty.com.google.protobuf.ByteString)4 InvalidProtocolBufferException (org.apache.ratis.thirdparty.com.google.protobuf.InvalidProtocolBufferException)4 StreamWriteRequestProto (org.apache.ratis.proto.ExamplesProtos.StreamWriteRequestProto)3 WriteRequestHeaderProto (org.apache.ratis.proto.ExamplesProtos.WriteRequestHeaderProto)3 StateMachineLogEntryProto (org.apache.ratis.proto.RaftProtos.StateMachineLogEntryProto)3 WriteRequestProto (org.apache.ratis.proto.ExamplesProtos.WriteRequestProto)2 DeleteRequestProto (org.apache.ratis.proto.ExamplesProtos.DeleteRequestProto)1 LogEntryProto (org.apache.ratis.proto.RaftProtos.LogEntryProto)1 TransactionContext (org.apache.ratis.statemachine.TransactionContext)1