Search in sources :

Example 1 with WriteRequestProto

use of org.apache.ratis.proto.ExamplesProtos.WriteRequestProto 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)1 StreamWriteRequestProto (org.apache.ratis.proto.ExamplesProtos.StreamWriteRequestProto)1 WriteRequestProto (org.apache.ratis.proto.ExamplesProtos.WriteRequestProto)1 TransactionContext (org.apache.ratis.statemachine.TransactionContext)1 ByteString (org.apache.ratis.thirdparty.com.google.protobuf.ByteString)1