zjncs opened a new pull request, #11101:
URL: https://github.com/apache/rocketmq/pull/11101

   ### 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:
   
   ```java
   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
   ```


-- 
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]

Reply via email to