lucasbru commented on code in PR #17795: URL: https://github.com/apache/kafka/pull/17795#discussion_r1853894662
########## clients/src/main/java/org/apache/kafka/clients/consumer/internals/StreamsAssignmentInterface.java: ########## @@ -281,17 +300,173 @@ public String toString() { } } + private final BlockingQueue<BackgroundEvent> onCallbackRequests = new LinkedBlockingQueue<>(); + + private ApplicationEventHandler applicationEventHandler = null; + + private Optional<Function<Set<StreamsAssignmentInterface.TaskId>, Optional<Exception>>> onTasksRevokedCallback = null; Review Comment: initialize to `Optional.empty()` ? Same for the two lines below. ########## clients/src/main/java/org/apache/kafka/clients/consumer/internals/StreamsGroupHeartbeatRequestManager.java: ########## @@ -126,7 +113,7 @@ public NetworkClientDelegate.PollResult poll(long currentTimeMs) { "messages. You can address this either by increasing max.poll.interval.ms or by " + "reducing the maximum size of batches returned in poll() with max.poll.records."); - membershipManager.transitionToSendingLeaveGroup(true); + membershipManager.onPollTimerExpired(); Review Comment: why these renamings? I think it could be beneficial to not rename things too much, unless we change the behavior ########## clients/src/main/java/org/apache/kafka/clients/consumer/internals/events/StreamsOnAllTasksLostCallbackNeededEvent.java: ########## @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.kafka.clients.consumer.internals.events; + +public class StreamsOnAllTasksLostCallbackNeededEvent extends CompletableBackgroundEvent<Void> { Review Comment: Why did you create separate events by type (lost/revoked/assinged)? It seems the consumer intentionally has a single event for all those, which should cut down on the number of LOC in this PR. See `ConsumerRebalanceListenerMethodName`. ########## clients/src/test/java/org/apache/kafka/clients/consumer/internals/StreamsGroupHeartbeatRequestManagerTest.java: ########## @@ -347,35 +340,35 @@ void testSuccessfulResponse() { mockResponse(data); - ArgumentCaptor<ConsumerGroupHeartbeatResponse> captor = ArgumentCaptor.forClass(ConsumerGroupHeartbeatResponse.class); + ArgumentCaptor<StreamsGroupHeartbeatResponse> captor = ArgumentCaptor.forClass(StreamsGroupHeartbeatResponse.class); verify(membershipManager, times(1)).onHeartbeatSuccess(captor.capture()); - ConsumerGroupHeartbeatResponseData response = captor.getValue().data(); + StreamsGroupHeartbeatResponseData response = captor.getValue().data(); assertEquals(Errors.NONE.code(), response.errorCode()); assertEquals(TEST_MEMBER_ID, response.memberId()); assertEquals(TEST_MEMBER_EPOCH, response.memberEpoch()); assertEquals(TEST_THROTTLE_TIME_MS, response.throttleTimeMs()); assertEquals(1000, response.heartbeatIntervalMs()); - final List<TopicPartitions> tps = response.assignment().topicPartitions(); - assertEquals(2, tps.size()); - assertEquals(Set.of(uuid0, uuid1), tps.stream().map(TopicPartitions::topicId).collect(Collectors.toSet())); - assertEquals(Collections.singletonList(0), tps.get(0).partitions()); - assertEquals(Collections.singletonList(0), tps.get(1).partitions()); - - final Assignment targetAssignment = streamsAssignmentInterface.targetAssignment.get(); - assertEquals(1, targetAssignment.activeTasks.size()); - final TaskId activeTaskId = targetAssignment.activeTasks.stream().findFirst().get(); - assertEquals(activeTaskId.subtopologyId(), "0"); - assertEquals(activeTaskId.partitionId(), 0); - - assertEquals(1, targetAssignment.standbyTasks.size()); - final TaskId standbyTaskId = targetAssignment.standbyTasks.stream().findFirst().get(); - assertEquals(standbyTaskId.subtopologyId(), "1"); - assertEquals(standbyTaskId.partitionId(), 1); - - assertEquals(1, targetAssignment.warmupTasks.size()); - final TaskId warmupTaskId = targetAssignment.warmupTasks.stream().findFirst().get(); - assertEquals(warmupTaskId.subtopologyId(), "2"); - assertEquals(warmupTaskId.partitionId(), 2); +// final List<TopicPartitions> tps = response.assign.topicPartitions(); Review Comment: Why is this stuff commented out? ########## streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamThread.java: ########## @@ -1397,23 +1403,59 @@ public void maybeHandleAssignmentFromStreamsRebalanceProtocol() { ); // Process assignment from Streams Rebalance Protocol - final Assignment newAssignment = streamsAssignmentInterface.targetAssignment.get(); - if (!newAssignment.equals(streamsAssignmentInterface.reconciledAssignment.get())) { - - final Map<TaskId, Set<TopicPartition>> activeTasksWithPartitions = - pairWithTopicPartitions(newAssignment.activeTasks.stream()); - final Map<TaskId, Set<TopicPartition>> standbyTasksWithPartitions = - pairWithTopicPartitions(Stream.concat(newAssignment.standbyTasks.stream(), newAssignment.warmupTasks.stream())); + streamsAssignmentInterface.processStreamsRebalanceEvents(); + } + } - log.info("Processing new assignment {} from Streams Rebalance Protocol", newAssignment); + private Optional<Exception> onTasksRevoked(final Set<StreamsAssignmentInterface.TaskId> activeTasksToRevoke) { Review Comment: Just thinking - could these live in a different class? It seems there is a ton going on in the = stream thead. also, this would simplify testing this. maybe a "StreamsRebalanceListener"? Then we could also unit test this, your PR doesn't seem to have a unit test for these methods. -- 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-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org