rocketmq icon indicating copy to clipboard operation
rocketmq copied to clipboard

[Enhancement] Tiered Storage: memory backpressure, concurrency hardening and bug fixes

Open lizhimins opened this issue 5 months ago • 2 comments

Before Creating the Enhancement Request

  • [x] I have confirmed that this should be classified as an enhancement rather than a bug/feature.

Summary

Systematic improvements to the tieredstore module covering memory backpressure, concurrency safety, resource leak fixes, thread pool optimization, error handling, and log standardization.

Motivation

The tieredstore module has several stability and data-safety risks:

  • No backpressure mechanism — unbounded memory growth when dispatch falls behind, risking OOM
  • PosixFileSegment FileChannel concurrent read/write race condition
  • IndexStoreFile hash overflow on Integer.MIN_VALUE causing out-of-bounds access
  • FileSegment close does not wait for in-flight commits, risking data loss
  • MessageStoreExecutor thread pool too large (256+ threads on 32-core machines)
  • Inconsistent log formatting makes troubleshooting difficult

Describe the Solution You'd Like

Memory backpressure: add ratio + cap backpressure (default 10% heap, capped at 1GB), check available memory before dispatch.

Concurrency fixes:

  • PosixFileSegment: use read(ByteBuffer, long) for atomic reads
  • IndexStoreFile: hash with & 0x7FFFFFFF to prevent MIN_VALUE overflow
  • FlatCommitLogFile: local variable snapshot for firstOffset to prevent TOCTOU
  • FlatMessageFile: add volatile to metadata fields

Resource management:

  • FileSegment close() waits for in-flight commit (30s timeout)
  • PosixFileSegment: store RAF references to prevent handle leaks
  • MessageStoreExecutor shutdown(): add awaitTermination(30s)
  • Remove MessageStoreExecutor singleton pattern and fileRecyclingExecutor
  • FlatFileFactory: remove test constructor that leaks thread pool

Thread pool optimization: core = processors, max = processors * 2, remove fileRecyclingExecutor.

Error handling:

  • TieredMessageStore: unwrap CompletionException, re-throw Error instead of swallowing
  • PosixFileSegment: throw RuntimeException on IOException instead of returning empty buffer
  • FlatAppendFile: getFileCorrectSize changed to bounded 3-retry
  • IndexStoreFile: timeDiff clamped to [0, Integer.MAX_VALUE]

Log standardization: unify to ClassName#methodName, description, key={} format.

Describe Alternatives You've Considered

N/A

Additional Context

N/A

lizhimins avatar Jun 10 '26 12:06 lizhimins

Issue Evaluation

Type: Enhancement Category: Tiered Storage - Stability & Performance Priority: High

Assessment

This is a comprehensive enhancement request addressing critical stability and data-safety risks in the tieredstore module. The identified issues are well-documented and represent real production concerns:

Validated Concerns:

  • ✅ Memory backpressure: Unbounded memory growth is a legitimate OOM risk
  • ✅ Concurrency issues: Race conditions in PosixFileSegment and IndexStoreFile can cause data corruption
  • ✅ Resource leaks: FileChannel handles and thread pools not properly closed
  • ✅ Thread pool sizing: 256+ threads on 32-core machines is excessive
  • ✅ Error handling: Swallowing exceptions hides real failures

Proposed Solutions Review: The solutions are well-thought-out and follow best practices:

  • Memory backpressure with configurable limits (10% heap, 1GB cap)
  • Atomic read operations and proper synchronization
  • Graceful shutdown with timeouts
  • Reduced thread pool sizing based on processor count
  • Better exception propagation and logging

Recommendation

This is a significant refactoring effort covering multiple areas. Consider breaking this into smaller, focused PRs for easier review:

  1. PR 1: Memory backpressure mechanism
  2. PR 2: Concurrency fixes (PosixFileSegment, IndexStoreFile, FlatCommitLogFile)
  3. PR 3: Resource management and shutdown improvements
  4. PR 4: Thread pool optimization
  5. PR 5: Error handling and log standardization

Verdict

✅ Accepted - This enhancement addresses real production risks and the proposed solutions are sound. High priority for implementation.


🤖 Automated evaluation by oss-sentinel-ai

oss-sentinel-ai avatar Jun 10 '26 13:06 oss-sentinel-ai

Issue Evaluation

Category: type/enhancement | Status: Evaluated

Thank you for this enhancement suggestion. This has been noted for community discussion.

If you'd like to contribute a fix, feel free to submit a PR. The maintainers will review and provide feedback.


Automated evaluation by RockteMQ-AI

RockteMQ-AI avatar Jun 12 '26 08:06 RockteMQ-AI