-
Notifications
You must be signed in to change notification settings - Fork 111
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 #682]🚀Optimize ResponseCode #683
Conversation
(cherry picked from commit dbd78248f3ab4c059ee3e7375cd26c43826bc42a)
🚀Thanks for your contribution🎉. CodeRabbit(AI) will review your code first🔥 |
WalkthroughThe changes primarily focus on improving the Changes
Assessment against linked issues
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 as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
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: 2
Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Files selected for processing (2)
- rocketmq-broker/src/out_api/broker_outer_api.rs (2 hunks)
- rocketmq-remoting/src/code/response_code.rs (1 hunks)
Files skipped from review due to trivial changes (1)
- rocketmq-broker/src/out_api/broker_outer_api.rs
Additional comments not posted (1)
rocketmq-remoting/src/code/response_code.rs (1)
Line range hint
9-114
: Enums are well-defined and appropriately documented.Both
RemotingSysResponseCode
andResponseCode
enums are well-structured and serve their purpose effectively in categorizing various response codes.
assert_eq!( | ||
ResponseCode::from(200), | ||
ResponseCode::TransactionShouldCommit | ||
); | ||
assert_eq!( | ||
ResponseCode::from(201), | ||
ResponseCode::TransactionShouldRollback | ||
); | ||
assert_eq!( | ||
ResponseCode::from(202), | ||
ResponseCode::TransactionStateUnknow | ||
); | ||
assert_eq!( | ||
ResponseCode::from(203), | ||
ResponseCode::TransactionStateGroupWrong | ||
); | ||
assert_eq!(ResponseCode::from(204), ResponseCode::NoBuyerId); | ||
assert_eq!(ResponseCode::from(205), ResponseCode::NotInCurrentUnit); | ||
assert_eq!(ResponseCode::from(206), ResponseCode::ConsumerNotOnline); | ||
assert_eq!(ResponseCode::from(207), ResponseCode::ConsumeMsgTimeout); | ||
assert_eq!(ResponseCode::from(208), ResponseCode::NoMessage); | ||
assert_eq!(ResponseCode::from(209), ResponseCode::PollingFull); | ||
assert_eq!(ResponseCode::from(210), ResponseCode::PollingTimeout); | ||
assert_eq!(ResponseCode::from(211), ResponseCode::BrokerNotExist); | ||
assert_eq!( | ||
ResponseCode::from(212), | ||
ResponseCode::BrokerDispatchNotComplete | ||
); | ||
assert_eq!(ResponseCode::from(213), ResponseCode::BroadcastConsumption); | ||
assert_eq!(ResponseCode::from(215), ResponseCode::FlowControl); | ||
assert_eq!(ResponseCode::from(501), ResponseCode::NotLeaderForQueue); | ||
assert_eq!(ResponseCode::from(604), ResponseCode::IllegalOperation); | ||
assert_eq!(ResponseCode::from(-1000), ResponseCode::RpcUnknown); | ||
assert_eq!(ResponseCode::from(-1002), ResponseCode::RpcAddrIsNull); | ||
assert_eq!( | ||
ResponseCode::from(-1004), | ||
ResponseCode::RpcSendToChannelFailed | ||
); | ||
assert_eq!(ResponseCode::from(-1006), ResponseCode::RpcTimeOut); | ||
assert_eq!(ResponseCode::from(1500), ResponseCode::GoAway); | ||
assert_eq!( | ||
ResponseCode::from(2000), | ||
ResponseCode::ControllerFencedMasterEpoch | ||
); | ||
assert_eq!( | ||
ResponseCode::from(2001), | ||
ResponseCode::ControllerFencedSyncStateSetEpoch | ||
); | ||
assert_eq!( | ||
ResponseCode::from(2002), | ||
ResponseCode::ControllerInvalidMaster | ||
); | ||
assert_eq!( | ||
ResponseCode::from(2003), | ||
ResponseCode::ControllerInvalidReplicas | ||
); | ||
assert_eq!( | ||
ResponseCode::from(2004), | ||
ResponseCode::ControllerMasterNotAvailable | ||
); | ||
assert_eq!( | ||
ResponseCode::from(2005), | ||
ResponseCode::ControllerInvalidRequest | ||
); | ||
assert_eq!( | ||
ResponseCode::from(2006), | ||
ResponseCode::ControllerBrokerNotAlive | ||
); | ||
assert_eq!(ResponseCode::from(2007), ResponseCode::ControllerNotLeader); | ||
assert_eq!( | ||
ResponseCode::from(2008), | ||
ResponseCode::ControllerBrokerMetadataNotExist | ||
); | ||
assert_eq!( | ||
ResponseCode::from(2009), | ||
ResponseCode::ControllerInvalidCleanBrokerMetadata | ||
); | ||
assert_eq!( | ||
ResponseCode::from(2010), | ||
ResponseCode::ControllerBrokerNeedToBeRegistered | ||
); | ||
assert_eq!( | ||
ResponseCode::from(2011), | ||
ResponseCode::ControllerMasterStillExist | ||
); | ||
assert_eq!( | ||
ResponseCode::from(2012), | ||
ResponseCode::ControllerElectMasterFailed | ||
); | ||
assert_eq!( | ||
ResponseCode::from(2013), | ||
ResponseCode::ControllerAlterSyncStateSetFailed | ||
); | ||
assert_eq!( | ||
ResponseCode::from(2014), | ||
ResponseCode::ControllerBrokerIdInvalid | ||
); | ||
assert_eq!(ResponseCode::from(9999), ResponseCode::SystemError); // Edge case | ||
} | ||
} |
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.
Add test for default case in conversion.
The tests are well-implemented and cover a wide range of cases. However, to ensure robustness, consider adding a test for the default case in the From<i32> for ResponseCode
implementation to handle unexpected values gracefully.
#[test]
fn response_code_from_unexpected_i32() {
assert_eq!(ResponseCode::from(9999), ResponseCode::SystemError); // Assuming SystemError is your default case
}
impl From<i32> for ResponseCode { | ||
fn from(value: i32) -> Self { | ||
match value { | ||
0 => ResponseCode::Success, | ||
1 => ResponseCode::SystemError, | ||
2 => ResponseCode::SystemBusy, | ||
3 => ResponseCode::RequestCodeNotSupported, | ||
4 => ResponseCode::TransactionFailed, | ||
10 => ResponseCode::FlushDiskTimeout, | ||
11 => ResponseCode::SlaveNotAvailable, | ||
12 => ResponseCode::FlushSlaveTimeout, | ||
13 => ResponseCode::MessageIllegal, | ||
14 => ResponseCode::ServiceNotAvailable, | ||
15 => ResponseCode::VersionNotSupported, | ||
16 => ResponseCode::NoPermission, | ||
17 => ResponseCode::TopicNotExist, | ||
18 => ResponseCode::TopicExistAlready, | ||
19 => ResponseCode::PullNotFound, | ||
20 => ResponseCode::PullRetryImmediately, | ||
21 => ResponseCode::PullOffsetMoved, | ||
22 => ResponseCode::QueryNotFound, | ||
23 => ResponseCode::SubscriptionParseFailed, | ||
24 => ResponseCode::SubscriptionNotExist, | ||
25 => ResponseCode::SubscriptionNotLatest, | ||
26 => ResponseCode::SubscriptionGroupNotExist, | ||
27 => ResponseCode::FilterDataNotExist, | ||
28 => ResponseCode::FilterDataNotLatest, | ||
200 => ResponseCode::TransactionShouldCommit, | ||
201 => ResponseCode::TransactionShouldRollback, | ||
202 => ResponseCode::TransactionStateUnknow, | ||
203 => ResponseCode::TransactionStateGroupWrong, | ||
204 => ResponseCode::NoBuyerId, | ||
205 => ResponseCode::NotInCurrentUnit, | ||
206 => ResponseCode::ConsumerNotOnline, | ||
207 => ResponseCode::ConsumeMsgTimeout, | ||
208 => ResponseCode::NoMessage, | ||
209 => ResponseCode::PollingFull, | ||
210 => ResponseCode::PollingTimeout, | ||
211 => ResponseCode::BrokerNotExist, | ||
212 => ResponseCode::BrokerDispatchNotComplete, | ||
213 => ResponseCode::BroadcastConsumption, | ||
215 => ResponseCode::FlowControl, | ||
501 => ResponseCode::NotLeaderForQueue, | ||
604 => ResponseCode::IllegalOperation, | ||
-1000 => ResponseCode::RpcUnknown, | ||
-1002 => ResponseCode::RpcAddrIsNull, | ||
-1004 => ResponseCode::RpcSendToChannelFailed, | ||
-1006 => ResponseCode::RpcTimeOut, | ||
1500 => ResponseCode::GoAway, | ||
2000 => ResponseCode::ControllerFencedMasterEpoch, | ||
2001 => ResponseCode::ControllerFencedSyncStateSetEpoch, | ||
2002 => ResponseCode::ControllerInvalidMaster, | ||
2003 => ResponseCode::ControllerInvalidReplicas, | ||
2004 => ResponseCode::ControllerMasterNotAvailable, | ||
2005 => ResponseCode::ControllerInvalidRequest, | ||
2006 => ResponseCode::ControllerBrokerNotAlive, | ||
2007 => ResponseCode::ControllerNotLeader, | ||
2008 => ResponseCode::ControllerBrokerMetadataNotExist, | ||
2009 => ResponseCode::ControllerInvalidCleanBrokerMetadata, | ||
2010 => ResponseCode::ControllerBrokerNeedToBeRegistered, | ||
2011 => ResponseCode::ControllerMasterStillExist, | ||
2012 => ResponseCode::ControllerElectMasterFailed, | ||
2013 => ResponseCode::ControllerAlterSyncStateSetFailed, | ||
2014 => ResponseCode::ControllerBrokerIdInvalid, | ||
_ => ResponseCode::SystemError, | ||
} | ||
} | ||
} |
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 for conversion implementation.
The implementation of From<i32> for ResponseCode
is comprehensive, covering all defined enum variants. However, the default case returns ResponseCode::SystemError
which might mask unrecognized error codes. Consider logging unrecognized codes or using a dedicated Unknown
variant to handle such cases explicitly.
- _ => ResponseCode::SystemError,
+ _ => ResponseCode::Unknown, // Ensure you have an Unknown variant in your enum
Committable suggestion was skipped due to low confidence.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #683 +/- ##
==========================================
+ Coverage 26.73% 27.42% +0.68%
==========================================
Files 250 250
Lines 19145 19310 +165
==========================================
+ Hits 5119 5295 +176
+ Misses 14026 14015 -11 ☔ View full report in Codecov by Sentry. |
(cherry picked from commit dbd78248f3ab4c059ee3e7375cd26c43826bc42a)
Which Issue(s) This PR Fixes(Closes)
Fixes #682
Brief Description
How Did You Test This Change?
Summary by CodeRabbit
New Features
ResponseCode
enum.Tests
i32
toResponseCode
enum.