[Enhancement] Optimize RocksDB ConsumeQueue iterator for sequential reads
Before Creating the Enhancement Request
- [x] I have confirmed that this should be classified as an enhancement rather than a bug/feature.
Summary
Currently, when RocketMQ uses RocksDB-based ConsumeQueue, the default read path is controlled by iteratorWhenUseRocksdbConsumeQueue, which is enabled by default.
However, this iterator is a RocketMQ-level reusable iterator. Internally, it still calls RocksDBConsumeQueueTable#rangeQuery, which builds N RocksDB keys for consecutive ConsumeQueue offsets and then calls multiGet.
This enhancement proposes optimizing the RocksDB ConsumeQueue sequential read path by using a bounded RocksIterator scan for consecutive offsets, while preserving the existing external ConsumeQueue iterator semantics.
Motivation
Using RocksDB's native iterator scan for continuous offsets to improve performance.
Describe the Solution You'd Like
Use a bounded RocksIterator scan in RocksDBConsumeQueueTable#rangeQuery to read continuous offsets while keeping existing ConsumeQueue iterator semantics unchanged.
Describe Alternatives You've Considered
No
Additional Context
No response
Issue Evaluation
Category: type/enhancement | Status: Evaluated
Feasibility: Feasible
Scope: store module — RocksDB ConsumeQueue iterator
Compatibility: Internal optimization — no API changes.
Sequential read optimization for RocksDB iterators is a well-understood pattern. Using ReadOptions.setPrefixSameAsStart(true) or adjusting block_cache hints for sequential access can significantly reduce read amplification in consume queue scans.
Consideration: Benchmark with realistic consume patterns (mixed sequential/random) to ensure the optimization does not regress non-sequential access paths.
Automated evaluation by RockteMQ-AI