runzhiwang commented on a change in pull request #470:
URL: https://github.com/apache/ratis/pull/470#discussion_r632242074
##########
File path:
ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java
##########
@@ -1560,21 +1565,28 @@ private InstallSnapshotReplyProto
notifyStateMachineToInstallSnapshot(
return reply;
}
- Optional<RaftPeerProto> leaderPeerInfo = null;
+ RaftPeerProto leaderPeerInfo = null;
if (request.hasLastRaftConfigurationLogEntryProto()) {
List<RaftPeerProto> peerList =
request.getLastRaftConfigurationLogEntryProto().getConfigurationEntry()
.getPeersList();
- leaderPeerInfo = peerList.stream().filter(p ->
RaftPeerId.valueOf(p.getId()).equals(leaderId)).findFirst();
- Preconditions.assertTrue(leaderPeerInfo.isPresent());
+ Optional<RaftPeerProto> optionalLeaderPeerInfo = peerList.stream()
+ .filter(p ->
RaftPeerId.valueOf(p.getId()).equals(leaderId)).findFirst();
+ leaderPeerInfo = (optionalLeaderPeerInfo.isPresent()) ?
optionalLeaderPeerInfo.get() : null;
}
// For the cases where RaftConf is empty on newly started peer with
// empty peer list, we retrieve leader info from
// installSnapShotRequestProto.
- RoleInfoProto roleInfoProto =
- getRaftConf().getPeer(state.getLeaderId()) == null ?
- getRoleInfoProto(ProtoUtils.toRaftPeer(leaderPeerInfo.get())) :
- getRoleInfoProto();
+ RoleInfoProto roleInfoProto;
+ RaftPeer raftPeer = getRaftConf().getPeer(state.getLeaderId());
+ if (raftPeer == null && leaderPeerInfo != null) {
Review comment:
please use the following code:
```
if (raftPeer == null) {
if (leaderPeerInfo != null) {
roleInfoProto =
getRoleInfoProto(ProtoUtils.toRaftPeer(leaderPeerInfo));
} else {
throw new IOException("Leader peer info is unknown.");
}
} else {
roleInfoProto = getRoleInfoProto();
}
```
--
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:
[email protected]