You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ratis.apache.org by GitBox <gi...@apache.org> on 2022/12/08 09:20:46 UTC

[GitHub] [ratis] SzyWilliam opened a new pull request, #797: RATIS-1758. Add linearizable read in Counter example

SzyWilliam opened a new pull request, #797:
URL: https://github.com/apache/ratis/pull/797

   ## What changes were proposed in this pull request?
   
   Add linearizable read usage in Counter example.
   Also fixed some problems in ratis-examples/README
   
   ## What is the link to the Apache JIRA
   https://issues.apache.org/jira/browse/RATIS-1758
   
   ## How was this patch tested?
   
   manual test.
   ![WX20221208-170241](https://user-images.githubusercontent.com/48054931/206407663-415baba0-ade7-45bf-8010-5496afd1f9a3.png)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ratis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ratis] szetszwo merged pull request #797: RATIS-1758. Add linearizable read in Counter example

Posted by GitBox <gi...@apache.org>.
szetszwo merged PR #797:
URL: https://github.com/apache/ratis/pull/797


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ratis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ratis] SzyWilliam commented on a diff in pull request #797: RATIS-1758. Add linearizable read in Counter example

Posted by GitBox <gi...@apache.org>.
SzyWilliam commented on code in PR #797:
URL: https://github.com/apache/ratis/pull/797#discussion_r1044306932


##########
ratis-examples/src/main/java/org/apache/ratis/examples/counter/server/CounterServer.java:
##########
@@ -80,35 +90,46 @@ public void close() throws IOException {
 
   public static void main(String[] args) {
     try {
-      //get peerIndex from the arguments
-      if (args.length != 1) {
-        throw new IllegalArgumentException("Invalid argument number: expected to be 1 but actual is " + args.length);
+      //get peerIndex & simulatedSlowness from the arguments
+      if (args.length != 1 && args.length != 2) {
+        throw new IllegalArgumentException("Invalid argument number: expected to be 1 or 2 but actual is "
+            + args.length);
       }
       final int peerIndex = Integer.parseInt(args[0]);
       if (peerIndex < 0 || peerIndex > 2) {
         throw new IllegalArgumentException("The server index must be 0, 1 or 2: peerIndex=" + peerIndex);
       }
+      TimeDuration simulatedSlowness = TimeDuration.ZERO;
+      if (args.length == 2) {
+        final int slowness = Integer.parseInt(args[1]);

Review Comment:
   Done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ratis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ratis] SzyWilliam commented on a diff in pull request #797: RATIS-1758. Add linearizable read in Counter example

Posted by GitBox <gi...@apache.org>.
SzyWilliam commented on code in PR #797:
URL: https://github.com/apache/ratis/pull/797#discussion_r1044249306


##########
ratis-examples/src/main/java/org/apache/ratis/examples/counter/server/CounterServer.java:
##########
@@ -52,6 +52,7 @@ public CounterServer(RaftPeer peer, File storageDir) throws IOException {
 
     //set the storage directory (different for each peer) in the RaftProperty object
     RaftServerConfigKeys.setStorageDir(properties, Collections.singletonList(storageDir));
+    RaftServerConfigKeys.Read.setOption(properties, RaftServerConfigKeys.Read.Option.LINEARIZABLE);

Review Comment:
   Done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ratis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ratis] SzyWilliam commented on pull request #797: RATIS-1758. Add linearizable read in Counter example

Posted by GitBox <gi...@apache.org>.
SzyWilliam commented on PR #797:
URL: https://github.com/apache/ratis/pull/797#issuecomment-1344071099

   @szetszwo Thanks for your advices! I've made changes according to these steps and verified linearizable read, see the following screenshot.
   ![WX20221209-171535](https://user-images.githubusercontent.com/48054931/206670207-c35d5657-13a2-4846-a31a-2b72e96fc502.png)
   The original purpose of this PR is to simply demonstrate linearizable read usages. Hope that this patch will not make it too complicated for users to grasp.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ratis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ratis] szetszwo commented on pull request #797: RATIS-1758. Add linearizable read in Counter example

Posted by GitBox <gi...@apache.org>.
szetszwo commented on PR #797:
URL: https://github.com/apache/ratis/pull/797#issuecomment-1344099289

   > ... I've made changes according to these steps and verified linearizable read, see the following screenshot. ...
   
   Thanks a lot for trying it!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ratis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ratis] SzyWilliam commented on a diff in pull request #797: RATIS-1758. Add linearizable read in Counter example

Posted by GitBox <gi...@apache.org>.
SzyWilliam commented on code in PR #797:
URL: https://github.com/apache/ratis/pull/797#discussion_r1044307965


##########
ratis-examples/src/main/resources/conf.properties:
##########
@@ -15,4 +15,5 @@
 # limitations under the License.
 
 raft.server.address.list=127.0.0.1:10024,127.0.0.1:10124,127.0.0.1:11124
-# raft.server.root.storage.path
\ No newline at end of file
+# raft.server.root.storage.path
+# raft.server.priority.list=1,0,0

Review Comment:
   It's a great idea! Saved me many nasty parsing code.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ratis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ratis] szetszwo commented on a diff in pull request #797: RATIS-1758. Add linearizable read in Counter example

Posted by GitBox <gi...@apache.org>.
szetszwo commented on code in PR #797:
URL: https://github.com/apache/ratis/pull/797#discussion_r1044275482


##########
ratis-examples/src/main/java/org/apache/ratis/examples/counter/server/CounterServer.java:
##########
@@ -80,35 +90,46 @@ public void close() throws IOException {
 
   public static void main(String[] args) {
     try {
-      //get peerIndex from the arguments
-      if (args.length != 1) {
-        throw new IllegalArgumentException("Invalid argument number: expected to be 1 but actual is " + args.length);
+      //get peerIndex & simulatedSlowness from the arguments
+      if (args.length != 1 && args.length != 2) {
+        throw new IllegalArgumentException("Invalid argument number: expected to be 1 or 2 but actual is "
+            + args.length);
       }
       final int peerIndex = Integer.parseInt(args[0]);
       if (peerIndex < 0 || peerIndex > 2) {
         throw new IllegalArgumentException("The server index must be 0, 1 or 2: peerIndex=" + peerIndex);
       }
+      TimeDuration simulatedSlowness = TimeDuration.ZERO;
+      if (args.length == 2) {
+        final int slowness = Integer.parseInt(args[1]);

Review Comment:
   Use  `TimeDuration.valueOf(String timeString, TimeUnit defaultUnit)`.
   



##########
ratis-examples/src/main/resources/conf.properties:
##########
@@ -15,4 +15,5 @@
 # limitations under the License.
 
 raft.server.address.list=127.0.0.1:10024,127.0.0.1:10124,127.0.0.1:11124
-# raft.server.root.storage.path
\ No newline at end of file
+# raft.server.root.storage.path
+# raft.server.priority.list=1,0,0

Review Comment:
   How about adding slowness list here instead of passing it in CLI?
   ```
   # raft.server.simulated-slowness.list=0,1s,0
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ratis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ratis] codings-dan commented on a diff in pull request #797: RATIS-1758. Add linearizable read in Counter example

Posted by GitBox <gi...@apache.org>.
codings-dan commented on code in PR #797:
URL: https://github.com/apache/ratis/pull/797#discussion_r1043309170


##########
ratis-examples/src/main/java/org/apache/ratis/examples/counter/server/CounterServer.java:
##########
@@ -52,6 +52,7 @@ public CounterServer(RaftPeer peer, File storageDir) throws IOException {
 
     //set the storage directory (different for each peer) in the RaftProperty object
     RaftServerConfigKeys.setStorageDir(properties, Collections.singletonList(storageDir));
+    RaftServerConfigKeys.Read.setOption(properties, RaftServerConfigKeys.Read.Option.LINEARIZABLE);

Review Comment:
   Please add a comment to explain what this parameter does



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ratis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ratis] szetszwo commented on pull request #797: RATIS-1758. Add linearizable read in Counter example

Posted by GitBox <gi...@apache.org>.
szetszwo commented on PR #797:
URL: https://github.com/apache/ratis/pull/797#issuecomment-1343277835

   @SzyWilliam , I got some idea to use the Counter example to test Linearizable Read:
   - Add a configurable SIMULATED_SLOWNESS to the `CounterStateMachine` -- add a sleep time such that it will sleep in each `applyTransaction(..)` call.
   - Setup a 3-node (n0, n1, n2) cluster as following
     - Set n0 to have a higher priority, so it will always be the leader.
     - Set n1 to be slow -- set SIMULATED_SLOWNESS to 1 second or higher.
   - After the cluster started
     - run a client to update the leader 10 times.
     - after that, read from the n1 to see if it will wait (~10s) and get the latest value.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@ratis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org