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 2021/03/17 10:47:42 UTC

[GitHub] [ratis] bshashikant opened a new pull request #449: RATIS-1326. NotifyInstallSnapshot during SetConfiguration has leader info missing.

bshashikant opened a new pull request #449:
URL: https://github.com/apache/ratis/pull/449


   ## What changes were proposed in this pull request?
   Fixed missing leader info during installSnapshot.
   ## What is the link to the Apache JIRA
   https://issues.apache.org/jira/browse/RATIS-1326
   
   ## How was this patch tested?
   Modified existing unit tests.
   
   


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

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



[GitHub] [ratis] szetszwo commented on a change in pull request #449: RATIS-1326. NotifyInstallSnapshot during SetConfiguration has leader info missing.

Posted by GitBox <gi...@apache.org>.
szetszwo commented on a change in pull request #449:
URL: https://github.com/apache/ratis/pull/449#discussion_r595937602



##########
File path: ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java
##########
@@ -526,13 +526,21 @@ RoleInfoProto getRoleInfoProto() {
       break;
 
     case FOLLOWER:
-      role.getFollowerState().ifPresent(fs -> {
-        final ServerRpcProto leaderInfo = ServerProtoUtils.toServerRpcProto(
-            getRaftConf().getPeer(state.getLeaderId()), fs.getLastRpcTime().elapsedTimeMs());
+      if (role.getFollowerState().isPresent()) {
+        final FollowerState fs = role.getFollowerState().get();
+        final ServerRpcProto leaderInfo =
+          ServerProtoUtils.toServerRpcProto(getRaftConf().
+            getPeer(state.getLeaderId()), fs.getLastRpcTime().elapsedTimeMs());
         roleInfo.setFollowerInfo(FollowerInfoProto.newBuilder()
-            .setLeaderInfo(leaderInfo)
-            .setOutstandingOp(fs.getOutstandingOp()));
-      });
+          .setLeaderInfo(leaderInfo).setOutstandingOp(fs.getOutstandingOp()));
+      } else {
+        // FollowerState can be null while adding a new peer as it is not
+        // a voting member yet
+        final ServerRpcProto leaderInfo = ServerProtoUtils.
+          toServerRpcProto(getRaftConf().getPeer(state.getLeaderId()), 0);
+        roleInfo.setFollowerInfo(FollowerInfoProto.newBuilder().
+          setLeaderInfo(leaderInfo).setOutstandingOp(0));
+      }

Review comment:
       Let's change fs to Optional<FollowerState> so that the code can be shorter?
   ```
         final Optional<FollowerState> fs = role.getFollowerState();
         final ServerRpcProto leaderInfo = ServerProtoUtils.toServerRpcProto(
             getRaftConf().getPeer(state.getLeaderId()),
             fs.map(FollowerState::getLastRpcTime).map(Timestamp::elapsedTimeMs).orElse(0L);
         roleInfo.setFollowerInfo(FollowerInfoProto.newBuilder()
             .setLeaderInfo(leaderInfo)
             .setOutstandingOp(fs.map(FollowerState::getOutstandingOp).orElse(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.

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



[GitHub] [ratis] bshashikant commented on pull request #449: RATIS-1326. NotifyInstallSnapshot during SetConfiguration has leader info missing.

Posted by GitBox <gi...@apache.org>.
bshashikant commented on pull request #449:
URL: https://github.com/apache/ratis/pull/449#issuecomment-801051319


   Thanks @szetszwo for the review.


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

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



[GitHub] [ratis] bshashikant merged pull request #449: RATIS-1326. NotifyInstallSnapshot during SetConfiguration has leader info missing.

Posted by GitBox <gi...@apache.org>.
bshashikant merged pull request #449:
URL: https://github.com/apache/ratis/pull/449


   


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

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