-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[ISSUE #1692]🍻Implement ChangeInvisibleTimeProcessor#append_check_point method🚀 #1734
Conversation
WalkthroughThe pull request introduces several modifications across three main files. In Changes
Assessment against linked issues
Possibly related PRs
Suggested reviewers
📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (1)
🔇 Additional comments (4)rocketmq-broker/src/processor/change_invisible_time_processor.rs (4)
The import is correctly placed and properly used in the implementation.
The changes properly pass the new parameters and implement robust error handling with the
Casting
The implementation:
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
🔊@mxsm 🚀Thanks for your contribution 🎉. CodeRabbit(AI) will review your code first 🔥 |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1734 +/- ##
==========================================
- Coverage 28.08% 28.05% -0.03%
==========================================
Files 466 466
Lines 64167 64226 +59
==========================================
+ Hits 18019 18020 +1
- Misses 46148 46206 +58 ☔ View full report in Codecov by Sentry. |
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.
Actionable comments posted: 4
🧹 Outside diff range and nitpick comments (1)
rocketmq-broker/src/processor/change_invisible_time_processor.rs (1)
362-372
: Logging format may include unintended whitespaceThe logging statement in the
info!
macro spans multiple lines, which may introduce unintended whitespace or newlines in the log output. Consider formatting the string to avoid this issue.Apply this diff to adjust the logging format:
info!( - "change Invisible , appendCheckPoint, topic {}, queueId {},reviveId {}, cid {}, \ - startOffset {}, rt {}, result {}", + "change Invisible, appendCheckPoint, topic {}, queueId {}, reviveId {}, cid {}, startOffset {}, rt {}, result {}", request_header.topic, queue_id, revive_qid, request_header.consumer_group, offset, ck.get_revive_time(), put_message_result.put_message_status() );
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
rocketmq-broker/src/processor/change_invisible_time_processor.rs
(3 hunks)rocketmq-common/src/common/broker/broker_config.rs
(2 hunks)rocketmq-store/src/pop/pop_check_point.rs
(1 hunks)
🔇 Additional comments (3)
rocketmq-broker/src/processor/change_invisible_time_processor.rs (2)
45-45
: Import PopCheckPoint
The PopCheckPoint
struct is now imported, which is necessary for the updated checkpoint management.
207-212
: Verify usage of new parameters in append_check_point
The call to append_check_point
now includes the additional parameters queue_id
and offset
. Ensure that these parameters are correctly used within the append_check_point
method and that all other calls to this method have been updated accordingly.
Run the following script to check for all calls to append_check_point
:
✅ Verification successful
Let me search for the implementation of append_check_point
to verify how these parameters are used.
Let me try a different approach to find the implementation using ripgrep with more context.
Let me try one more time with a simpler ripgrep command to get the implementation.
Parameters are correctly used in append_check_point
implementation
The implementation shows that both queue_id
and offset
parameters are properly utilized:
queue_id
is assigned to thePopCheckPoint
struct'squeue_id
fieldoffset
is assigned to thestart_offset
field of thePopCheckPoint
struct
Since this is the only call site of append_check_point
in the codebase (as shown by our first search), and the implementation correctly uses the parameters, there are no issues to address.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Find all usages of `append_check_point` in the codebase and display with context.
rg 'append_check_point\(' -A 5
Length of output: 1190
Script:
#!/bin/bash
# Search for the implementation of append_check_point using ast-grep
ast-grep --pattern 'async fn append_check_point($$$) {
$$$
}'
Length of output: 65
Script:
#!/bin/bash
# Search for the implementation of append_check_point with more context
rg -U 'async fn append_check_point.*?\{.*?\}' -A 30
Length of output: 53
Script:
#!/bin/bash
# Search for the implementation with more context lines
rg 'async fn append_check_point' -B 5 -A 30 rocketmq-broker/src/processor/change_invisible_time_processor.rs
Length of output: 1417
rocketmq-common/src/common/broker/broker_config.rs (1)
270-270
: Default value for enable_pop_log
The enable_pop_log
field is set to false
by default, which is acceptable. Ensure that this aligns with the expected default behavior for logging.
let deliver_time_ms = ck.get_revive_time() - PopAckConstants::ACK_TIME_INTERVAL; | ||
inner.set_delay_time_ms(deliver_time_ms as u64); |
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.
Possible integer underflow when calculating deliver_time_ms
The calculation of deliver_time_ms
may result in a negative value if PopAckConstants::ACK_TIME_INTERVAL
is greater than ck.get_revive_time()
. Casting a negative i64
to u64
in inner.set_delay_time_ms(deliver_time_ms as u64)
could lead to unexpected behavior. Consider ensuring that deliver_time_ms
is non-negative before casting.
Apply this diff to check for non-negative deliver_time_ms
:
let deliver_time_ms = ck.get_revive_time() - PopAckConstants::ACK_TIME_INTERVAL;
+let deliver_time_ms = if deliver_time_ms > 0 {
+ deliver_time_ms as u64
+} else {
+ 0
+};
inner.set_delay_time_ms(deliver_time_ms);
📝 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.
let deliver_time_ms = ck.get_revive_time() - PopAckConstants::ACK_TIME_INTERVAL; | |
inner.set_delay_time_ms(deliver_time_ms as u64); | |
let deliver_time_ms = ck.get_revive_time() - PopAckConstants::ACK_TIME_INTERVAL; | |
let deliver_time_ms = if deliver_time_ms > 0 { | |
deliver_time_ms as u64 | |
} else { | |
0 | |
}; | |
inner.set_delay_time_ms(deliver_time_ms); |
let mut ck = PopCheckPoint { | ||
bit_map: 0, | ||
num: 1, | ||
pop_time: pop_time as i64, |
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.
Potential overflow when casting pop_time
from u64
to i64
Casting pop_time
from u64
to i64
may result in an overflow if the value of pop_time
exceeds i64::MAX
. Consider validating pop_time
before casting or using u64
for the pop_time
field in PopCheckPoint
.
Apply this diff to change the field type to u64
:
pub struct PopCheckPoint {
- #[serde(rename = "pt")]
- pub pop_time: i64,
+ #[serde(rename = "pt")]
+ pub pop_time: u64,
// ...
}
Committable suggestion skipped: line range outside the PR's diff.
pub fn get_revive_time(&self) -> i64 { | ||
self.pop_time + self.invisible_time | ||
} |
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.
Potential integer overflow in get_revive_time
Adding pop_time
and invisible_time
may cause an overflow if the sum exceeds i64::MAX
. To prevent this, consider using checked_add
to handle potential overflows safely.
Apply this diff to use checked_add
and handle the overflow:
- pub fn get_revive_time(&self) -> i64 {
- self.pop_time + self.invisible_time
+ pub fn get_revive_time(&self) -> Option<i64> {
+ self.pop_time.checked_add(self.invisible_time)
}
Ensure to handle the Option<i64>
return type appropriately in the calling code.
📝 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 get_revive_time(&self) -> i64 { | |
self.pop_time + self.invisible_time | |
} | |
pub fn get_revive_time(&self) -> Option<i64> { | |
self.pop_time.checked_add(self.invisible_time) | |
} |
@@ -179,6 +179,7 @@ pub struct BrokerConfig { | |||
pub load_balance_poll_name_server_interval: u64, | |||
pub server_load_balancer_enable: bool, | |||
pub enable_remote_escape: bool, | |||
pub enable_pop_log: bool, |
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
Ensure enable_pop_log
is included in properties serialization
The new field enable_pop_log
is added to BrokerConfig
but is not included in the get_properties
method. If this property needs to be shared or persisted, consider adding it to the properties map.
Apply this diff to include enable_pop_log
in get_properties
:
properties.insert(
"forwardTimeout".into(),
self.forward_timeout.to_string().into(),
);
+ properties.insert(
+ "enablePopLog".into(),
+ self.enable_pop_log.to_string().into(),
+ );
}
Committable suggestion skipped: line range outside the PR's diff.
🔊@mxsm 🚀Thanks for your contribution 🎉. CodeRabbit(AI) will review your code first 🔥 |
Which Issue(s) This PR Fixes(Closes)
Fixes #1692
Brief Description
How Did You Test This Change?
Summary by CodeRabbit
New Features
enable_pop_log
in the broker settings.get_revive_time
to calculate revive time in thePopCheckPoint
struct.Enhancements
append_check_point
method to include additional parameters for improved error handling and processing logic.