-
Notifications
You must be signed in to change notification settings - Fork 173
[ISSUE #4014]♻️Refactor: Update async functions to return RocketMQResult for better error handling #4015
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
[ISSUE #4014]♻️Refactor: Update async functions to return RocketMQResult for better error handling #4015
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 |
---|---|---|
|
@@ -60,7 +60,7 @@ async fn main() -> Result<()> { | |
}) | ||
.build() | ||
.boot() | ||
.await; | ||
.await?; | ||
|
||
Ok(()) | ||
} | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -19,9 +19,10 @@ use std::sync::Arc; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
use cheetah_string::CheetahString; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
use rocketmq_common::common::namesrv::namesrv_config::NamesrvConfig; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
use rocketmq_common::utils::serde_json_utils::SerdeJsonUtils; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
use rocketmq_common::FileUtils; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
use rocketmq_error::RocketMQResult; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
use rocketmq_remoting::protocol::body::kv_table::KVTable; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
use rocketmq_remoting::protocol::RemotingDeserializable; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
use rocketmq_remoting::protocol::RemotingSerializable; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
use rocketmq_rust::ArcMut; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
use tracing::error; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -82,23 +83,23 @@ impl KVConfigManager { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
impl KVConfigManager { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
/// Loads key-value configurations from a file. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pub fn load(&mut self) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pub fn load(&mut self) -> RocketMQResult<()> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let result = FileUtils::file_to_string( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.name_server_runtime_inner | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.name_server_config() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.kv_config_path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.as_str(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if let Ok(content) = result { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let wrapper = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
SerdeJsonUtils::decode::<KVConfigSerializeWrapper>(content.as_bytes()).unwrap(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let wrapper = KVConfigSerializeWrapper::decode(content.as_bytes())?; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if let Some(config_table) = wrapper.config_table { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
for (key, value) in config_table { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.config_table.insert(key, value); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
info!("load KV config success"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Ok(()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+86
to
103
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Propagate file I/O errors and skip decoding empty content to avoid startup failure
- pub fn load(&mut self) -> RocketMQResult<()> {
- let result = FileUtils::file_to_string(
- self.name_server_runtime_inner
- .name_server_config()
- .kv_config_path
- .as_str(),
- );
- if let Ok(content) = result {
- let wrapper = KVConfigSerializeWrapper::decode(content.as_bytes())?;
- if let Some(config_table) = wrapper.config_table {
- for (key, value) in config_table {
- self.config_table.insert(key, value);
- }
- info!("load KV config success");
- }
- }
- Ok(())
- }
+ pub fn load(&mut self) -> RocketMQResult<()> {
+ let path = self
+ .name_server_runtime_inner
+ .name_server_config()
+ .kv_config_path
+ .as_str();
+ let content = FileUtils::file_to_string(path)?;
+ if content.trim().is_empty() {
+ // Missing or empty file is not an error; nothing to load.
+ return Ok(());
+ }
+ let wrapper = KVConfigSerializeWrapper::decode(content.as_bytes())?;
+ if let Some(config_table) = wrapper.config_table {
+ for (key, value) in config_table {
+ self.config_table.insert(key, value);
+ }
+ info!("load KV config success");
+ }
+ Ok(())
+ } 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
/// Updates the Namesrv configuration. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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.
The change from
SerdeJsonUtils::decode()
toKVConfigSerializeWrapper::decode()
may introduce a breaking change if the deserialization behavior differs. Ensure thatKVConfigSerializeWrapper::decode()
provides the same error handling and deserialization logic as the previous implementation.Copilot uses AI. Check for mistakes.