Repository navigation
[ISSUE #4465] BrokerRuntimeInner#message_store method to return an Option reference for improved safety - #4509
Conversation
… for improved safety
|
🔊@EricZZZ 🚀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💥. |
WalkthroughThe Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
rocketmq-broker/src/topic/manager/topic_config_manager.rs (1)
405-436: Bug: new topics increate_topic_in_send_message_back_methodcan panic when registering broker dataIn
create_topic_in_send_message_back_method, you currently do:let mut config = ArcMut::new(TopicConfig::new(topic)); ... let current_ref = self.put_topic_config(config); ... (self.data_version...).next_version_with(...); self.persist(); (current_ref, true) ... if create_new { self.register_broker_data(topic_config.clone().unwrap()); }However,
put_topic_configreturns the previous value from the map, so for a newly created topiccurrent_refwill beNone. You then propagate(current_ref, true)intotopic_config/create_new, andtopic_config.clone().unwrap()will panic on exactly the case where you are inserting a fresh topic.You likely intended to use the newly created
confighere, similar to howcreate_topic_in_send_message_methodandcreate_topic_of_tran_check_max_timebehave. A minimal fix:- let current_ref = self.put_topic_config(config); + self.put_topic_config(config.clone()); self.data_version.mut_from_ref().next_version_with( self.broker_runtime_inner .message_store() .unwrap() .get_state_machine_version(), ); self.persist(); - (current_ref, true) + (Some(config), true)This ensures
topic_configisSome(new_config)whencreate_newistrue, avoiding the panic and correctly registering the new topic.
🧹 Nitpick comments (1)
rocketmq-broker/src/topic/manager/topic_config_manager.rs (1)
361-365: Unifystate_machine_versionlookup to avoid repeatedmessage_store().unwrap()You now handle the
Nonecase explicitly indelete_topic_config, but other sites still do:
create_topic_in_send_message_method(lines 361–365)create_topic_in_send_message_back_method(lines 421–427)update_topic_config(lines 530–535)create_topic_of_tran_check_max_time(lines 602–607)If
message_storecan ever be legitimatelyNone, theseunwrap()calls would still panic; if it’s an invariant that it is alwaysSomeafter broker startup, that invariant is currently implicit and duplicated. Consider centralizing this in a small helper (e.g., a method returning the currentstate_machine_version, either handlingNonelikedelete_topic_configor using anexpectwith a clear message). This would reduce repetition and make the lifecycle assumptions aroundmessage_storeexplicit.Also applies to: 421-427, 530-535, 602-607
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (21)
rocketmq-broker/src/broker_runtime.rs(1 hunks)rocketmq-broker/src/failover/escape_bridge.rs(1 hunks)rocketmq-broker/src/long_polling/long_polling_service/pull_request_hold_service.rs(0 hunks)rocketmq-broker/src/processor/ack_message_processor.rs(2 hunks)rocketmq-broker/src/processor/admin_broker_processor/broker_config_request_handler.rs(1 hunks)rocketmq-broker/src/processor/admin_broker_processor/broker_epoch_cache_handler.rs(1 hunks)rocketmq-broker/src/processor/admin_broker_processor/consumer_request_handler.rs(0 hunks)rocketmq-broker/src/processor/admin_broker_processor/offset_request_handler.rs(0 hunks)rocketmq-broker/src/processor/admin_broker_processor/topic_request_handler.rs(0 hunks)rocketmq-broker/src/processor/change_invisible_time_processor.rs(0 hunks)rocketmq-broker/src/processor/consumer_manage_processor.rs(0 hunks)rocketmq-broker/src/processor/pop_message_processor.rs(0 hunks)rocketmq-broker/src/processor/processor_service/pop_revive_service.rs(0 hunks)rocketmq-broker/src/processor/pull_message_processor.rs(0 hunks)rocketmq-broker/src/processor/query_message_processor.rs(0 hunks)rocketmq-broker/src/processor/reply_message_processor.rs(0 hunks)rocketmq-broker/src/processor/send_message_processor.rs(0 hunks)rocketmq-broker/src/schedule/schedule_message_service.rs(0 hunks)rocketmq-broker/src/subscription/manager/subscription_group_manager.rs(0 hunks)rocketmq-broker/src/topic/manager/topic_config_manager.rs(1 hunks)rocketmq-broker/src/transaction/queue/transactional_message_bridge.rs(0 hunks)
💤 Files with no reviewable changes (15)
- rocketmq-broker/src/processor/consumer_manage_processor.rs
- rocketmq-broker/src/processor/admin_broker_processor/consumer_request_handler.rs
- rocketmq-broker/src/transaction/queue/transactional_message_bridge.rs
- rocketmq-broker/src/processor/reply_message_processor.rs
- rocketmq-broker/src/processor/change_invisible_time_processor.rs
- rocketmq-broker/src/processor/admin_broker_processor/topic_request_handler.rs
- rocketmq-broker/src/processor/processor_service/pop_revive_service.rs
- rocketmq-broker/src/processor/send_message_processor.rs
- rocketmq-broker/src/schedule/schedule_message_service.rs
- rocketmq-broker/src/long_polling/long_polling_service/pull_request_hold_service.rs
- rocketmq-broker/src/processor/query_message_processor.rs
- rocketmq-broker/src/processor/pop_message_processor.rs
- rocketmq-broker/src/processor/pull_message_processor.rs
- rocketmq-broker/src/subscription/manager/subscription_group_manager.rs
- rocketmq-broker/src/processor/admin_broker_processor/offset_request_handler.rs
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-05-10T06:20:00.401Z
Learnt from: 578223592
Repo: mxsm/rocketmq-rust PR: 3240
File: rocketmq-namesrv/src/kvconfig/kvconfig_mananger.rs:69-71
Timestamp: 2025-05-10T06:20:00.401Z
Learning: In RocketMQ Rust, while dashmap is concurrent-safe, returning a direct reference to a DashMap can break encapsulation by allowing external code to modify the map without triggering persistence methods like `persist()`. Consider returning a read-only view, iterator methods, or a snapshot instead.
Applied to files:
rocketmq-broker/src/broker_runtime.rsrocketmq-broker/src/processor/admin_broker_processor/broker_config_request_handler.rsrocketmq-broker/src/failover/escape_bridge.rs
🧬 Code graph analysis (4)
rocketmq-broker/src/processor/ack_message_processor.rs (1)
rocketmq-broker/src/broker_runtime.rs (1)
message_store(1922-1924)
rocketmq-broker/src/processor/admin_broker_processor/broker_epoch_cache_handler.rs (2)
rocketmq-broker/src/broker_runtime.rs (1)
message_store(1922-1924)rocketmq-broker/src/topic/manager/topic_config_manager.rs (1)
broker_runtime_inner(637-639)
rocketmq-broker/src/failover/escape_bridge.rs (1)
rocketmq-broker/src/broker_runtime.rs (1)
message_store(1922-1924)
rocketmq-broker/src/topic/manager/topic_config_manager.rs (1)
rocketmq-broker/src/broker_runtime.rs (1)
message_store(1922-1924)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Check (fmt + clippy)
- GitHub Check: auto-approve
🔇 Additional comments (7)
rocketmq-broker/src/broker_runtime.rs (1)
1922-1924: LGTM - Improved API ergonomics with idiomatic Rust pattern.The change from
&Option<ArcMut<MS>>toOption<&ArcMut<MS>>is a good refactor. ReturningOption<&T>instead of&Option<T>is more idiomatic in Rust because:
- Callers can directly use
.unwrap(),.map(),.ok_or()etc. without needing an intermediate.as_ref()call- It communicates intent better - the caller gets an optional reference rather than a reference to an optional value
rocketmq-broker/src/failover/escape_bridge.rs (1)
473-473: Consistent with the API change.The call site correctly adapts to the new
message_store()signature. Sincemessage_store()now returnsOption<&ArcMut<MS>>, the.unwrap()directly yields&ArcMut<MS>, eliminating the need for.clone().rocketmq-broker/src/processor/admin_broker_processor/broker_epoch_cache_handler.rs (1)
71-71: LGTM - Clean adaptation to the new API.The removal of
.as_ref()is correct sincemessage_store()now directly returnsOption<&ArcMut<MS>>.rocketmq-broker/src/processor/admin_broker_processor/broker_config_request_handler.rs (1)
266-266: LGTM - Consistent with the updated API.The change correctly removes the intermediate
.as_ref()call, aligning with the newmessage_store()return type.rocketmq-broker/src/processor/ack_message_processor.rs (2)
235-235: LGTM - Correctly adapted to the new API.The change aligns with the updated
message_store()signature that now returnsOption<&ArcMut<MS>>directly.
364-364: LGTM - Consistent pattern applied.Same correct adaptation as above for the batch ack code path.
rocketmq-broker/src/topic/manager/topic_config_manager.rs (1)
479-484: Safermessage_store()handling indelete_topic_config; please confirm0fallback semanticsUsing
if let Some(message_store) = self.broker_runtime_inner.message_store()here avoids a panic whenmessage_storeisNone, which is a clear safety improvement for this path. The only open question is whether passing0intoDataVersion::next_version_withis always semantically correct for “no message store available” (e.g., during early startup or specific test modes). If0is intended as a sentinel, consider adding a short comment, or otherwise double‑check that this won’t regress any versioning assumptions.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #4509 +/- ##
==========================================
+ Coverage 30.35% 30.37% +0.01%
==========================================
Files 673 673
Lines 97386 97329 -57
==========================================
Hits 29561 29561
+ Misses 67825 67768 -57 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
rocketmq-rust-bot
left a comment
There was a problem hiding this comment.
LGTM - All CI checks passed ✅
Which Issue(s) This PR Fixes(Closes)
Fixes #4465
Brief Description
How Did You Test This Change?
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.