mjsax commented on code in PR #18771:
URL: https://github.com/apache/kafka/pull/18771#discussion_r1938344950
##########
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://stackoverflow.com/questions/28915215/iterator-type-in-java-weakly-consistent
Somewhat old, and refers to Java 8 only.
Not sure how to read this one:
> What this doesn't say (and what may be implicit in the use of the word
"consistent") is that iteration won't result in an error such as
IndexOutOfBoundsException or NoSuchElementException [..] The third bullet in
particular explicitly doesn't make any guarantees about what elements are seen
by the iteration if modifications occur during iteration.
Also:
> Weakly consistent iteration provides guarantees against repeated elements
and against a variety of errors or infinite loops that can occur. The
"weakness" is that they provide few guarantees about exactly which elements are
observed during iteration.
The last sentence seem to indicate that it's safe to use `hasNext/next` --
it's just not guaranteed which elements from the collection are returned. What
aligns to the last sentence of the first paragraph (even if the first one is
less conclusive about `hasNext/next` safety IMHO).
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]