Source:
public void restore() { initializeChangelogs(registeredChangelogs()); if (!activeRestoringChangelogs().isEmpty() && state == ChangelogReaderState.STANDBY_UPDATING) { throw new IllegalStateException("Should not be in standby updating state if there are still un-completed active changelogs"); } if (allChangelogsCompleted()) { log.debug("Finished restoring all changelogs {}", changelogs.keySet()); return; } final Set<TopicPartition> restoringChangelogs = restoringChangelogs(); if (!restoringChangelogs.isEmpty()) { final ConsumerRecords<byte[], byte[]> polledRecords; try { polledRecords = restoreConsumer.poll(pollTime); } catch (final FencedInstanceIdException e) { throw new TaskMigratedException("Restore consumer get fenced by instance-id polling records.", e); } catch (final InvalidOffsetException e) { log.warn("Encountered fetching records from restore consumer for partitions {}, " + "marking the corresponding tasks as corrupted.", e.getClass().getName(), e.partitions()); final Set<TaskId> taskIds = new HashSet<>(); for (final TopicPartition partition : e.partitions()) { taskIds.add(changelogs.get(partition).stateManager.taskId()); } throw new TaskCorruptedException(taskIds); } catch (final KafkaException e) { throw new StreamsException("Restore consumer get unexpected error polling records.", e); } for (final TopicPartition partition : polledRecords.partitions()) { bufferChangelogRecords(restoringChangelogByPartition(partition), polledRecords.records(partition)); } for (final TopicPartition partition: restoringChangelogs) { restoreChangelog(changelogs.get(partition)); } maybeUpdateLimitOffsetsForStandbyChangelogs(); } }

Target:
public void restore() { initializeChangelogs(registeredChangelogs()); if (!activeRestoringChangelogs().isEmpty() && state == ChangelogReaderState.STANDBY_UPDATING) { throw new IllegalStateException("Should not be in standby updating state if there are still un-completed active changelogs"); } if (allChangelogsCompleted()) { log.debug("Finished restoring all changelogs {}", changelogs.keySet()); return; } final Set<TopicPartition> restoringChangelogs = restoringChangelogs(); if (!restoringChangelogs.isEmpty()) { final ConsumerRecords<byte[], byte[]> polledRecords; try { polledRecords = restoreConsumer.poll(pollTime); } catch (final FencedInstanceIdException e) { throw new TaskMigratedException("Restore consumer get fenced by instance-id polling records.", e); } catch (final InvalidOffsetException e) { log.warn("Encountered fetching records from restore consumer for partitions {}, it is likely that " + "the consumer's position has fallen out of the topic partition offset range because the topic was " + "truncated or compacted on the broker, marking the corresponding tasks as corrupted and re-initializing" + "it later.", e.getClass().getName(), e.partitions()); final Map<TaskId, Set<TopicPartition>> taskWithCorruptedChangelogs = new HashMap<>(); for (final TopicPartition partition : e.partitions()) { final TaskId taskId = changelogs.get(partition).stateManager.taskId(); taskWithCorruptedChangelogs.computeIfAbsent(taskId, k -> new HashSet<>()).add(partition); } throw new TaskCorruptedException(taskWithCorruptedChangelogs); } catch (final KafkaException e) { throw new StreamsException("Restore consumer get unexpected error polling records.", e); } for (final TopicPartition partition : polledRecords.partitions()) { bufferChangelogRecords(restoringChangelogByPartition(partition), polledRecords.records(partition)); } for (final TopicPartition partition: restoringChangelogs) { restoreChangelog(changelogs.get(partition)); } maybeUpdateLimitOffsetsForStandbyChangelogs(); } }