[Enhancement] Tiered Storage: memory backpressure, concurrency hardening and bug fixes
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
& 0x7FFFFFFFto prevent MIN_VALUE overflow - FlatCommitLogFile: local variable snapshot for firstOffset to prevent TOCTOU
- FlatMessageFile: add
volatileto metadata fields
Resource management:
- FileSegment
close()waits for in-flight commit (30s timeout) - PosixFileSegment: store RAF references to prevent handle leaks
- MessageStoreExecutor
shutdown(): addawaitTermination(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-throwErrorinstead of swallowing - PosixFileSegment: throw
RuntimeExceptionon IOException instead of returning empty buffer - FlatAppendFile:
getFileCorrectSizechanged to bounded 3-retry - IndexStoreFile:
timeDiffclamped 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
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:
- PR 1: Memory backpressure mechanism
- PR 2: Concurrency fixes (PosixFileSegment, IndexStoreFile, FlatCommitLogFile)
- PR 3: Resource management and shutdown improvements
- PR 4: Thread pool optimization
- 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
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