You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2022/09/15 14:01:19 UTC

[GitHub] [iotdb] JackieTien97 commented on a diff in pull request #7334: [IOTDB-4421] implement retry in RatisConsensus

JackieTien97 commented on code in PR #7334:
URL: https://github.com/apache/iotdb/pull/7334#discussion_r972017863


##########
consensus/src/main/java/org/apache/iotdb/consensus/ratis/ApplicationStateMachineProxy.java:
##########
@@ -58,6 +59,7 @@ public class ApplicationStateMachineProxy extends BaseStateMachine {
 
   public ApplicationStateMachineProxy(IStateMachine stateMachine, RaftGroupId id) {
     applicationStateMachine = stateMachine;
+    retryPolicy = (IStateMachine.RetryPolicy) applicationStateMachine;

Review Comment:
   ```suggestion
       retryPolicy = applicationStateMachine instance of IStateMachine.RetryPolicy ? (IStateMachine.RetryPolicy) applicationStateMachine : defaultImplementation;
   ```
   Although we will make sure that all the current StateMachine implements `RetryPolicy`, but Consensus layer shouldn't make any assumptions about it.



##########
consensus/src/main/java/org/apache/iotdb/consensus/ratis/ApplicationStateMachineProxy.java:
##########
@@ -117,23 +119,33 @@ public CompletableFuture<Message> applyTransaction(TransactionContext trx) {
               log.getStateMachineLogEntry().getLogData().asReadOnlyByteBuffer());
     }
 
-    Message ret;
+    Message ret = null;
     waitUntilSystemNotReadOnly();
+    TSStatus finalStatus = null;
+    boolean shouldRetry = false;
     do {
       try {
         TSStatus result = applicationStateMachine.write(applicationRequest);
-        ret = new ResponseMessage(result);
-        break;
+

Review Comment:
   ```suggestion
   if (notFirstTry) {
     TimeUnit.MILLISECONDS.sleep(retryPolicy.getSleepTime());
   }
   ```



##########
consensus/src/main/java/org/apache/iotdb/consensus/ratis/ApplicationStateMachineProxy.java:
##########
@@ -117,23 +119,33 @@ public CompletableFuture<Message> applyTransaction(TransactionContext trx) {
               log.getStateMachineLogEntry().getLogData().asReadOnlyByteBuffer());
     }
 
-    Message ret;
+    Message ret = null;
     waitUntilSystemNotReadOnly();
+    TSStatus finalStatus = null;
+    boolean shouldRetry = false;
     do {
       try {
         TSStatus result = applicationStateMachine.write(applicationRequest);
-        ret = new ResponseMessage(result);
-        break;
+
+        finalStatus =
+            (finalStatus == null) ? result : retryPolicy.updateResult(finalStatus, result);
+        shouldRetry = retryPolicy.shouldRetry(finalStatus);
+
+        if (!shouldRetry) {
+          ret = new ResponseMessage(finalStatus);
+          break;
+        }
       } catch (Exception rte) {

Review Comment:
   ```suggestion
         } catch (Throwable rte) {
   ```



##########
consensus/src/main/java/org/apache/iotdb/consensus/ratis/ApplicationStateMachineProxy.java:
##########
@@ -117,23 +119,33 @@ public CompletableFuture<Message> applyTransaction(TransactionContext trx) {
               log.getStateMachineLogEntry().getLogData().asReadOnlyByteBuffer());
     }
 
-    Message ret;
+    Message ret = null;
     waitUntilSystemNotReadOnly();
+    TSStatus finalStatus = null;
+    boolean shouldRetry = false;
     do {
       try {
         TSStatus result = applicationStateMachine.write(applicationRequest);
-        ret = new ResponseMessage(result);
-        break;
+
+        finalStatus =
+            (finalStatus == null) ? result : retryPolicy.updateResult(finalStatus, result);

Review Comment:
   use another `boolean` flag to indicate whether this time is first try in case of retryPolicy.updateResult() return a `null` 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: reviews-unsubscribe@iotdb.apache.org

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