Skip to content

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

Open

Description

@liang636600

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions