Drifter-yh opened a new pull request, #11650: URL: https://github.com/apache/rocketmq/pull/11650
### Which Issue(s) This PR Fixes - Fixes #11649 ### Brief Description `CommitLog#recoverAbnormally` picks the commit log file to replay via `isMappedFileMatchedRecover` across all `CommitLogDispatchStore`s, then, when accelerated recovery is enabled, positions the reader at `dispatchFromPhyOffset - mappedFile.getFileFromOffset()`. When `messageIndexSafe` is enabled, `IndexService#isMappedFileMatchedRecover` can force recovery to start from a file older than the file that contains `dispatchFromPhyOffset` (the consume queue checkpoint), because index files newer than the index checkpoint are deleted on abnormal load and the index has to be rebuilt by replaying commit log from the index checkpoint. In that case: - if the selected file is older than the dispatch offset, `ByteBuffer#position` throws `IllegalArgumentException: newPosition > limit` and `DefaultMessageStore#load` returns `false` (broker cannot start); - if both offsets are in the same file, recovery starts after the index rebuild point and the index is only partially rebuilt, so queries by key lose pre-restart messages (single commit log segment store). `IndexService#getDispatchFromPhyOffset` returns `-1`, so the index rebuild point is not part of the min dispatch offset calculated by `DefaultMessageStore#recover`. This change skips accelerated recovery when `messageIndexEnable && messageIndexSafe` is true, falling back to replaying the selected commit log file from its beginning. That is the only safe start position for that configuration (it is also what recovery did before accelerated recovery was enabled for the file-based consume queue in #10012), and it restores the documented `messageIndexSafe` behavior. ### How Did You Test This Change? Added two regression tests in `DefaultMessageStoreTest` (file-based store, `enableAcceleratedRecovery=true`, `messageIndexSafe=true`, abort file to force abnormal recovery): - `testAcceleratedRecoveryWithSafeIndexStartingInEarlierFile`: 4 KB commit log segments so the store spans three segments. Without the fix `store.load()` returns `false` with `newPosition > limit: (11099 > 4096)`; with the fix the store loads, `maxPhyOffset`/consume queue offsets are unchanged, the first message is readable, `queryMessage` finds both the first and the last key, and the next message is appended at the next queue offset. - `testAcceleratedRecoveryWithSafeIndexStartingInCurrentFile`: store fits in one commit log segment. Without the fix the store loads but `queryMessage(topic, "key-0", ...)` returns 0 messages; with the fix the index is rebuilt and the query returns 1 message. Both tests fail on develop and pass with the change. Verification: `mvn -pl store -am -Dtest=DefaultMessageStoreTest,ReputMessageServiceTest,StoreCheckpointTest test` -> 42 tests, 0 failures; checkstyle and spotbugs clean for the store module. -- 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]
