bbejeck commented on code in PR #24216:
URL: https://github.com/apache/kafka/pull/24216#discussion_r4566581901
##########
group-coordinator/src/test/java/org/apache/kafka/coordinator/group/GroupMetadataManagerTest.java:
##########
@@ -24667,6 +24667,310 @@ public void
testStreamsGroupEndpointInformationOnlyWhenEpochGreater() {
assertNull(result.response().data().partitionsByUserEndpoint());
}
+ @Test
+ public void
testStreamsGroupHeartbeatWithUserEndpointAndMissingSourceTopics() {
+ String groupId = "fooup";
+ String memberId = Uuid.randomUuid().toString();
+ String subtopology1 = "subtopology1";
+ String fooTopicName = "foo";
+ Topology topology = new Topology().setSubtopologies(List.of(
+ new
Subtopology().setSubtopologyId(subtopology1).setSourceTopics(List.of(fooTopicName))
+ ));
+
+ // The source topic does not exist, so the configured topology has no
subtopologies.
+ MockTaskAssignor assignor = new MockTaskAssignor("sticky");
+ GroupMetadataManagerTestContext context = new
GroupMetadataManagerTestContext.Builder()
+ .withStreamsGroupTaskAssignors(List.of(assignor))
+ .withMetadataImage(new
MetadataImageBuilder().buildCoordinatorMetadataImage())
+
.withConfig(GroupCoordinatorConfig.STREAMS_GROUP_INITIAL_REBALANCE_DELAY_MS_CONFIG,
0)
+ .build();
+
+ // A client that has not yet received endpoint information sends -1 as
the endpoint information epoch.
+ CoordinatorResult<StreamsGroupHeartbeatResult, CoordinatorRecord>
result = context.streamsGroupHeartbeat(
+ new StreamsGroupHeartbeatRequestData()
+ .setGroupId(groupId)
+ .setMemberId(memberId)
+ .setMemberEpoch(0)
+ .setRebalanceTimeoutMs(1500)
+ .setTopology(topology)
+ .setActiveTasks(List.of())
+ .setStandbyTasks(List.of())
+ .setWarmupTasks(List.of())
+ .setUserEndpoint(new
StreamsGroupHeartbeatRequestData.Endpoint().setHost("localhost").setPort(9092))
+ .setEndpointInformationEpoch(-1));
+
+ assertResponseEquals(
+ new StreamsGroupHeartbeatResponseData()
+ .setMemberId(memberId)
+ .setMemberEpoch(2)
+ .setHeartbeatIntervalMs(5000)
+ .setActiveTasks(List.of())
+ .setStandbyTasks(List.of())
+ .setWarmupTasks(List.of())
+ .setPartitionsByUserEndpoint(List.of())
+ .setStatus(List.of(new
StreamsGroupHeartbeatResponseData.Status()
+ .setStatusCode(Status.MISSING_SOURCE_TOPICS.code())
+ .setStatusDetail("Source topics foo are missing.")))
+ .setTaskOffsetIntervalMs(60_000)
+ .setAcceptableRecoveryLag(10_000),
+ result.response().data()
+ );
+
+ // The client now knows the group's endpoint information epoch, so no
mapping is sent again.
+ result = context.streamsGroupHeartbeat(
+ new StreamsGroupHeartbeatRequestData()
+ .setGroupId(groupId)
+ .setMemberId(memberId)
+ .setMemberEpoch(result.response().data().memberEpoch())
+
.setEndpointInformationEpoch(result.response().data().endpointInformationEpoch()));
+
+ assertNull(result.response().data().partitionsByUserEndpoint());
+ }
+
+ @Test
+ public void
testStreamsGroupHeartbeatWithUserEndpointWhenSourceTopicIsDeleted() {
+ String groupId = "fooup";
+ String memberId = Uuid.randomUuid().toString();
+ String subtopology1 = "subtopology1";
+ String fooTopicName = "foo";
+ Uuid fooTopicId = Uuid.randomUuid();
+ Topology topology = new Topology().setSubtopologies(List.of(
+ new
Subtopology().setSubtopologyId(subtopology1).setSourceTopics(List.of(fooTopicName))
+ ));
+ StreamsGroupHeartbeatRequestData.Endpoint endpoint =
+ new
StreamsGroupHeartbeatRequestData.Endpoint().setHost("localhost").setPort(9092);
+
+ MetadataDelta delta = new MetadataDelta.Builder()
+ .setImage(MetadataImage.EMPTY)
+ .build();
+ delta.replay(new
TopicRecord().setTopicId(fooTopicId).setName(fooTopicName));
+ delta.replay(new
PartitionRecord().setTopicId(fooTopicId).setPartitionId(0));
+ delta.replay(new
PartitionRecord().setTopicId(fooTopicId).setPartitionId(1));
+ MetadataImage image = delta.apply(MetadataProvenance.EMPTY);
+
+ MockTaskAssignor assignor = new MockTaskAssignor("sticky");
+ GroupMetadataManagerTestContext context = new
GroupMetadataManagerTestContext.Builder()
+ .withStreamsGroupTaskAssignors(List.of(assignor))
+ .withMetadataImage(new KRaftCoordinatorMetadataImage(image))
+
.withConfig(GroupCoordinatorConfig.STREAMS_GROUP_INITIAL_REBALANCE_DELAY_MS_CONFIG,
0)
+
.withConfig(GroupCoordinatorConfig.STREAMS_GROUP_ASSIGNMENT_INTERVAL_MS_CONFIG,
0)
+ .build();
+
+ assignor.prepareGroupAssignment(
+ Map.of(memberId,
TaskAssignmentTestUtil.mkTasksTuple(TaskRole.ACTIVE,
TaskAssignmentTestUtil.mkTasks(subtopology1, 0, 1))));
+
+ CoordinatorResult<StreamsGroupHeartbeatResult, CoordinatorRecord>
result = context.streamsGroupHeartbeat(
+ new StreamsGroupHeartbeatRequestData()
+ .setGroupId(groupId)
+ .setMemberId(memberId)
+ .setMemberEpoch(0)
+ .setRebalanceTimeoutMs(1500)
+ .setTopology(topology)
+ .setActiveTasks(List.of())
+ .setStandbyTasks(List.of())
+ .setWarmupTasks(List.of())
+ .setUserEndpoint(endpoint)
+ .setEndpointInformationEpoch(-1));
+ assertEquals(
+ List.of(new
StreamsGroupHeartbeatResponseData.EndpointToPartitions()
+ .setUserEndpoint(new
StreamsGroupHeartbeatResponseData.Endpoint().setHost("localhost").setPort(9092))
+ .setActivePartitions(List.of(new
StreamsGroupHeartbeatResponseData.TopicPartition().setTopic("foo").setPartitions(List.of(0,
1))))
+ .setStandbyPartitions(List.of())),
+ result.response().data().partitionsByUserEndpoint()
+ );
+
+ // Delete the source topic while the member still owns its tasks.
+ delta = new MetadataDelta.Builder()
+ .setImage(image)
+ .build();
+ delta.replay(new RemoveTopicRecord().setTopicId(fooTopicId));
+ image = delta.apply(MetadataProvenance.EMPTY);
+ context.groupMetadataManager.onMetadataUpdate(new
KRaftCoordinatorMetadataDelta(delta), new KRaftCoordinatorMetadataImage(image));
+
+ result = context.streamsGroupHeartbeat(
+ new StreamsGroupHeartbeatRequestData()
+ .setGroupId(groupId)
+ .setMemberId(memberId)
+ .setMemberEpoch(result.response().data().memberEpoch())
+ .setUserEndpoint(endpoint)
+
.setEndpointInformationEpoch(result.response().data().endpointInformationEpoch()));
+
+ // The tasks are revoked, and clients are told that there is nothing
to route to.
+ assertEquals(List.of(), result.response().data().activeTasks());
+ assertEquals(1, result.response().data().endpointInformationEpoch());
Review Comment:
Finding from claude - the ready→not-ready bump is untested. The
source-topic-deleted test asserts epoch == 1, but that bump comes from the
existing "tasks changed and member has an endpoint" bump, not the new
one. The new bump never fires there because the first heartbeat runs on
a temporary group object. So the saved group has no configured topology yet and
wasReady is empty.
##########
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/streams/StreamsGroup.java:
##########
@@ -1578,6 +1579,11 @@ public
List<StreamsGroupHeartbeatResponseData.EndpointToPartitions> buildEndpoin
"This is a bug, please file a JIRA ticket.", groupId);
return endpointToPartitionsList;
}
+ // While the topology is not ready, for example because source or
internal topics are missing, the target assignment
Review Comment:
not sure this comment is necessary, it more or less says the same thing as
the method level comment, up to you.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]