chennaji9 opened a new pull request, #11295: URL: https://github.com/apache/rocketmq/pull/11295
<!-- Please make sure the target branch is right. In most case, the target branch should be `develop`. --> ### Which Issue(s) This PR Fixes Fixes #11281 ### Brief Description Fixes two defects in the lite-pull random-commit example `example/src/main/java/org/apache/rocketmq/example/simple/RandomAsyncCommit.java`: 1. `commitableOffset` called `firstKey()` on the cached `TreeMap` without an emptiness check, so once every cached message had been removed (or an empty batch was cached) it threw `NoSuchElementException` instead of returning the existing `-1` sentinel. It now returns `-1` when the cache exists but is empty. 2. `putMessages` initialized the per-queue cache with get-then-put, so two threads touching the same queue for the first time could overwrite each other's `CachedQueue` and lose a cached batch; the inner `TreeMap` was also read/written without synchronization. Initialization now uses `computeIfAbsent` and the three public methods are `synchronized`. `CachedQueue.java` is untouched; storage type and public API are unchanged. ### How Did You Test This Change? - `mvn -B -pl example -am -DskipTests -Dmaven.javadoc.skip=true compile` → BUILD SUCCESS (exit 0). - Smoke test without a broker (compiled against `example`/`common` classes): after `putMessages(mq, emptyList)` → `commitableOffset = -1` (was `NoSuchElementException`); after caching one message at offset 7 → returns 7; after `removeMessage` → returns -1; unknown queue → -1. - Diff is confined to the one class (9 insertions / 9 deletions). 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- 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]
