Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replicate method calls the AppendEntries method on servers without skipping itself #52

Open
liang636600 opened this issue Oct 14, 2024 · 0 comments

Comments

@liang636600
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant