Skip to content

MINOR: simplify OpenIterator#20060

Merged
mjsax merged 1 commit intoapache:trunkfrom
mjsax:minor-iterator-metric
Jul 1, 2025
Merged

MINOR: simplify OpenIterator#20060
mjsax merged 1 commit intoapache:trunkfrom
mjsax:minor-iterator-metric

Conversation

@mjsax
Copy link
Copy Markdown
Member

@mjsax mjsax commented Jun 27, 2025

We can remove the explicit counter for open iterators, and just use
size() on the set of open iterators we track anyway.

Reviewers: Chia-Ping Tsai chia7712@gmail.com

We can remove the explicit counter for open iterators, and just use size() on the set of open iterators we track anyway.
@mjsax mjsax added streams small Small PRs labels Jun 27, 2025
@mjsax
Copy link
Copy Markdown
Member Author

mjsax commented Jun 27, 2025

Follow up PR to #20022 (comment)

numOpenIterators.increment();

if (numOpenIterators.intValue() == 1) {
if (openIterators.size() == 1) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was worried for adding the same iterator, which could create unexpected metrics, but it seems StateStoreMetrics.addOldestOpenIteratorGauge already handle this case.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sue if I can follow. Can you elaborate?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the unclear comment. Please see the following example

        var openIterators = new OpenIterators();
        var iterator = new MeteredIterator(1000L);
        openIterators.add(iterator);
        openIterators.add(iterator);

The second openIterators.add(iterator) did not invoke StateStoreMetrics.addOldestOpenIteratorGauge before, but it does now. However, this should be fine, since StateStoreMetrics.addOldestOpenIteratorGauge does not create new metrics in this scenario.

Copy link
Copy Markdown
Member Author

@mjsax mjsax Jul 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, would be a bug anyway, to call openIterators.add(iterator); twice on the same iterator object. Each iterator should be registered exactly one time.

But yes, we would not add a new metric.

@mjsax mjsax merged commit eaa55c4 into apache:trunk Jul 1, 2025
29 checks passed
@mjsax mjsax deleted the minor-iterator-metric branch July 1, 2025 19:54
jiafu1115 pushed a commit to jiafu1115/kafka that referenced this pull request Jul 2, 2025
We can remove the explicit counter for open iterators, and just use
size() on the set of open iterators we track anyway.

Reviewers: Chia-Ping Tsai <chia7712@gmail.com>
jiafu1115 pushed a commit to jiafu1115/kafka that referenced this pull request Jul 3, 2025
We can remove the explicit counter for open iterators, and just use
size() on the set of open iterators we track anyway.

Reviewers: Chia-Ping Tsai <chia7712@gmail.com>
k-apol pushed a commit to k-apol/kafka that referenced this pull request Aug 8, 2025
We can remove the explicit counter for open iterators, and just use
size() on the set of open iterators we track anyway.

Reviewers: Chia-Ping Tsai <chia7712@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants