nicktelford commented on code in PR #18771: URL: https://github.com/apache/kafka/pull/18771#discussion_r1938340249
########## 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: As far as I understand, "weakly consistent" means that two different threads, constructing two different iterators over the structure would see a view of the structure that is consistent with _each other_ even in the face of additions or removals. I'm not certain of the behaviour of an Iterator between `hasNext` and `next` calls. I'm on my phone right now so can't check, but it's possible that `hasNext` actually takes a reference to the next object that `next` then returns. This is how `KeyValueIterator` works IIRC. I think the only way to be sure would be to check in the JDK implementation and hope they don't change it in the future. -- 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