Hi, @wenweihu86 , I think there's an issue in Code Snippet 1 because configuration.getServersList also includes the node itself. If peerMap.get(server.getServerId()) refers to the node itself, the return value will be null, and calling appendEntries(null) will trigger a null pointer exception(see Code Snippet 2 peer.getNextIndex()).
|
for (RaftProto.Server server : configuration.getServersList()) { |
|
final Peer peer = peerMap.get(server.getServerId()); |
|
executorService.submit(new Runnable() { |
|
@Override |
|
public void run() { |
|
appendEntries(peer); |
|
} |
|
}); |
|
} |
Code Snippet 1. Replicate method.
|
try { |
|
long firstLogIndex = raftLog.getFirstLogIndex(); |
|
if (peer.getNextIndex() < firstLogIndex) { |
|
isNeedInstallSnapshot = true; |
|
} |
Code Snippet 2. AppendEntries method.
Suggested fix:
for (RaftProto.Server server : configuration.getServersList()) {
+ if (server.getServerId() == localServer.getServerId()) {
+ continue;
+ }
final Peer peer = peerMap.get(server.getServerId());
executorService.submit(new Runnable() {
@Override
public void run() {
appendEntries(peer);
}
});
}
I'm looking forward to your confirmation, and would be happy to help fix the issue if needed.
Hi, @wenweihu86 , I think there's an issue in
Code Snippet 1becauseconfiguration.getServersListalso includes the node itself. IfpeerMap.get(server.getServerId())refers to the node itself, the return value will be null, and calling appendEntries(null) will trigger a null pointer exception(seeCode Snippet 2peer.getNextIndex()).raft-java/raft-java-core/src/main/java/com/github/wenweihu86/raft/RaftNode.java
Lines 161 to 169 in 50761c6
Code Snippet 1. Replicate method.
raft-java/raft-java-core/src/main/java/com/github/wenweihu86/raft/RaftNode.java
Lines 203 to 207 in 50761c6
Code Snippet 2. AppendEntries method.
Suggested fix:
I'm looking forward to your confirmation, and would be happy to help fix the issue if needed.