Skip to content

KAFKA-18185: remove internal.leave.group.on.close config #19400

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

Open
wants to merge 66 commits into
base: trunk
Choose a base branch
from

Conversation

frankvicky
Copy link
Contributor

@frankvicky frankvicky commented Apr 7, 2025

JIRA: KAFKA-18185

This is a follow-up of #17614 The patch is to remove the
internal.leave.group.on.close config.

@github-actions github-actions bot added triage PRs from the community streams core Kafka Broker consumer connect clients small Small PRs labels Apr 7, 2025
@frankvicky frankvicky marked this pull request as draft April 7, 2025 09:53
@frankvicky frankvicky marked this pull request as ready for review April 8, 2025 07:45
@github-actions github-actions bot removed the small Small PRs label Apr 8, 2025
@frankvicky frankvicky changed the title KAFKA-16758: remove internal.leave.group.on.close config KAFKA-18185: remove internal.leave.group.on.close config Apr 8, 2025
@frankvicky frankvicky marked this pull request as draft April 8, 2025 15:49
@frankvicky frankvicky marked this pull request as ready for review April 9, 2025 04:21
@frankvicky frankvicky changed the title KAFKA-18185: remove internal.leave.group.on.close config [WIP] KAFKA-18185: remove internal.leave.group.on.close config Apr 9, 2025
@github-actions github-actions bot added the tools label Apr 9, 2025
Comment on lines -1457 to -1459
if (leaveGroup) {
processStreamThread(streamThreadLeaveConsumerGroup(timeoutMs));
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As previous discussion, we should only close the consumer in StreamThread#completeShutdown

}
}

private void completeShutdown(final boolean cleanRun, final boolean leaveGroup) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could leverage the leaveGroupRequested and don't need a new argument.

@@ -1823,14 +1826,7 @@ private void completeShutdown(final boolean cleanRun, final boolean leaveGroup)
log.error("Failed to close changelog reader due to the following error:", e);
}
try {
if (leaveGroupRequested.get()) {
mainConsumer.unsubscribe();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Consumer# unsubscribe() will make consumers leave the group.
I believe this is a workaround, and now we could rely onthe new close API

Copy link
Member

Choose a reason for hiding this comment

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

mm yeah that's correct

Copy link
Member

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

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

@frankvicky thanks for this patch. a couple of comments are left.

final Optional<String> groupInstanceID = streamThread.groupInstanceID();
streamThread.requestLeaveGroupDuringShutdown();
streamThread.shutdown();
streamThread.shutdown(true);
if (!streamThread.getName().equals(Thread.currentThread().getName())) {
Copy link
Member

Choose a reason for hiding this comment

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

As you are updating this file, please replace !streamThread.getName().equals(Thread.currentThread().getName()) with callingThreadIsNotCurrentStreamThread.

} catch (final Throwable e) {
log.error("Failed to close consumer due to the following error:", e);
}
try {
restoreConsumer.close();
restoreConsumer.close(CloseOptions.groupMembershipOperation(REMAIN_IN_GROUP));
Copy link
Member

Choose a reason for hiding this comment

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

The restore consumer does not use a consumer group, so it should be fine to call restoreConsumer.close();, right?

log.info("Informed to shut down");
final State oldState = setState(State.PENDING_SHUTDOWN);
if (leaveGroup) {
requestLeaveGroupDuringShutdown();
Copy link
Member

Choose a reason for hiding this comment

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

requestLeaveGroupDuringShutdown is not used by other classes now, so we can remove requestLeaveGroupDuringShutdown by calling leaveGroupRequested.set(true);

@@ -490,7 +487,7 @@ private void replaceStreamThread(final Throwable throwable) {
closeToError();
}
final StreamThread deadThread = (StreamThread) Thread.currentThread();
deadThread.shutdown();
deadThread.shutdown(true);
Copy link
Member

Choose a reason for hiding this comment

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

It seems the origin behavior does not want to leave group, right? otherwise, it will trigger the extra rebalance.

+ " for the following reason: ",
exception.getCause()
);
}
Copy link
Member

Choose a reason for hiding this comment

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

It seems the behavior of KafkaStreams#removeStreamThread has changed. Without an explicit removal, the consumer is kicked off from the group after stream thread completes its run function. This means users CANNOT assume KafkaStreams#removeStreamThread will remove the member from the group.

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

Successfully merging this pull request may close these issues.

3 participants