Skip to content

[ISSUE #9699] Optimize shutdown process and resource management#9700

Merged
ltamber merged 9 commits intoapache:developfrom
RongtongJin:pr-shutdown-0913
Sep 17, 2025
Merged

[ISSUE #9699] Optimize shutdown process and resource management#9700
ltamber merged 9 commits intoapache:developfrom
RongtongJin:pr-shutdown-0913

Conversation

@RongtongJin
Copy link
Copy Markdown
Contributor

Which Issue(s) This PR Fixes

Fixes #9699

This PR optimizes the shutdown process and resource management across multiple RocketMQ components to ensure graceful shutdown and prevent resource leaks.

Brief Description

Key Improvements:

  1. Enhanced BrokerController Shutdown Sequence

    • Improved shutdown order for all broker services
    • Added proper termination for transactional message services
    • Enhanced cleanup of notification processors and offset managers
  2. Storage Layer Optimizations

    • DefaultMessageStore: Enhanced shutdown flow with proper state management
    • CommitLog: Improved resource cleanup during shutdown
    • MappedFileQueue: Added proper shutdown handling
    • StoreCheckpoint: Enhanced checkpoint shutdown process
    • DefaultHAService: Improved HA service shutdown
  3. Timer Component Enhancements

    • TimerMessageStore: Comprehensive shutdown improvements with proper resource cleanup
    • TimerCheckpoint: Enhanced checkpoint shutdown process
    • TimerLog: Improved log shutdown handling
    • TimerWheel: Better wheel shutdown management
  4. Processor Improvements

    • AckMessageProcessor: Added proper shutdown handling
    • NotificationProcessor: Enhanced shutdown process
    • PopMessageProcessor: Improved shutdown sequence
    • PopBufferMergeService: Better resource cleanup
  5. Common Components

    • AbstractRocksDBStorage: Enhanced RocksDB shutdown process
    • StatisticsManager: Improved statistics cleanup
    • ClientHousekeepingService: Better client cleanup

Impact:

  • Prevents resource leaks during broker shutdown
  • Ensures graceful termination of all components
  • Improves system stability and reliability
  • Fixes test failures related to improper shutdown handling

How Did You Test This Change?

Manual Testing Scenarios:

  • Broker startup and shutdown cycles
  • Resource cleanup verification
  • State management validation
  • Error handling verification

- Improve BrokerController shutdown flow for graceful shutdown
- Optimize BrokerStartup startup and shutdown logic
- Enhance ClientHousekeepingService resource cleanup
- Improve shutdown handling for various processors
- Optimize resource management in storage layer components
- Enhance lifecycle management for statistics manager
- Improve shutdown flow for timer components
- Add proper null checks and exception handling in test cleanup
- Prevent IllegalStateException during test teardown
- Ensure graceful test cleanup without state conflicts
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Sep 14, 2025

Codecov Report

❌ Patch coverage is 46.37681% with 111 lines in your changes missing coverage. Please review.
✅ Project coverage is 48.09%. Comparing base (1d9b02c) to head (c12e2ee).

Files with missing lines Patch % Lines
...apache/rocketmq/store/timer/TimerMessageStore.java 47.45% 11 Missing and 20 partials ⚠️
...org/apache/rocketmq/store/DefaultMessageStore.java 51.72% 4 Missing and 10 partials ⚠️
...rocketmq/common/config/AbstractRocksDBStorage.java 0.00% 12 Missing ⚠️
...main/java/org/apache/rocketmq/store/CommitLog.java 40.00% 3 Missing and 3 partials ⚠️
...ache/rocketmq/store/logfile/DefaultMappedFile.java 58.33% 4 Missing and 1 partial ⚠️
...g/apache/rocketmq/store/timer/TimerCheckpoint.java 44.44% 3 Missing and 2 partials ⚠️
...a/org/apache/rocketmq/broker/BrokerController.java 50.00% 0 Missing and 4 partials ⚠️
...rocketmq/broker/processor/PopMessageProcessor.java 0.00% 4 Missing ⚠️
...ava/org/apache/rocketmq/store/StoreCheckpoint.java 63.63% 4 Missing ⚠️
...rocketmq/store/queue/RocksDBConsumeQueueStore.java 42.85% 1 Missing and 3 partials ⚠️
... and 9 more
Additional details and impacted files
@@              Coverage Diff              @@
##             develop    #9700      +/-   ##
=============================================
- Coverage      48.18%   48.09%   -0.09%     
+ Complexity     12141    12138       -3     
=============================================
  Files           1313     1313              
  Lines          93113    93238     +125     
  Branches       11904    11950      +46     
=============================================
- Hits           44868    44845      -23     
- Misses         42715    42810      +95     
- Partials        5530     5583      +53     

☔ View full report in Codecov by Sentry.
📢 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.

fuyou001
fuyou001 previously approved these changes Sep 15, 2025
Copy link
Copy Markdown
Contributor

@fuyou001 fuyou001 left a comment

Choose a reason for hiding this comment

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

LGTM

@ltamber ltamber merged commit 73e8fdb into apache:develop Sep 17, 2025
22 of 29 checks passed
@RongtongJin RongtongJin added the ha label Sep 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Enhancement] Optimize shutdown process and resource management for graceful broker shutdown

5 participants