Drifter-yh opened a new pull request, #11594: URL: https://github.com/apache/rocketmq/pull/11594
### Which Issue(s) This PR Fixes Fixes #11379 ### Brief Description `MessageStoreDispatcherImpl#doScheduleDispatch` preflights the first offset of a batch with null guards, but the group-commit append loop re-fetches the consume queue unit and the commitlog message for every subsequent offset without those guards. Once the consume queue is truncated, or the commitlog data has expired, `cqUnit.getSize()` or `message.getByteBuffer()` throws an NPE mid-loop. Every `SelectMappedBufferResult` fetched before that point is then dropped without being released, holding mapped-file references and preventing expired commitlog files from being cleaned. This change: - Mirrors the preflight guards inside the loop and breaks the batch on a missing CQ unit or a missing message, so the partial batch still commits. - Keeps every fetched buffer owned by the `GroupCommitContext` until its upload has finished. A non-empty batch is committed even when no consume-queue entry was appended, instead of dropping the context and leaking its buffers. - Marks a context that has a successful commitlog append without a matching consume-queue entry as ending one offset past the missing entry, so a busy/failed commit cannot release the context (and unmap the retained bytes) while a later upload may still read them. An earlier PR for this issue (#11380) adds the same two guards, but releases the context directly when no consume-queue entry was appended. That release is unsafe: `FileSegment#append` already keeps the source `ByteBuffer` in its buffer list, so dropping the mapped-file reference can let an expired commitlog file be unmapped while a pending upload still reads it — the concern raised by @yx9o in #11380. This change releases the buffers only after the commit that reads them has completed. ### How Did You Test This Change? - On `develop` at `8764dd7b6a469eb7783401d749c60240e6814b70`, without the source change, `dispatchMidBatchConsumeQueueTruncationTest` fails with `NullPointerException: Cannot invoke "org.apache.rocketmq.store.queue.CqUnit.getSize()" because "cqUnit" is null`. - With the change: `mvn -B -ntp -pl tieredstore -am -Dtest=MessageStoreDispatcherImplTest -Dsurefire.failIfNoSpecifiedTests=false -DfailIfNoTests=false -Djacoco.skip=true test` on Windows 11, Microsoft OpenJDK 17.0.14 and Maven 3.9.2 — 9 tests passed, 0 failures/errors/skips; Checkstyle reported 0 violations. - The four new tests cover: CQ truncation mid-batch, commitlog expiry mid-batch, a failed first consume-queue append keeping its buffer alive until the commit completes, and the same failed batch surviving a busy commit (`commitAsync` returning `false`) until a later consume-queue commit moves the commit offset past the missing entry. - `-Djacoco.skip=true` is used because the repository's JaCoCo 0.8.5 agent cannot instrument Java 17 Mockito-generated classes on this machine (`Unsupported class file major version 61`); the same instrumentation failure reproduces on unmodified `develop` and is unrelated to this change. - `git diff --check` passed. No broker integration test or full-project test is claimed. AI assistance: DeepSeek was used for analysis, implementation, and tests; the changes were reviewed and tested as described above. -- 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]
