-
Notifications
You must be signed in to change notification settings - Fork 175
[ISSUE #4016]♻️Refactor: Simplify kv_config_path and config_store_path methods for improved readability #4017
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -37,25 +37,17 @@ mod defaults { | |||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| pub fn kv_config_path() -> String { | ||||||||||||||||||||||||||||||||||||||||||||||||
| format!( | ||||||||||||||||||||||||||||||||||||||||||||||||
| "{}{}{}{}{}", | ||||||||||||||||||||||||||||||||||||||||||||||||
| dirs::home_dir().unwrap().to_str().unwrap(), | ||||||||||||||||||||||||||||||||||||||||||||||||
| MAIN_SEPARATOR, | ||||||||||||||||||||||||||||||||||||||||||||||||
| "rocketmq-namesrv", | ||||||||||||||||||||||||||||||||||||||||||||||||
| MAIN_SEPARATOR, | ||||||||||||||||||||||||||||||||||||||||||||||||
| "kvConfig.json" | ||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||
| let mut kv_config_path = dirs::home_dir().unwrap_or_default(); | ||||||||||||||||||||||||||||||||||||||||||||||||
| kv_config_path.push("namesrv"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| kv_config_path.push("kvConfig.json"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| kv_config_path.to_str().unwrap_or_default().to_string() | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| pub fn config_store_path() -> String { | ||||||||||||||||||||||||||||||||||||||||||||||||
| format!( | ||||||||||||||||||||||||||||||||||||||||||||||||
| "{}{}{}{}{}", | ||||||||||||||||||||||||||||||||||||||||||||||||
| dirs::home_dir().unwrap().to_str().unwrap(), | ||||||||||||||||||||||||||||||||||||||||||||||||
| MAIN_SEPARATOR, | ||||||||||||||||||||||||||||||||||||||||||||||||
| "rocketmq-namesrv", | ||||||||||||||||||||||||||||||||||||||||||||||||
| MAIN_SEPARATOR, | ||||||||||||||||||||||||||||||||||||||||||||||||
| "rocketmq-namesrv.properties" | ||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||
| let mut kv_config_path = dirs::home_dir().unwrap_or_default(); | ||||||||||||||||||||||||||||||||||||||||||||||||
| kv_config_path.push("namesrv"); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+41
to
+48
|
||||||||||||||||||||||||||||||||||||||||||||||||
| kv_config_path.push("namesrv.properties"); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
| kv_config_path.push("namesrv.properties"); | |
| kv_config_path.push("rocketmq-namesrv.properties"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Filename and folder regressions + misnamed local var
- Folder changed to "namesrv" and file to "namesrv.properties" (was "rocketmq-namesrv.properties"), which breaks backward compatibility and differs from Default::default().
- Local var
kv_config_pathis misleading inconfig_store_path().
Apply:
- let mut kv_config_path = dirs::home_dir().unwrap_or_default();
- kv_config_path.push("namesrv");
- kv_config_path.push("namesrv.properties");
- kv_config_path.to_str().unwrap_or_default().to_string()
+ let mut path = dirs::home_dir().expect("home_dir unavailable");
+ path.push("rocketmq-namesrv");
+ path.push("rocketmq-namesrv.properties");
+ path.to_string_lossy().into_owned()If you add the helper suggested above:
- let mut path = dirs::home_dir().expect("home_dir unavailable");
- path.push("rocketmq-namesrv");
- path.push("rocketmq-namesrv.properties");
- path.to_string_lossy().into_owned()
+ default_namesrv_file("rocketmq-namesrv.properties")📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| pub fn config_store_path() -> String { | |
| format!( | |
| "{}{}{}{}{}", | |
| dirs::home_dir().unwrap().to_str().unwrap(), | |
| MAIN_SEPARATOR, | |
| "rocketmq-namesrv", | |
| MAIN_SEPARATOR, | |
| "rocketmq-namesrv.properties" | |
| ) | |
| let mut kv_config_path = dirs::home_dir().unwrap_or_default(); | |
| kv_config_path.push("namesrv"); | |
| kv_config_path.push("namesrv.properties"); | |
| kv_config_path.to_str().unwrap_or_default().to_string() | |
| } | |
| pub fn config_store_path() -> String { | |
| - let mut kv_config_path = dirs::home_dir().unwrap_or_default(); | |
| - kv_config_path.push("namesrv"); | |
| - kv_config_path.push("namesrv.properties"); | |
| let mut path = dirs::home_dir().expect("home_dir unavailable"); | |
| path.push("rocketmq-namesrv"); | |
| path.push("rocketmq-namesrv.properties"); | |
| path.to_string_lossy().into_owned() | |
| } |
🤖 Prompt for AI Agents
In rocketmq-common/src/common/namesrv/namesrv_config.rs around lines 46 to 51,
the function changed the folder/file to "namesrv/namesrv.properties" and uses a
misleading local variable name `kv_config_path`; restore backward compatibility
by using the original filename "rocketmq-namesrv.properties" (and the original
folder if applicable to match Default::default()), and rename the local variable
to a clearer name such as `config_path` or `path`; if you added the suggested
helper, call it here instead of duplicating logic so the path generation is
centralized and consistent with Default::default().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Unintended behavior change + silent fallback: align path and avoid empty-string defaults
Apply:
Optional helper to DRY both functions (place inside
defaultsmodule, outside this hunk):🤖 Prompt for AI Agents
💡 Verification agent
🧩 Analysis chain
Repo-wide check for path changes
Scan for usages that assume "rocketmq-namesrv" or "rocketmq-namesrv.properties" to ensure no hidden breakages if names were to change.
Also applies to: 46-51
🏁 Script executed:
Length of output: 148
🏁 Script executed:
Length of output: 73664
Unify namesrv path naming: resolve 'namesrv' vs 'rocketmq-namesrv' inconsistency
defaults::kv_config_path / defaults::config_store_path build paths under ~/namesrv/* while Default::default and format! calls build ~/rocketmq-namesrv/* — this will cause inconsistent runtime locations and break config/kv loading. Pick one canonical directory name (or add explicit fallback checks) and update all occurrences.
Locations to fix:
🤖 Prompt for AI Agents