Skip to content

[ISSUE #S3] Return an empty TPS when no samples have been collected yet - #11101

Open
zjncs wants to merge 1 commit into
apache:developfrom
zjncs:fix/store-stats-service-empty-lists
Open

[ISSUE #S3] Return an empty TPS when no samples have been collected yet#11101
zjncs wants to merge 1 commit into
apache:developfrom
zjncs:fix/store-stats-service-empty-lists

Conversation

@zjncs

@zjncs zjncs commented Sep 9, 2026

Copy link
Copy Markdown

Motivation

The TPS snapshot lists (putTimesList, getTimesFoundList, getTimesMissList, transferredMsgCountList) are only populated by sampling(), which runs from the service thread after start(). Yet every TPS getter used by toString() and getRuntimeInfo() calls LinkedList.getLast() unconditionally:

CallSnapshot last = this.putTimesList.getLast();   // NoSuchElementException on empty list

Before the first sampling tick — a freshly started store, or a StoreStatsService constructed but not yet started — DefaultMessageStore.getRuntimeInfo() (i.e. the broker runtime info admin API) and toString() therefore fail with NoSuchElementException instead of reporting empty TPS values.

Modifications

  • All five getters (getPutTps, getGetFoundTps, getGetMissTps, getGetTotalTps, getGetTransferredTps) return their empty value when the underlying list is still empty.

Verification

Fail-before (new test on unpatched code):

StoreStatsServiceTest.toStringAndRuntimeInfoBeforeFirstSampleShouldNotThrow:114 » NoSuchElement

Pass-after — full StoreStatsServiceTest (3 existing + 1 new):

mvn -pl store test -Dtest='StoreStatsServiceTest'
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0

The TPS snapshot lists are only filled by the sampling thread after
StoreStatsService.start(), but the getters used by toString() and
getRuntimeInfo() call LinkedList.getLast() unconditionally. Before the
first sample (fresh start, or a store constructed but not started in
tools/tests) every broker-runtime-info call therefore fails with
NoSuchElementException. Check isEmpty() first and return the empty
value.

Signed-off-by: zjncs <18910855655@163.com>
Copilot AI lite review requested due to automatic review settings September 9, 2026 10:35

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@RockteMQ-AI RockteMQ-AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Summary

Clean defensive fix — all five TPS getters now return empty when the sampling lists have not been populated yet, preventing NoSuchElementException from LinkedList.getLast() on empty lists which would crash getRuntimeInfo() and toString(). Consistent pattern across all getters, test validates.


Automated review by github-manager

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants