You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ratis.apache.org by "BUAAserein (via GitHub)" <gi...@apache.org> on 2023/07/27 07:57:15 UTC

[GitHub] [ratis] BUAAserein opened a new pull request, #895: RATIS-1861. leaderState is updated after server becomes leader

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

   see [jira1861](https://issues.apache.org/jira/browse/RATIS-1861).


-- 
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 #895: RATIS-1861. NullPointerException in readAsync when Ratis leader is changing

Posted by "szetszwo (via GitHub)" <gi...@apache.org>.
szetszwo commented on code in PR #895:
URL: https://github.com/apache/ratis/pull/895#discussion_r1276632473


##########
ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java:
##########
@@ -597,10 +597,11 @@ synchronized void changeToLeader() {
     Preconditions.assertTrue(getInfo().isCandidate());
     role.shutdownLeaderElection();
     setRole(RaftPeerRole.LEADER, "changeToLeader");
+    role.updateLeaderState(this);

Review Comment:
   Let's store the LeaderStateImpl and then use it later.
   ```java
   @@ -603,10 +603,11 @@ class RaftServerImpl implements RaftServer.Division,
        Preconditions.assertTrue(getInfo().isCandidate());
        role.shutdownLeaderElection();
        setRole(RaftPeerRole.LEADER, "changeToLeader");
   +    final LeaderStateImpl leader = role.updateLeaderState(this);
        state.becomeLeader();
    
        // start sending AppendEntries RPC to followers
   -    final LogEntryProto e = role.startLeaderState(this);
   +    final LogEntryProto e = leader.start();
        getState().setRaftConf(e);
      }
   ```



##########
ratis-server/src/main/java/org/apache/ratis/server/impl/RoleInfo.java:
##########
@@ -79,8 +79,12 @@ LeaderStateImpl getLeaderStateNonNull() {
     return Objects.requireNonNull(leaderState.get(), "leaderState is null");
   }
 
-  LogEntryProto startLeaderState(RaftServerImpl server) {
-    return updateAndGet(leaderState, new LeaderStateImpl(server)).start();
+  void updateLeaderState(RaftServerImpl server) {
+    updateAndGet(leaderState, new LeaderStateImpl(server));
+  }
+
+  LogEntryProto startLeaderState() {
+    return leaderState.get().start();

Review Comment:
   Then, we don't need the new `startLeaderState()` method.
   ```java
   +++ b/ratis-server/src/main/java/org/apache/ratis/server/impl/RoleInfo.java
   @@ -79,8 +79,8 @@ class RoleInfo {
        return Objects.requireNonNull(leaderState.get(), "leaderState is null");
      }
    
   -  LogEntryProto startLeaderState(RaftServerImpl server) {
   -    return updateAndGet(leaderState, new LeaderStateImpl(server)).start();
   +  LeaderStateImpl updateLeaderState(RaftServerImpl server) {
   +    return updateAndGet(leaderState, new LeaderStateImpl(server));
      }
    
   ```j



-- 
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 #895: RATIS-1861. NullPointerException in readAsync when Ratis leader is changing

Posted by "szetszwo (via GitHub)" <gi...@apache.org>.
szetszwo merged PR #895:
URL: https://github.com/apache/ratis/pull/895


-- 
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] BUAAserein commented on a diff in pull request #895: RATIS-1861. NullPointerException in readAsync when Ratis leader is changing

Posted by "BUAAserein (via GitHub)" <gi...@apache.org>.
BUAAserein commented on code in PR #895:
URL: https://github.com/apache/ratis/pull/895#discussion_r1277040727


##########
ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java:
##########
@@ -597,10 +597,11 @@ synchronized void changeToLeader() {
     Preconditions.assertTrue(getInfo().isCandidate());
     role.shutdownLeaderElection();
     setRole(RaftPeerRole.LEADER, "changeToLeader");
+    role.updateLeaderState(this);

Review Comment:
   OK



-- 
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] BUAAserein commented on a diff in pull request #895: RATIS-1861. NullPointerException in readAsync when Ratis leader is changing

Posted by "BUAAserein (via GitHub)" <gi...@apache.org>.
BUAAserein commented on code in PR #895:
URL: https://github.com/apache/ratis/pull/895#discussion_r1277042469


##########
ratis-server/src/main/java/org/apache/ratis/server/impl/RoleInfo.java:
##########
@@ -79,8 +79,12 @@ LeaderStateImpl getLeaderStateNonNull() {
     return Objects.requireNonNull(leaderState.get(), "leaderState is null");
   }
 
-  LogEntryProto startLeaderState(RaftServerImpl server) {
-    return updateAndGet(leaderState, new LeaderStateImpl(server)).start();
+  void updateLeaderState(RaftServerImpl server) {
+    updateAndGet(leaderState, new LeaderStateImpl(server));
+  }
+
+  LogEntryProto startLeaderState() {
+    return leaderState.get().start();

Review Comment:
   Done. Thanks a lot for the comments!



-- 
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