Description
We noticed this exception during testing:
java.util.NoSuchElementException 2 at org.apache.kafka.timeline.SnapshottableHashTable$HistoricalIterator.next(SnapshottableHashTable.java:276) 3 at org.apache.kafka.timeline.SnapshottableHashTable$HistoricalIterator.next(SnapshottableHashTable.java:189) 4 at org.apache.kafka.timeline.TimelineHashMap$EntryIterator.next(TimelineHashMap.java:360) 5 at org.apache.kafka.timeline.TimelineHashMap$EntryIterator.next(TimelineHashMap.java:346) 6 at org.apache.kafka.controller.FeatureControlManager$FeatureControlIterator.next(FeatureControlManager.java:375) 7 at org.apache.kafka.controller.FeatureControlManager$FeatureControlIterator.next(FeatureControlManager.java:347) 8 at org.apache.kafka.controller.SnapshotGenerator.generateBatch(SnapshotGenerator.java:109) 9 at org.apache.kafka.controller.SnapshotGenerator.generateBatches(SnapshotGenerator.java:126) 10 at org.apache.kafka.controller.QuorumController$SnapshotGeneratorManager.run(QuorumController.java:637) 11 at org.apache.kafka.controller.QuorumController$ControlEvent.run(QuorumController.java:539) 12 at org.apache.kafka.queue.KafkaEventQueue$EventContext.run(KafkaEventQueue.java:121) 13 at org.apache.kafka.queue.KafkaEventQueue$EventHandler.handleEvents(KafkaEventQueue.java:200) 14 at org.apache.kafka.queue.KafkaEventQueue$EventHandler.run(KafkaEventQueue.java:173) 15 at java.base/java.lang.Thread.run(Thread.java:833) 16 at org.apache.kafka.common.utils.KafkaThread.run(KafkaThread.java:64)
The iterator `FeatureControlIterator.hasNext()` checks two conditions: 1) whether we have already written the metadata version, and 2) whether the underlying iterator has additional records. However, in `next()`, we also check that the metadata version is at least high enough to include it in the log. When this fails, then we can see an unexpected `NoSuchElementException` if the underlying iterator is empty.
Attachments
Issue Links
- links to