[ISSUE #S3] Return an empty TPS when no samples have been collected yet - #11101
Open
zjncs wants to merge 1 commit into
Open
[ISSUE #S3] Return an empty TPS when no samples have been collected yet#11101zjncs wants to merge 1 commit into
zjncs wants to merge 1 commit into
Conversation
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>
RockteMQ-AI
approved these changes
Sep 9, 2026
RockteMQ-AI
left a comment
Contributor
There was a problem hiding this comment.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
The TPS snapshot lists (
putTimesList,getTimesFoundList,getTimesMissList,transferredMsgCountList) are only populated bysampling(), which runs from the service thread afterstart(). Yet every TPS getter used bytoString()andgetRuntimeInfo()callsLinkedList.getLast()unconditionally:Before the first sampling tick — a freshly started store, or a
StoreStatsServiceconstructed but not yet started —DefaultMessageStore.getRuntimeInfo()(i.e. the broker runtime info admin API) andtoString()therefore fail withNoSuchElementExceptioninstead of reporting empty TPS values.Modifications
getPutTps,getGetFoundTps,getGetMissTps,getGetTotalTps,getGetTransferredTps) return their empty value when the underlying list is still empty.Verification
Fail-before (new test on unpatched code):
Pass-after — full
StoreStatsServiceTest(3 existing + 1 new):