ratis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From msi...@apache.org
Subject incubator-ratis git commit: RATIS-462. Add readStateMachineData api for FileStoreStateMachine. Contributed by Mukul Kumar Singh.
Date Thu, 20 Dec 2018 16:30:58 GMT
Repository: incubator-ratis
Updated Branches:
  refs/heads/master 09cc126d7 -> 5a8495eb2


RATIS-462. Add readStateMachineData api for FileStoreStateMachine. Contributed by Mukul Kumar
Singh.


Project: http://git-wip-us.apache.org/repos/asf/incubator-ratis/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ratis/commit/5a8495eb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ratis/tree/5a8495eb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ratis/diff/5a8495eb

Branch: refs/heads/master
Commit: 5a8495eb287339a528b153396da6cd8c79c676b5
Parents: 09cc126
Author: Mukul Kumar Singh <msingh@apache.org>
Authored: Thu Dec 20 22:00:38 2018 +0530
Committer: Mukul Kumar Singh <msingh@apache.org>
Committed: Thu Dec 20 22:00:38 2018 +0530

----------------------------------------------------------------------
 .../examples/filestore/FileStoreClient.java     |  1 +
 .../filestore/FileStoreStateMachine.java        | 23 ++++++++++++++++++++
 ratis-proto/src/main/proto/Examples.proto       |  1 +
 3 files changed, 25 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/5a8495eb/ratis-examples/src/main/java/org/apache/ratis/examples/filestore/FileStoreClient.java
----------------------------------------------------------------------
diff --git a/ratis-examples/src/main/java/org/apache/ratis/examples/filestore/FileStoreClient.java
b/ratis-examples/src/main/java/org/apache/ratis/examples/filestore/FileStoreClient.java
index c671dee..a7c9fee 100644
--- a/ratis-examples/src/main/java/org/apache/ratis/examples/filestore/FileStoreClient.java
+++ b/ratis-examples/src/main/java/org/apache/ratis/examples/filestore/FileStoreClient.java
@@ -155,6 +155,7 @@ public class FileStoreClient implements Closeable {
     final WriteRequestHeaderProto.Builder header = WriteRequestHeaderProto.newBuilder()
         .setPath(ProtoUtils.toByteString(path))
         .setOffset(offset)
+        .setLength(data.position())
         .setClose(close);
 
     final WriteRequestProto.Builder write = WriteRequestProto.newBuilder()

http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/5a8495eb/ratis-examples/src/main/java/org/apache/ratis/examples/filestore/FileStoreStateMachine.java
----------------------------------------------------------------------
diff --git a/ratis-examples/src/main/java/org/apache/ratis/examples/filestore/FileStoreStateMachine.java
b/ratis-examples/src/main/java/org/apache/ratis/examples/filestore/FileStoreStateMachine.java
index 73f6d93..921b1bf 100644
--- a/ratis-examples/src/main/java/org/apache/ratis/examples/filestore/FileStoreStateMachine.java
+++ b/ratis-examples/src/main/java/org/apache/ratis/examples/filestore/FileStoreStateMachine.java
@@ -19,6 +19,7 @@ package org.apache.ratis.examples.filestore;
 
 import org.apache.ratis.conf.ConfUtils;
 import org.apache.ratis.conf.RaftProperties;
+import org.apache.ratis.proto.ExamplesProtos;
 import org.apache.ratis.proto.ExamplesProtos.DeleteReplyProto;
 import org.apache.ratis.proto.ExamplesProtos.DeleteRequestProto;
 import org.apache.ratis.proto.ExamplesProtos.FileStoreRequestProto;
@@ -131,6 +132,28 @@ public class FileStoreStateMachine extends BaseStateMachine {
   }
 
   @Override
+  public CompletableFuture<ByteString> readStateMachineData(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());
+
+    return reply.thenApply(ExamplesProtos.ReadReplyProto::getData);
+  }
+
+  @Override
   public CompletableFuture<Message> applyTransaction(TransactionContext trx) {
     final LogEntryProto entry = trx.getLogEntry();
 

http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/5a8495eb/ratis-proto/src/main/proto/Examples.proto
----------------------------------------------------------------------
diff --git a/ratis-proto/src/main/proto/Examples.proto b/ratis-proto/src/main/proto/Examples.proto
index c2e2500..407fa27 100644
--- a/ratis-proto/src/main/proto/Examples.proto
+++ b/ratis-proto/src/main/proto/Examples.proto
@@ -39,6 +39,7 @@ message WriteRequestHeaderProto {
   bytes path = 1;
   bool close = 2; // close the file after write?
   uint64 offset = 3;
+  uint64 length = 4;
 }
 
 message WriteRequestProto {


Mime
View raw message