Skip to content

KAFKA-18613: Add StreamsGroupHeartbeat handler in the group coordinator #19114

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

Merged
merged 13 commits into from
Mar 31, 2025

Conversation

lucasbru
Copy link
Member

@lucasbru lucasbru commented Mar 5, 2025

Basic streams group heartbeat handling. The main part of are the unit tests that make sure that we behave, for the most part, like a consumer group.

  • No support for static membership
  • No support for configurations (using constants instead)
  • No support for regular expressions

Reviewers: Bill Bejeck [email protected], Bruno Cadonna [email protected]

@lucasbru lucasbru requested a review from cadonna March 5, 2025 14:20
@lucasbru lucasbru added KIP-1071 PRs related to KIP-1071 streams labels Mar 6, 2025
lucasbru added 2 commits March 6, 2025 17:59
Basic streams group heartbeat handling.

- No support for static membership
- No support for configurations (using constants instead)
- No support for regular expressions
@lucasbru lucasbru force-pushed the kip1071merge/heartbeat_1 branch from b442946 to fccd6e1 Compare March 6, 2025 16:59
Copy link
Member

@cadonna cadonna left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, @lucasbru !

I did a first pass over the production code. I haven't looked at GroupMetadataTest, yet.

@cadonna cadonna added the core Kafka Broker label Mar 7, 2025
@lucasbru
Copy link
Member Author

@cadonna Thanks for the comments! Ready for re-review

Copy link
Member

@cadonna cadonna left a comment

Choose a reason for hiding this comment

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

Thanks for the updates @lucasbru !

I reviewed half of the tests in GroupMetadataTest.

Copy link
Member Author

@lucasbru lucasbru left a comment

Choose a reason for hiding this comment

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

@cadonna Thanks for the comments! Ready for re-review.

Copy link
Member

@bbejeck bbejeck left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @lucasbru, I a few comments, but otherwise this lgtm

@lucasbru
Copy link
Member Author

@bbejeck Thanks for the comments! Ready for re-review.

@lucasbru
Copy link
Member Author

@cadonna @bbejeck this PR has been pending for 3 weeks. Anything I can do to push it over the line?

@lucasbru lucasbru requested a review from mjsax March 24, 2025 19:37
Copy link
Member

@cadonna cadonna left a comment

Choose a reason for hiding this comment

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

Thanks for the updates, @lucasbru !

I reviewed also the second part of the tests.

Once you resolved to my comments, the PR is ready for merge.

.withTargetAssignment(memberId, TaskAssignmentTestUtil.mkTasksTuple(TaskRole.ACTIVE,
TaskAssignmentTestUtil.mkTasks(subtopology1, 0, 1, 2, 3, 4, 5)))
.withTargetAssignmentEpoch(10)
.withTopology(StreamsTopology.fromHeartbeatRequest(topology))
Copy link
Member

Choose a reason for hiding this comment

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

This test would be easier to understand if you added the following here:

.withPartitionMetadata(Map.of(
                    fooTopicName, new org.apache.kafka.coordinator.group.streams.TopicMetadata(fooTopicId, fooTopicName, 3),
                    barTopicName, new org.apache.kafka.coordinator.group.streams.TopicMetadata(barTopicId, barTopicName, 3)
                ))

or even add a variable changedPartitionCount = 3 and then:

.withPartitionMetadata(Map.of(
                    fooTopicName, new org.apache.kafka.coordinator.group.streams.TopicMetadata(fooTopicId, fooTopicName, changedPartitionCount),
                    barTopicName, new org.apache.kafka.coordinator.group.streams.TopicMetadata(barTopicId, barTopicName, 3)
                ))

It took me quite some time to understand in the partition metadata was from no metadata to some metadata.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done. It makes sense, but I changed the number of partitions in MetadataImage instead, as that is where a change would come from. I also changed the number of partitions of bar instead of foo.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, sure. My bad! I meant it as you did.

}

@Test
public void testStreamsLeavingMemberBumpsGroupEpoch() {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe a better name would be testStreamsLeavingMemberRemovesMemberAndBumpsGroupEpoch

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

TaskAssignmentTestUtil.mkTasks(subtopology1, 3, 4, 5),
TaskAssignmentTestUtil.mkTasks(subtopology2, 2)))
.withTargetAssignmentEpoch(10))
.build();
Copy link
Member

Choose a reason for hiding this comment

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

IMO, you should also add the partition metadata to the group. The test relies on the order of checking first the member changes and then partition metadata changes. In the case the production code changes that order this test would fail in this specific location although it should not. That is better than the other way around, i.e., the test does not fail although it should. Nevertheless, making the test more robust to production code changes saves some debugging pain.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done


// Member 1 joins the streams group. The request fails because the
// target assignment computation failed.
assertThrows(UnknownServerException.class, () ->
Copy link
Member

Choose a reason for hiding this comment

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

Could you please also verify the exception message?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

context.rollback();

// However, the next heartbeat should detect the divergence based on the epoch and trigger
// a metadata refr
Copy link
Member

Choose a reason for hiding this comment

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

nit:

Suggested change
// a metadata refr
// a metadata refresh.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

);

// Advance time past the revocation timeout.
List<ExpiredTimeout<Void, CoordinatorRecord>> timeouts = context.sleep(10000 + 1);
Copy link
Member

Choose a reason for hiding this comment

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

Could you please use a variable revocationTimeout instead of 10000?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

Copy link
Member

@bbejeck bbejeck left a comment

Choose a reason for hiding this comment

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

Thanks for the update @lucasbru LGTM modulo addressing Bruno's oustanding comments.

Copy link
Member Author

@lucasbru lucasbru left a comment

Choose a reason for hiding this comment

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

@cadonna I addressed your comments

);

// Advance time past the revocation timeout.
List<ExpiredTimeout<Void, CoordinatorRecord>> timeouts = context.sleep(10000 + 1);
Copy link
Member Author

Choose a reason for hiding this comment

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

Done

context.rollback();

// However, the next heartbeat should detect the divergence based on the epoch and trigger
// a metadata refr
Copy link
Member Author

Choose a reason for hiding this comment

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

Done


// Member 1 joins the streams group. The request fails because the
// target assignment computation failed.
assertThrows(UnknownServerException.class, () ->
Copy link
Member Author

Choose a reason for hiding this comment

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

Done

TaskAssignmentTestUtil.mkTasks(subtopology1, 3, 4, 5),
TaskAssignmentTestUtil.mkTasks(subtopology2, 2)))
.withTargetAssignmentEpoch(10))
.build();
Copy link
Member Author

Choose a reason for hiding this comment

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

Done

}

@Test
public void testStreamsLeavingMemberBumpsGroupEpoch() {
Copy link
Member Author

Choose a reason for hiding this comment

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

Done

.withTargetAssignment(memberId, TaskAssignmentTestUtil.mkTasksTuple(TaskRole.ACTIVE,
TaskAssignmentTestUtil.mkTasks(subtopology1, 0, 1, 2, 3, 4, 5)))
.withTargetAssignmentEpoch(10)
.withTopology(StreamsTopology.fromHeartbeatRequest(topology))
Copy link
Member Author

Choose a reason for hiding this comment

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

Done. It makes sense, but I changed the number of partitions in MetadataImage instead, as that is where a change would come from. I also changed the number of partitions of bar instead of foo.

Copy link
Member

@cadonna cadonna left a comment

Choose a reason for hiding this comment

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

Thanks @lucasbru for the updates!

LGTM!

@lucasbru lucasbru merged commit 6d72677 into apache:trunk Mar 31, 2025
24 checks passed
janchilling pushed a commit to janchilling/kafka that referenced this pull request Apr 4, 2025
…or (apache#19114)

Basic streams group heartbeat handling. The main part of are the unit
tests that make sure that we behave, for the most part, like a consumer
group.

- No support for static membership
- No support for configurations (using constants instead)
- No support for regular expressions

Reviewers: Bill Bejeck <[email protected]>, Bruno Cadonna
<[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Kafka Broker KIP-1071 PRs related to KIP-1071 streams
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants