Search in sources :

Example 1 with WriteRequestHeaderProto

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

the class FileStoreStateMachine method read.

@Override
public CompletableFuture<ByteString> read(LogEntryProto entry) {
    final StateMachineLogEntryProto smLog = entry.getStateMachineLogEntry();
    final ByteString data = smLog.getLogData();
    final FileStoreRequestProto proto;
    try {
        proto = FileStoreRequestProto.parseFrom(data);
    } catch (InvalidProtocolBufferException e) {
        return FileStoreCommon.completeExceptionally(entry.getIndex(), "Failed to parse data, entry=" + entry, e);
    }
    if (proto.getRequestCase() != FileStoreRequestProto.RequestCase.WRITEHEADER) {
        return null;
    }
    final WriteRequestHeaderProto h = proto.getWriteHeader();
    CompletableFuture<ExamplesProtos.ReadReplyProto> reply = files.read(h.getPath().toStringUtf8(), h.getOffset(), h.getLength(), false);
    return reply.thenApply(ExamplesProtos.ReadReplyProto::getData);
}
Also used : FileStoreRequestProto(org.apache.ratis.proto.ExamplesProtos.FileStoreRequestProto) ByteString(org.apache.ratis.thirdparty.com.google.protobuf.ByteString) InvalidProtocolBufferException(org.apache.ratis.thirdparty.com.google.protobuf.InvalidProtocolBufferException) WriteRequestHeaderProto(org.apache.ratis.proto.ExamplesProtos.WriteRequestHeaderProto) StateMachineLogEntryProto(org.apache.ratis.proto.RaftProtos.StateMachineLogEntryProto)

Example 2 with WriteRequestHeaderProto

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

the class FileStoreStateMachine method write.

@Override
public CompletableFuture<Integer> write(LogEntryProto entry) {
    final StateMachineLogEntryProto smLog = entry.getStateMachineLogEntry();
    final ByteString data = smLog.getLogData();
    final FileStoreRequestProto proto;
    try {
        proto = FileStoreRequestProto.parseFrom(data);
    } catch (InvalidProtocolBufferException e) {
        return FileStoreCommon.completeExceptionally(entry.getIndex(), "Failed to parse data, entry=" + entry, e);
    }
    if (proto.getRequestCase() != FileStoreRequestProto.RequestCase.WRITEHEADER) {
        return null;
    }
    final WriteRequestHeaderProto h = proto.getWriteHeader();
    final CompletableFuture<Integer> f = files.write(entry.getIndex(), h.getPath().toStringUtf8(), h.getClose(), h.getSync(), h.getOffset(), smLog.getStateMachineEntry().getStateMachineData());
    // sync only if closing the file
    return h.getClose() ? f : null;
}
Also used : FileStoreRequestProto(org.apache.ratis.proto.ExamplesProtos.FileStoreRequestProto) ByteString(org.apache.ratis.thirdparty.com.google.protobuf.ByteString) InvalidProtocolBufferException(org.apache.ratis.thirdparty.com.google.protobuf.InvalidProtocolBufferException) WriteRequestHeaderProto(org.apache.ratis.proto.ExamplesProtos.WriteRequestHeaderProto) StateMachineLogEntryProto(org.apache.ratis.proto.RaftProtos.StateMachineLogEntryProto)

Aggregations

FileStoreRequestProto (org.apache.ratis.proto.ExamplesProtos.FileStoreRequestProto)2 WriteRequestHeaderProto (org.apache.ratis.proto.ExamplesProtos.WriteRequestHeaderProto)2 StateMachineLogEntryProto (org.apache.ratis.proto.RaftProtos.StateMachineLogEntryProto)2 ByteString (org.apache.ratis.thirdparty.com.google.protobuf.ByteString)2 InvalidProtocolBufferException (org.apache.ratis.thirdparty.com.google.protobuf.InvalidProtocolBufferException)2