mjsax commented on code in PR #18771: URL: https://github.com/apache/kafka/pull/18771#discussion_r1938345281
########## streams/src/main/java/org/apache/kafka/streams/state/internals/MeteredKeyValueStore.java: ########## @@ -156,11 +156,8 @@ private void registerMetrics() { (config, now) -> numOpenIterators.sum()); StateStoreMetrics.addOldestOpenIteratorGauge(taskId.toString(), metricsScope, name(), streamsMetrics, (config, now) -> { - try { - return openIterators.isEmpty() ? null : openIterators.first().startTimestamp(); - } catch (final NoSuchElementException ignored) { - return null; - } + final Iterator<MeteredIterator> openIteratorsIterator = openIterators.iterator(); + return openIteratorsIterator.hasNext() ? openIteratorsIterator.next().startTimestamp() : null; Review Comment: https://www.javaspecialists.eu/archive/Issue288-Weakly-Consistent-Iteration.html Refers to Java 16 (we are using 11 for Kafka Streams since AK 4.0). This one seems to be more conclusive: > Vector's Enumeration was neither fail-fast nor weakly-consistent. We could create an Enumeration, but even if hasMoreElements() was true, nextElement() could throw a NoSuchElementException. Also, with Vector if we removed an element before our current position, then we would skip over the next element. Similarly, adding an element before our current position would make us see duplicate elements. These effects do not happen with weakly-consistent iterators. `These effects do not happen with weakly-consistent iterators.` seems to refer to `NoSuchElementException` -- 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. To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org