Skip to content

[ISSUE #2109]💫Refactor name server crate with NameServerRuntimeInner♻️ #2110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 5, 2025

Conversation

mxsm
Copy link
Owner

@mxsm mxsm commented Jan 5, 2025

Which Issue(s) This PR Fixes(Closes)

Fixes #2109

Brief Description

How Did You Test This Change?

Summary by CodeRabbit

  • Refactor

    • Restructured NameServerRuntime to improve configuration and client management
    • Consolidated multiple configuration fields into a single NameServerRuntimeInner struct
    • Updated various processor components to use the new runtime inner structure
  • New Features

    • Added ability to clone TokioClientConfig
  • Chores

    • Simplified dependency management across name server components
    • Improved code organization and encapsulation

Copy link
Contributor

coderabbitai bot commented Jan 5, 2025

Walkthrough

The pull request introduces a significant architectural refactoring of the RocketMQ name server runtime. The primary change involves creating a new NameServerRuntimeInner struct that encapsulates various configurations and managers previously scattered across different components. This refactoring consolidates RouteInfoManager, KVConfigManager, server configurations, and client configurations into a single, more organized structure, improving the overall code organization and maintainability of the name server module.

Changes

File Change Summary
rocketmq-namesrv/src/bootstrap.rs Restructured NameServerRuntime to use NameServerRuntimeInner, encapsulating configuration and manager fields
rocketmq-namesrv/src/kvconfig/kvconfig_mananger.rs Replaced namesrv_config with name_server_runtime_inner, updated methods to access configuration through new structure
rocketmq-namesrv/src/processor/client_request_processor.rs Consolidated RouteInfoManager and NamesrvConfig into NameServerRuntimeInner
rocketmq-namesrv/src/processor/default_request_processor.rs Replaced multiple fields with name_server_runtime_inner, updated method implementations
rocketmq-namesrv/src/route/route_info_manager.rs Removed namesrv_config and remoting_client, added name_server_runtime_inner
rocketmq-remoting/src/runtime/config/client_config.rs Added #[derive(Clone)] to TokioClientConfig

Assessment against linked issues

Objective Addressed Explanation
Refactor name server crate
Ensure no new bugs
Update unit tests Test modifications not clearly visible in the diff
No performance impact Performance implications require further investigation
Document architecture changes No explicit documentation provided

Possibly related PRs

Suggested labels

refactor, auto merge, ready to review, waiting-review, AI review first, rocketmq-namesrv crate

Suggested reviewers

  • TeslaRustor
  • SpaceXCN
  • rocketmq-rust-bot

Poem

🐰 A Rabbit's Refactoring Rhyme 🐰

In the name server's cozy den,
Configs danced, now gathered in one pen
Runtime inner, sleek and bright,
Brings structure to our coding might!
Refactoring with bunny delight! 🚀


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@rocketmq-rust-bot
Copy link
Collaborator

🔊@mxsm 🚀Thanks for your contribution🎉!

💡CodeRabbit(AI) will review your code first🔥!

Note

🚨The code review suggestions from CodeRabbit are to be used as a reference only, and the PR submitter can decide whether to make changes based on their own judgment. Ultimately, the project management personnel will conduct the final code review💥.

Copy link

codecov bot commented Jan 5, 2025

Codecov Report

Attention: Patch coverage is 0% with 244 lines in your changes missing coverage. Please review.

Project coverage is 28.05%. Comparing base (901322f) to head (b02ad3d).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...namesrv/src/processor/default_request_processor.rs 0.00% 125 Missing ⚠️
rocketmq-namesrv/src/bootstrap.rs 0.00% 47 Missing ⚠️
...-namesrv/src/processor/client_request_processor.rs 0.00% 27 Missing ⚠️
rocketmq-namesrv/src/route/route_info_manager.rs 0.00% 27 Missing ⚠️
rocketmq-namesrv/src/kvconfig/kvconfig_mananger.rs 0.00% 18 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2110      +/-   ##
==========================================
- Coverage   28.26%   28.05%   -0.21%     
==========================================
  Files         493      493              
  Lines       70675    70722      +47     
==========================================
- Hits        19977    19843     -134     
- Misses      50698    50879     +181     

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

Copy link
Collaborator

@rocketmq-rust-bot rocketmq-rust-bot left a comment

Choose a reason for hiding this comment

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

LGTM

@rocketmq-rust-bot rocketmq-rust-bot merged commit 967b00d into main Jan 5, 2025
23 of 26 checks passed
@rocketmq-rust-bot rocketmq-rust-bot added approved PR has approved and removed ready to review waiting-review waiting review this PR labels Jan 5, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (10)
rocketmq-namesrv/src/processor/client_request_processor.rs (1)

117-123: Optional KV config retrieval.
Storing order_topic_conf directly is reasonable. For debugging, consider logging if config retrieval returns None.

rocketmq-namesrv/src/bootstrap.rs (3)

52-60: Commented-out fields and new fields.
Leaving old fields commented might cause confusion. Removing them or using version control history can keep the codebase cleaner.

-/*name_server_config: ArcMut<NamesrvConfig>,
-  ...
-  remoting_client: ArcMut<RocketmqDefaultClient>,*/
+// Remove commented-out code for clarity unless it's temporarily kept for reference

221-223: Mutable retrieval methods.
Returning .expect("...") in route_info_manager_mut / kvconfig_manager_mut is direct. Consider returning Result to avoid panics in certain edge cases.

Also applies to: 228-230


255-257: Immutable retrieval methods.
Same concern as mutable methods—expect("...") is straightforward but panics if these resources are unexpectedly absent.

Also applies to: 262-264

rocketmq-namesrv/src/kvconfig/kvconfig_mananger.rs (2)

125-128: Persisting KV configs.
Writing updated data to name_server_runtime_inner.name_server_config().kv_config_path. Consider adding fallback or backup logic if the path is unwritable.


209-213: Test module’s usage of builder.
Commented-out test code references Builder. Re-enable or remove if no longer required.

rocketmq-namesrv/src/processor/default_request_processor.rs (4)

303-312: Optional order topic config to broker.
If return_order_topic_config_to_broker is enabled, config is included. Verify that large configs won’t cause overhead or timeouts.


453-461: All topic list retrieval.
Checking enable_all_topic_list is consistent. Potentially large lists might require pagination or streaming in the future.


542-546: Cluster-based topic retrieval.
Disabling the feature with a simple condition is fine. Log if needed.


692-695: Updating NameServer config.
Ensure partial updates remain consistent. Potential rollback mechanism if needed in production.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 901322f and b02ad3d.

📒 Files selected for processing (6)
  • rocketmq-namesrv/src/bootstrap.rs (7 hunks)
  • rocketmq-namesrv/src/kvconfig/kvconfig_mananger.rs (8 hunks)
  • rocketmq-namesrv/src/processor/client_request_processor.rs (4 hunks)
  • rocketmq-namesrv/src/processor/default_request_processor.rs (25 hunks)
  • rocketmq-namesrv/src/route/route_info_manager.rs (8 hunks)
  • rocketmq-remoting/src/runtime/config/client_config.rs (1 hunks)
🔇 Additional comments (50)
rocketmq-namesrv/src/processor/client_request_processor.rs (7)

36-36: Import addition looks appropriate.
No functional or security concerns.


42-42: Struct field consolidation enhances encapsulation.
Replacing multiple fields (route_info_manager, etc.) with name_server_runtime_inner simplifies dependency management.


48-52: Constructor refactor is clear and consistent.
Accepting a single NameServerRuntimeInner parameter ensures a cleaner interface and reduces code duplication.


70-75: Time calculation logic.
Casting to milliseconds and comparing the difference is valid. However, consider verifying large wait_seconds_for_service values are properly handled to avoid potential overflow.


76-81: Conditional server readiness check.
Logic is consistent but ensure concurrency safety if other threads also check or set need_check_namesrv_ready. Atomic usage appears correct.


94-95: Safe topic route retrieval.
No issues found using pickup_topic_route_data. Check upstream handling of the Option returned.


111-115: Conditional ordering configuration.
Using order_message_enable for gating special processing seems correct.

rocketmq-namesrv/src/bootstrap.rs (9)

79-86: Server startup logic.
Creating RocketMQServer with server_config.listen_port is straightforward. Confirm that the correct port is used for all environments.


88-93: Weak reference usage for remoting client.
Using ArcMut::downgrade is a typical pattern to prevent cyclic references. Ensure that any calls on remoting_client are preceded by validity checks.


101-117: Initialize processors & schedule tasks.
Invoking route_info_manager().start(...) and scheduling scan_not_active_broker is cohesive. Watch out for potential concurrency bottlenecks in broadcast usage.


162-166: Builder pattern usage.
Fallback to default configs is logical for NamesrvConfig and TokioClientConfig. This approach is consistent with robust code design.


169-177: Constructing NameServerRuntimeInner.
Centralizing configurations (name_server_config, tokio_client_config, etc.) fosters better maintainability.


179-182: Attaching managers to the inner field.
Assigning route_info_manager and kvconfig_manager as Some(...) ensures they remain optional. Confirm that no usage occurs before initialization.


188-188: Storing inner reference.
Clean integration of the newly-created ArcMut<NameServerRuntimeInner> into NameServerRuntime.


198-200: Optional typed fields in NameServerRuntimeInner.
The optional approach is flexible, but ensure you call .expect("...") carefully, or handle None gracefully in production.


289-289: Setters for runtime inner fields.
Implementation looks consistent. Optionally, add checks/logs to confirm valid arguments.

Also applies to: 294-294, 298-298

rocketmq-namesrv/src/kvconfig/kvconfig_mananger.rs (7)

31-31: Importing NameServerRuntimeInner.
No immediate concerns. Consolidation aligns with the PR’s refactor objective.


44-44: Single consolidated field.
Replacing namesrv_config with name_server_runtime_inner simplifies internal usage.


57-59: Redesigned constructor.
Now only requires ArcMut<NameServerRuntimeInner>. This is simpler for testing but ensure that any direct config usage is updated.

Also applies to: 62-62


83-83: Get Namesrv config from NameServerRuntimeInner.
Direct accessor usage is consistent with the new design.


90-95: Loading KV configs from file.
Reading name_server_config().kv_config_path is correct. Confirm file handling with robust error checking (though partial checks are present).


112-114: Updating config in place.
name_server_config_mut().update(...) is a direct call. Any errors are returned. This is cohesive with the new design.


217-217: Combined usage in tests.
builder.build() returning name_server_runtime_inner.kvconfig_manager() is more integrated. Possibly confirm no race conditions if tests are run in parallel.

rocketmq-namesrv/src/processor/default_request_processor.rs (19)

60-60: ArcMut import usage.
Consistent with the rest of the refactor. No issues noted.


63-63: Single name_server_runtime_inner field.
Combining the previous managers into this single reference is neat and reduces boilerplate.

Also applies to: 69-69


138-144: KV config insertion uses new runtime inner.
Ensure correct concurrency practice when updating shared data in put_kv_config.


159-160: Synchronous KV retrieval.
No issues in reading from kvconfig_manager. The code returns an error response if missing.


188-189: KV config deletion.
Again, concurrency correctness is crucial. The usage of locks inside KVConfigManager looks appropriate.


208-216: Topic config change detection.
Refactored approach via name_server_runtime_inner is logical. Double-check data version logic to prevent stale updates.

Also applies to: 217-222, 226-226


238-240: Consolidated constructor.
DefaultRequestProcessor::new(...) now only requires ArcMut<NameServerRuntimeInner>. Matches the rest of the refactor.


279-296: Broker registration logic.
Storing broker info via route_info_manager().register_broker is consistent with the new structure. Ensure the snapshot or data version mismatch is handled gracefully.


338-339: Broker unregistration.
Refactored to call route_info_manager_mut().un_register_broker. No issues.


358-363: Broker heartbeat update.
route_info_manager_mut().update_broker_info_update_timestamp(...) is straightforward.


381-382: Get broker member group.
Relies on route_info_manager_mut(). Confirm no conflicts if called in parallel with other route updates.


398-399: Getting broker cluster info.
Reads from route_info_manager().get_all_cluster_info(); no concerns found.


422-423: Modifying broker write permissions.
wipe_write_perm_of_broker_by_lock and add_write_perm_of_broker_by_lock handle locking internally. Good concurrency approach.

Also applies to: 442-443


487-488: Deleting topic in NameServer.
Synchronized with route_info_manager_mut().delete_topic(...). No further concerns.


508-509: Register topic in NameServer.
Creates or updates existing queue definitions in route_info_manager. No issues observed.


526-527: Namespace-based KV listing.
Method is consistent with the updated manager pattern.


575-578: System topic and unit topic retrieval logic.
All are straightforward read operations. No concurrency or correctness issues apparent.

Also applies to: 586-594, 612-620, 638-645


682-683: Blacklist config check.
Ensuring certain properties can’t be updated is a valid security measure.


711-711: Get entire config.
Successfully retrieves config from name_server_runtime_inner.name_server_config().

rocketmq-namesrv/src/route/route_info_manager.rs (7)

52-52: Importing NameServerRuntimeInner.
Matches the PR’s overarching refactor.


83-83: Unified field in RouteInfoManager.
name_server_runtime_inner helps centralize config & remoting client usage.


89-98: Constructor uses consolidated field.
This is consistent with other managers. Ensures shared state is managed via a single entry point.


235-238: Topic deletion upon broker registration.
Conditional delete_topic_with_broker_registration usage might surprise some brokers. Confirm these topics are truly obsolete or consider a safer approach.


346-351: Notify min broker ID changes.
Checks the notify_min_broker_id_changed config. The approach is correct but confirm potential concurrency issues if multiple concurrent calls.


1033-1038: Notification after broker unregistration.
Again checks notify_min_broker_id_changed. The logic is consistent with the new design.


1163-1170: Asynchronous socket disconnect listener.
Uses tokio::spawn referencing a cloned ArcMut<NameServerRuntimeInner>. Validate that potential simultaneous writes to route info are properly synchronized.

rocketmq-remoting/src/runtime/config/client_config.rs (1)

26-26: Enabling clone is beneficial for flexible runtime usage and configuration.

Adding #[derive(Clone)] here is straightforward and allows TokioClientConfig to be duplicated as needed. Given that all fields are either primitives or String, this clone implementation should pose no immediate performance or concurrency concerns. Good to see that no references or synchronization primitives are involved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Refactor♻️]Refactor name server crate with NameServerRuntimeInner
3 participants