avalsa commented on a change in pull request #8221: URL: https://github.com/apache/kafka/pull/8221#discussion_r426498877
########## 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: fixed ---------------------------------------------------------------- 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: us...@infra.apache.org