Source:
<code>public Collection<TopicPartition> restore(final RestoringTasks active) { if (!needsInitializing.isEmpty()) { initialize(active); } <START> if (needsRestoring.isEmpty()) { <END> log.info("Finished restoring all active tasks"); restoreConsumer.unsubscribe(); return completedRestorers; } try { final ConsumerRecords<byte[], byte[]> records = restoreConsumer.poll(pollTime); for (final TopicPartition partition : needsRestoring) { final StateRestorer restorer = stateRestorers.get(partition); final long pos = processNext(records.records(partition), restorer, restoreToOffsets.get(partition)); restorer.setRestoredOffset(pos); if (restorer.hasCompleted(pos, restoreToOffsets.get(partition))) { restorer.restoreDone(); restoreToOffsets.remove(partition); completedRestorers.add(partition); } } } catch (final InvalidOffsetException recoverableException) { log.warn("Restoring StreamTasks failed. Deleting StreamTasks stores to recreate from scratch.", recoverableException); final Set<TopicPartition> partitions = recoverableException.partitions(); for (final TopicPartition partition : partitions) { final StreamTask task = active.restoringTaskFor(partition); log.info("Reinitializing StreamTask for changelog {}", task, partition); needsInitializing.remove(partition); needsRestoring.remove(partition); final StateRestorer restorer = stateRestorers.get(partition); restorer.setCheckpointOffset(StateRestorer.NO_CHECKPOINT); task.reinitializeStateStoresForPartitions(recoverableException.partitions()); } restoreConsumer.seekToBeginning(partitions); } needsRestoring.removeAll(completedRestorers); if (needsRestoring.isEmpty()) { log.info("Finished restoring all active tasks"); restoreConsumer.unsubscribe(); } return completedRestorers; }</code><technical_language>nit: module this if check L120</technical_language>

Target:
public Collection<TopicPartition> restore(final RestoringTasks active) { if (!needsInitializing.isEmpty()) { initialize(active); } if (checkForCompletedRestoration()) { return completedRestorers; } try { final ConsumerRecords<byte[], byte[]> records = restoreConsumer.poll(pollTime); for (final TopicPartition partition : needsRestoring) { final StateRestorer restorer = stateRestorers.get(partition); final long pos = processNext(records.records(partition), restorer, restoreToOffsets.get(partition)); restorer.setRestoredOffset(pos); if (restorer.hasCompleted(pos, restoreToOffsets.get(partition))) { restorer.restoreDone(); restoreToOffsets.remove(partition); completedRestorers.add(partition); } } } catch (final InvalidOffsetException recoverableException) { log.warn("Restoring StreamTasks failed. Deleting StreamTasks stores to recreate from scratch.", recoverableException); final Set<TopicPartition> partitions = recoverableException.partitions(); for (final TopicPartition partition : partitions) { final StreamTask task = active.restoringTaskFor(partition); log.info("Reinitializing StreamTask for changelog {}", task, partition); needsInitializing.remove(partition); needsRestoring.remove(partition); final StateRestorer restorer = stateRestorers.get(partition); restorer.setCheckpointOffset(StateRestorer.NO_CHECKPOINT); task.reinitializeStateStoresForPartitions(recoverableException.partitions()); } restoreConsumer.seekToBeginning(partitions); } needsRestoring.removeAll(completedRestorers); checkForCompletedRestoration(); return completedRestorers; }