Skip to content

[ISSUE #11579] Persist RocksDB consumer offsets incrementally in asynchronous batches - #11580

Merged
lizhimins merged 3 commits into
apache:developfrom
f1amingo:enhancement/async-batch-consumer-offset-persist
Nov 27, 2026
Merged

lizhimins merged 3 commits into
apache:developfrom
f1amingo:enhancement/async-batch-consumer-offset-persist

Conversation

@f1amingo

Copy link
Copy Markdown
Contributor

Which Issue(s) This PR Fixes

Brief Description

  • Persist incremental consumer offsets of the V1 RocksDB manager through a deduplicated background batch writer instead of a synchronous write per commit.
  • Drain pending offsets and sync the WAL on persist() and stop(); deleting an offset cancels its pending write.
  • Add flushWALChecked() so the offset barrier can detect WAL flush failures.
  • Persist all config managers before closing the shared RocksDB on broker shutdown.

How Did You Test This Change?

  • Added RocksDBConsumerOffsetManagerLmqPersistTest (32 cases) and shared-RocksDB shutdown cases in BrokerShutdownTest; both pass together with RocksDBConfigManagerTest.
  • Component benchmark (1M LMQs, 10k commits/s): process CPU -41%, commit p99 17.28μs -> 2.14μs, RocksDB write calls -99.3%, all offsets persisted consistently.

@f1amingo
f1amingo force-pushed the enhancement/async-batch-consumer-offset-persist branch from 3909860 to c4c5b4e Compare November 23, 2026 08:22
@codecov-commenter

codecov-commenter commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.02326% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 51.02%. Comparing base (ea103d9) to head (c050b29).
⚠️ Report is 41 commits behind head on develop.

Files with missing lines Patch % Lines
.../java/org/apache/rocketmq/common/BrokerConfig.java 16.66% 5 Missing ⚠️
...broker/config/v1/RocksDBConsumerOffsetManager.java 98.01% 1 Missing and 2 partials ⚠️
...a/org/apache/rocketmq/broker/BrokerController.java 66.66% 0 Missing and 2 partials ⚠️
...ocketmq/broker/config/v1/RocksDBConfigManager.java 77.77% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             develop   #11580      +/-   ##
=============================================
+ Coverage      49.89%   51.02%   +1.12%     
- Complexity     14464    14966     +502     
=============================================
  Files           1391     1391              
  Lines         103438   103910     +472     
  Branches       13551    13633      +82     
=============================================
+ Hits           51610    53015    +1405     
+ Misses         45601    44690     -911     
+ Partials        6227     6205      -22     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…n asynchronous batches

- Batch incremental offset writes through a deduplicated background persister
- Drain pending offsets and sync WAL on persist and stop
- Add checked WAL flush to surface flush failures
- Persist all config managers before closing the shared RocksDB on shutdown
- Add tests for batching, deletion, stop and shared RocksDB shutdown
@f1amingo
f1amingo force-pushed the enhancement/async-batch-consumer-offset-persist branch from c4c5b4e to 9df3035 Compare November 23, 2026 09:08
- Advance versions in memory and persist them during offset persistence and shutdown.
- Preallocate the selected-key buffer and verify commits proceed during slow version writes.
@ShannonDing
ShannonDing requested review from RongtongJin and yx9o and removed request for RongtongJin November 23, 2026 12:07
@f1amingo
f1amingo force-pushed the enhancement/async-batch-consumer-offset-persist branch from 7b4d6a7 to 9e14011 Compare November 26, 2026 15:55
- Add a configurable 100ms fixed-delay interval and use 2500-key/512KiB batches.
- Skip dirty-key registration for unchanged offsets while preserving version updates.
- Retain all queue offsets during concurrent first commits with putIfAbsent.
- Log successful batch limits outside locks at most once per minute.
- Cover interval lifecycle, unchanged offsets, concurrent queue creation and batch limits.

Validation: 61 unit tests and Checkstyle pass; ordinary-topic component benchmark at 5k commits/s passes all nine runs.
@f1amingo
f1amingo force-pushed the enhancement/async-batch-consumer-offset-persist branch from 9e14011 to c050b29 Compare November 26, 2026 16:09

@lizhimins lizhimins left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The deduplicated async batch design is clean: clear writeLock -> pendingLock ordering, mark-before-read so concurrent updates requeue, atomic WriteBatch retry on failure, and delete/batch serialized by writeLock. The shared-RocksDB shutdown ordering fix is a real improvement, tests are thorough, and CI is green.

A few non-blocking follow-ups worth tracking separately:

  • stop() failure/timeout path: in shared-RocksDB mode the shared store can still be closed by topic/subscription stop() while the offset worker may still be alive; AbstractRocksDBStorage.batchPut has no hold() guard.
  • Persisted kvDataVersion now lags persisted offsets (version only written on persist/stop). Consider stamping the version into the same WriteBatch as V2 does.
  • The pending set is unbounded and each tick flushes a single batch; consider multi-batch draining and a pending-size metric.

Thanks for the contribution!

@lizhimins
lizhimins merged commit dfc07ec into apache:develop Nov 27, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Enhancement] Persist RocksDB consumer offsets incrementally in asynchronous batches

3 participants