You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by GitBox <gi...@apache.org> on 2020/05/18 06:05:35 UTC

[GitHub] [kafka] abbccdda commented on a change in pull request #8221: KAFKA-9561: update task input partitions after rebalance

abbccdda commented on a change in pull request #8221:
URL: https://github.com/apache/kafka/pull/8221#discussion_r426377894



##########
File path: streams/src/main/java/org/apache/kafka/streams/processor/internals/Task.java
##########
@@ -170,6 +170,8 @@ public boolean isValidTransition(final State newState) {
      */
     void closeDirty();
 
+    void update(final Set<TopicPartition> topicPartitions, final ProcessorTopology processorTopology);

Review comment:
       nit: could we add some comments for this function?

##########
File path: streams/src/main/java/org/apache/kafka/streams/processor/internals/PartitionGroup.java
##########
@@ -93,6 +96,28 @@ long partitionTimestamp(final TopicPartition partition) {
         return queue.partitionTime();
     }
 
+    // creates queues for new partitions, removes old queues, saves cached records for previously assigned partitions
+    void updatePartitions(final Set<TopicPartition> newInputPartitions, final Function<TopicPartition, RecordQueue> recordQueueCreator) {
+        final Set<TopicPartition> removedPartitions = new HashSet<>();
+        final Iterator<Map.Entry<TopicPartition, RecordQueue>> queuesIterator = partitionQueues.entrySet().iterator();
+        while (queuesIterator.hasNext()) {
+            final Map.Entry<TopicPartition, RecordQueue> queueEntry = queuesIterator.next();
+            final TopicPartition topicPartition = queueEntry.getKey();
+            if (!newInputPartitions.contains(topicPartition)) {
+                // if partition is removed should delete it's queue

Review comment:
       s/it's/its

##########
File path: streams/src/main/java/org/apache/kafka/streams/processor/internals/PartitionGroup.java
##########
@@ -93,6 +96,28 @@ long partitionTimestamp(final TopicPartition partition) {
         return queue.partitionTime();
     }
 
+    // creates queues for new partitions, removes old queues, saves cached records for previously assigned partitions
+    void updatePartitions(final Set<TopicPartition> newInputPartitions, final Function<TopicPartition, RecordQueue> recordQueueCreator) {
+        final Set<TopicPartition> removedPartitions = new HashSet<>();
+        final Iterator<Map.Entry<TopicPartition, RecordQueue>> queuesIterator = partitionQueues.entrySet().iterator();
+        while (queuesIterator.hasNext()) {
+            final Map.Entry<TopicPartition, RecordQueue> queueEntry = queuesIterator.next();
+            final TopicPartition topicPartition = queueEntry.getKey();
+            if (!newInputPartitions.contains(topicPartition)) {
+                // if partition is removed should delete it's queue
+                totalBuffered -= queueEntry.getValue().size();
+                queuesIterator.remove();
+                removedPartitions.add(topicPartition);
+            }
+            newInputPartitions.remove(topicPartition);
+        }
+        for (final TopicPartition newInputPartition : newInputPartitions) {
+            partitionQueues.put(newInputPartition, recordQueueCreator.apply(newInputPartition));
+        }
+        nonEmptyQueuesByTime.removeIf(q -> removedPartitions.contains(q.partition()));
+        allBuffered = allBuffered && newInputPartitions.isEmpty();

Review comment:
       nit: allBuffered &= newInputPartitions.isEmpty();




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org