[ 
https://issues.apache.org/jira/browse/RATIS-2055?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17838365#comment-17838365
 ] 

Tsz-wo Sze commented on RATIS-2055:
-----------------------------------

The compatibility problem is easy to fix in Ratis (although it is a bug in 
Ozone since SCM uses notifyTermIndexUpdated(..) to set the leader is ready. The 
correct way is to use notifyLeaderReady() as [~Symious] mentioned.)  We may 
move down the notifyTermIndexUpdated(..) call as below.  Would you like to 
submit a pull request?
{code}
+++ 
b/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java
@@ -1805,9 +1805,6 @@ class RaftServerImpl implements RaftServer.Division,
   CompletableFuture<Message> 
applyLogToStateMachine(ReferenceCountedObject<LogEntryProto> nextRef)
       throws RaftLogIOException {
     LogEntryProto next = nextRef.get();
-    if (!next.hasStateMachineLogEntry()) {
-      stateMachine.event().notifyTermIndexUpdated(next.getTerm(), 
next.getIndex());
-    }
 
     if (next.hasConfigurationEntry()) {
       // the reply should have already been set. only need to record
@@ -1830,6 +1827,7 @@ class RaftServerImpl implements RaftServer.Division,
         throw new RaftLogIOException(e);
       }
     }
+    stateMachine.event().notifyTermIndexUpdated(next.getTerm(), 
next.getIndex());
     return null;
   }
{code} 




> Changed logic of LeaderState.isReady impacts application
> --------------------------------------------------------
>
>                 Key: RATIS-2055
>                 URL: https://issues.apache.org/jira/browse/RATIS-2055
>             Project: Ratis
>          Issue Type: Bug
>          Components: Leader
>    Affects Versions: 3.1.0
>            Reporter: Duong
>            Priority: Major
>
> RATIS-2019 changes the logic of `LeaderState.isReady`. Before, isReady itself 
> performs the logic to check if the leader state is ready. After the change, 
> the logic is moved to `LeaderState.checkReady` and `isReady` now only reads 
> the result.
> This change impacts client applications that rely on `isReady` check. For 
> example, Ozone's SCMStateMachine [listens to notifyTermIndexUpdated 
> |https://github.com/apache/ozone/blob/5ff79613e546a09f23b2c3bae61d62fb757eaf70/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/ha/SCMStateMachine.java#L359]
>  and checks if the leader state is ready. However, because the 
> `leader.checkReady` is called after the `notifyTermIndexUpdated`, 
> SCMStateMachine never sees leader ready state in the intercepted 
> `notifyTermIndexUpdated` events.
> {code:java|title=RaftServerImpl.applyLogToStateMachine}
> CompletableFuture<Message> 
> applyLogToStateMachine(ReferenceCountedObject<LogEntryProto> nextRef)
>     throws RaftLogIOException {
>   LogEntryProto next = nextRef.get();
>   if (!next.hasStateMachineLogEntry()) {
>     stateMachine.event().notifyTermIndexUpdated(next.getTerm(), 
> next.getIndex());
>   }
>   if (next.hasConfigurationEntry()) {
>     // the reply should have already been set. only need to record
>     // the new conf in the metadata file and notify the StateMachine.
>     state.writeRaftConfiguration(next);
>     stateMachine.event().notifyConfigurationChanged(next.getTerm(), 
> next.getIndex(), next.getConfigurationEntry());
>     role.getLeaderState().ifPresent(leader -> leader.checkReady(next)); 
> ....{code}
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to