You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "ShivsundarR (via GitHub)" <gi...@apache.org> on 2025/02/10 17:38:50 UTC
[PR] KAFKA-18769: Improve leadership changes handling in ShareConsumeRequestManager. [kafka]
ShivsundarR opened a new pull request, #18851:
URL: https://github.com/apache/kafka/pull/18851
*What*
Currently when we fetch records from a node and then there is a leadership change before we acknowledge, we attempt to send the acknowledgements to the old leader.
This was just the case when the leadership changes before we acknowledge, if the leadership change happened after, we would get a `NOT_LEADER_OR_FOLLOWER` exception from the broker in the response.
In order to have a consistent behaviour, we will now fail the acknowledgements with `NOT_LEADER_OR_FOLLOWER` exception in the clients and avoid sending the request to the previous leader.
These records would now timeout and be re-acquired in the next fetch cycle.
--
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.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-18769: Improve leadership changes handling in ShareConsumeRequestManager. [kafka]
Posted by "ShivsundarR (via GitHub)" <gi...@apache.org>.
ShivsundarR commented on code in PR #18851:
URL: https://github.com/apache/kafka/pull/18851#discussion_r1952500382
##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/ShareConsumeRequestManager.java:
##########
@@ -630,6 +663,26 @@ public CompletableFuture<Void> acknowledgeOnClose(final Map<TopicIdPartition, No
return closeFuture;
}
+ /**
+ *
+ * @return True if nodeId is the leader or if leader information is not present for the topicIdPartition.
+ * Returns false if nodeId is not the leader for the given topicIdPartition
+ */
+ private boolean isNodeLeader(int nodeId, TopicIdPartition topicIdPartition) {
Review Comment:
Thanks, yeah that sounds good. I have updated the PR.
--
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.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-18769: Improve leadership changes handling in ShareConsumeRequestManager. [kafka]
Posted by "AndrewJSchofield (via GitHub)" <gi...@apache.org>.
AndrewJSchofield merged PR #18851:
URL: https://github.com/apache/kafka/pull/18851
--
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.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-18769: Improve leadership changes handling in ShareConsumeRequestManager. [kafka]
Posted by "AndrewJSchofield (via GitHub)" <gi...@apache.org>.
AndrewJSchofield commented on code in PR #18851:
URL: https://github.com/apache/kafka/pull/18851#discussion_r1952295803
##########
clients/src/test/java/org/apache/kafka/clients/consumer/internals/ShareConsumeRequestManagerTest.java:
##########
@@ -862,6 +867,81 @@ public void testCommitAsyncWithSubscriptionChange() {
}
+ @Test
+ public void testCommitSyncWithSubscriptionChange() {
+ buildRequestManager();
+
+ assignFromSubscribed(singleton(tp0));
+
+ assertEquals(1, sendFetches());
+ assertFalse(shareConsumeRequestManager.hasCompletedFetches());
+
+ client.prepareResponse(fullFetchResponse(tip0, records, acquiredRecords, Errors.NONE));
+ networkClientDelegate.poll(time.timer(0));
+ assertTrue(shareConsumeRequestManager.hasCompletedFetches());
+
+ Acknowledgements acknowledgements = Acknowledgements.empty();
+ acknowledgements.add(1L, AcknowledgeType.ACCEPT);
+ acknowledgements.add(2L, AcknowledgeType.ACCEPT);
+ acknowledgements.add(3L, AcknowledgeType.REJECT);
+
+ subscriptions.subscribeToShareGroup(Collections.singleton(topicName2));
+ subscriptions.assignFromSubscribed(Collections.singleton(t2p0));
+
+ client.updateMetadata(
+ RequestTestUtils.metadataUpdateWithIds(1, singletonMap(topicName2, 1),
+ tp -> validLeaderEpoch, topicIds, false));
+
+ shareConsumeRequestManager.commitSync(Collections.singletonMap(tip0, new NodeAcknowledgements(0, acknowledgements)),
+ calculateDeadlineMs(time.timer(100)));
+
+ assertEquals(1, shareConsumeRequestManager.sendAcknowledgements());
+
+ client.prepareResponse(fullAcknowledgeResponse(tip1, Errors.NONE));
Review Comment:
These new tests that use topic 2 are still referring to `tip1` which seems a mistake.
##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/ShareConsumeRequestManager.java:
##########
@@ -630,6 +663,26 @@ public CompletableFuture<Void> acknowledgeOnClose(final Map<TopicIdPartition, No
return closeFuture;
}
+ /**
+ *
+ * @return True if nodeId is the leader or if leader information is not present for the topicIdPartition.
+ * Returns false if nodeId is not the leader for the given topicIdPartition
+ */
+ private boolean isNodeLeader(int nodeId, TopicIdPartition topicIdPartition) {
Review Comment:
This is a bit confusing. How about `isLeaderKnownToHaveChanged`?
--
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.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-18769: Improve leadership changes handling in ShareConsumeRequestManager. [kafka]
Posted by "AndrewJSchofield (via GitHub)" <gi...@apache.org>.
AndrewJSchofield commented on code in PR #18851:
URL: https://github.com/apache/kafka/pull/18851#discussion_r1950358289
##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/ShareConsumeRequestManager.java:
##########
@@ -630,6 +665,21 @@ public CompletableFuture<Void> acknowledgeOnClose(final Map<TopicIdPartition, No
return closeFuture;
}
+ private boolean isNodeLeader(int nodeId, TopicIdPartition topicIdPartition) {
+ Optional<Node> leaderNode = metadata.currentLeader(topicIdPartition.topicPartition()).leader;
+ if (leaderNode.isPresent()) {
+ if (leaderNode.get().id() != nodeId) {
+ log.debug("Node {} is no longer the leader for topic ID partition {}, failing acknowledgements", nodeId, topicIdPartition);
Review Comment:
nit: In this file, the log lines just use `for partition {}` and never `for topic ID partition {}`.
##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/ShareConsumeRequestManager.java:
##########
@@ -630,6 +665,21 @@ public CompletableFuture<Void> acknowledgeOnClose(final Map<TopicIdPartition, No
return closeFuture;
}
+ private boolean isNodeLeader(int nodeId, TopicIdPartition topicIdPartition) {
+ Optional<Node> leaderNode = metadata.currentLeader(topicIdPartition.topicPartition()).leader;
+ if (leaderNode.isPresent()) {
+ if (leaderNode.get().id() != nodeId) {
+ log.debug("Node {} is no longer the leader for topic ID partition {}, failing acknowledgements", nodeId, topicIdPartition);
+ return false;
+ }
+ } else {
+ log.debug("No leader found for topic ID partition {}", topicIdPartition);
Review Comment:
And here too.
--
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.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org