Search in sources :

Example 6 with ByteString

use of org.apache.ratis.thirdparty.com.google.protobuf.ByteString in project incubator-ratis by apache.

the class TestRaftId method testRaftGroupId.

@Test
public void testRaftGroupId() {
    final RaftGroupId id = RaftGroupId.randomId();
    final ByteString bytes = id.toByteString();
    Assert.assertEquals(bytes, id.toByteString());
    Assert.assertEquals(id, RaftGroupId.valueOf(bytes));
}
Also used : ByteString(org.apache.ratis.thirdparty.com.google.protobuf.ByteString) Test(org.junit.Test) BaseTest(org.apache.ratis.BaseTest)

Example 7 with ByteString

use of org.apache.ratis.thirdparty.com.google.protobuf.ByteString in project incubator-ratis by apache.

the class FileStoreClient method write.

public long write(String path, long offset, boolean close, ByteBuffer buffer, boolean sync) throws IOException {
    final int chunkSize = FileStoreCommon.getChunkSize(buffer.remaining());
    buffer.limit(chunkSize);
    final ByteString reply = writeImpl(this::send, path, offset, close, buffer, sync);
    return WriteReplyProto.parseFrom(reply).getLength();
}
Also used : ByteString(org.apache.ratis.thirdparty.com.google.protobuf.ByteString)

Example 8 with ByteString

use of org.apache.ratis.thirdparty.com.google.protobuf.ByteString 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 9 with ByteString

use of org.apache.ratis.thirdparty.com.google.protobuf.ByteString in project incubator-ratis by apache.

the class FileStoreStateMachine method stream.

@Override
public CompletableFuture<DataStream> stream(RaftClientRequest request) {
    final ByteString reqByteString = request.getMessage().getContent();
    final FileStoreRequestProto proto;
    try {
        proto = FileStoreRequestProto.parseFrom(reqByteString);
    } catch (InvalidProtocolBufferException e) {
        return FileStoreCommon.completeExceptionally("Failed to parse stream header", e);
    }
    return files.createDataChannel(proto.getStream().getPath().toStringUtf8()).thenApply(LocalStream::new);
}
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)

Example 10 with ByteString

use of org.apache.ratis.thirdparty.com.google.protobuf.ByteString 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

ByteString (org.apache.ratis.thirdparty.com.google.protobuf.ByteString)19 FileStoreRequestProto (org.apache.ratis.proto.ExamplesProtos.FileStoreRequestProto)4 RaftClientReply (org.apache.ratis.protocol.RaftClientReply)4 InvalidProtocolBufferException (org.apache.ratis.thirdparty.com.google.protobuf.InvalidProtocolBufferException)4 Test (org.junit.Test)4 BaseTest (org.apache.ratis.BaseTest)3 SimpleMessage (org.apache.ratis.RaftTestUtil.SimpleMessage)3 RaftClient (org.apache.ratis.client.RaftClient)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 WriteRequestHeaderProto (org.apache.ratis.proto.ExamplesProtos.WriteRequestHeaderProto)2 StateMachineLogEntryProto (org.apache.ratis.proto.RaftProtos.StateMachineLogEntryProto)2 RaftPeerId (org.apache.ratis.protocol.RaftPeerId)2 TimeDuration (org.apache.ratis.util.TimeDuration)2 Gauge (com.codahale.metrics.Gauge)1 ByteBuffer (java.nio.ByteBuffer)1 Collection (java.util.Collection)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Random (java.util.Random)1