Skip to content

RATIS-2849. Correlate concurrent leadership-transfer election RPCs - #1721

Merged
szetszwo merged 2 commits into
apache:masterfrom
ivandika3:RATIS-2849
Dec 4, 2026
Merged

szetszwo merged 2 commits into
apache:masterfrom
ivandika3:RATIS-2849

Conversation

@ivandika3

@ivandika3 ivandika3 commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Generated-by: GPT 6.1 Sol

Please see https://issues.apache.org/jira/browse/RATIS-2849

We need to add callId for StartLeaderElection request and response to correlate a specific request with a response. Technically, this only affects Netty transport (not gRPC) since gRPC internal logic already correlate the request and response internally.

In Netty transport, NettyRpcProxy.Connection.replies is a map of CallID -> Reply. If we don't set this and there are two concurrent requests with default CallID 0, the latter request will fail the Preconditions.assertNull(previous, "previous") and this can make the latter request to timeout, among other possible issues.

What is the link to the Apache JIRA

https://issues.apache.org/jira/browse/RATIS-2849

How was this patch tested?

UT.

@ivandika3 ivandika3 self-assigned this Dec 3, 2026

@szetszwo szetszwo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ivandika3 , thanks for working on this!

Just some minor comments inlined. See also https://issues.apache.org/jira/secure/attachment/13086847/1721_review.patch


static StartLeaderElectionReplyProto toStartLeaderElectionReplyProto(
RaftPeerId requestorId, RaftGroupMemberId replyId, boolean success) {
RaftPeerId requestorId, RaftGroupMemberId replyId, boolean success, long callId) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to be consistent with ClientProtoUtils.toRaftRpcReplyProtoBuilder, let's swap success and callId, i.e.

  static StartLeaderElectionReplyProto toStartLeaderElectionReplyProto(
      RaftPeerId requestorId, RaftGroupMemberId replyId, long callId, boolean success) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, updated.

RaftPeerId requestorId, RaftGroupMemberId replyId, boolean success, long callId) {
return StartLeaderElectionReplyProto.newBuilder()
.setServerReply(toRaftRpcReplyProtoBuilder(requestorId, replyId, success))
.setServerReply(toRaftRpcReplyProtoBuilder(requestorId, replyId, success).setCallId(callId))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

   private static RaftRpcReplyProto.Builder toRaftRpcReplyProtoBuilder(
-      RaftPeerId requestorId, RaftGroupMemberId replyId, boolean success) {
+      RaftPeerId requestorId, RaftGroupMemberId replyId, Long callId, boolean success) {
     return ClientProtoUtils.toRaftRpcReplyProtoBuilder(
-        requestorId.toByteString(), replyId.getPeerId().toByteString(), replyId.getGroupId(), null, success);
+        requestorId.toByteString(), replyId.getPeerId().toByteString(), replyId.getGroupId(), callId, success);
   }
  • Let's add a callId parameter to toRaftRpcReplyProtoBuilder, which currently pass null callId to ClientProtoUtils.toRaftRpcReplyProtoBuilder as above.
  • For the other rpcs such as toInstallSnapshotReplyProto and toReadIndexReplyProto, they probably have a similar bug. See if you would fix it here or we can fix it separately. (we can pass null as the callId parameter for now)

@ivandika3 ivandika3 Dec 4, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a callId parameter to toRaftRpcReplyProtoBuilder, which currently pass null callId to ClientProtoUtils.toRaftRpcReplyProtoBuilder as above.

Thanks for the review, updated.

For the other rpcs such as toInstallSnapshotReplyProto and toReadIndexReplyProto, they probably have a similar bug. See if you would fix it here or we can fix it separately. (we can pass null as the callId parameter for now)

Let's address it in another ticket. Checking with AI and only InstallSnapshot can have impact since InstallSnapshot can use Netty, raised RATIS-2851 for InstallSnapshot. Currently RaftServerAsynchronousProtocol#readIndexAsync is only supported by the gRPC which does not need to call ID to correlate request and response. I raised RATIS-2852 to support the RaftServerAsynchronousProtocol for Netty (at least the readIndexAsync for now).

@szetszwo szetszwo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 the change looks good.

@szetszwo
szetszwo merged commit caa9a71 into apache:master Dec 4, 2026
17 checks passed
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

Successfully merging this pull request may close these issues.

2 participants