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));
}
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();
}
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);
}
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);
}
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;
}
Aggregations