Skip to content
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 #1480]⚡️Optimize SendMessageProcessor error handle🔥 #1481

Merged
merged 1 commit into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions rocketmq-broker/src/broker_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,32 @@
ClientError(#[from] rocketmq_client_rust::client_error::MQClientError),
}

impl From<BrokerError> for rocketmq_remoting::remoting_error::RemotingError {
fn from(value: BrokerError) -> Self {
match value {
BrokerError::BrokerRemotingError(e) => e,
BrokerError::BrokerCommonError(e) => {
rocketmq_remoting::remoting_error::RemotingError::RemoteError(format!("{}", e))

Check warning on line 43 in rocketmq-broker/src/broker_error.rs

View check run for this annotation

Codecov / codecov/patch

rocketmq-broker/src/broker_error.rs#L39-L43

Added lines #L39 - L43 were not covered by tests
}
BrokerError::MQBrokerError(code, message, _) => {
rocketmq_remoting::remoting_error::RemotingError::RemoteError(format!(
"CODE:{}, Message:{}",
code, message
))

Check warning on line 49 in rocketmq-broker/src/broker_error.rs

View check run for this annotation

Codecov / codecov/patch

rocketmq-broker/src/broker_error.rs#L45-L49

Added lines #L45 - L49 were not covered by tests
}
BrokerError::IllegalArgumentError(e) => {
rocketmq_remoting::remoting_error::RemotingError::RemoteError(e)

Check warning on line 52 in rocketmq-broker/src/broker_error.rs

View check run for this annotation

Codecov / codecov/patch

rocketmq-broker/src/broker_error.rs#L51-L52

Added lines #L51 - L52 were not covered by tests
}
BrokerError::ClientError(e) => {
rocketmq_remoting::remoting_error::RemotingError::RemotingCommandError(format!(
"{}",
e
))

Check warning on line 58 in rocketmq-broker/src/broker_error.rs

View check run for this annotation

Codecov / codecov/patch

rocketmq-broker/src/broker_error.rs#L54-L58

Added lines #L54 - L58 were not covered by tests
}
}
}

Check warning on line 61 in rocketmq-broker/src/broker_error.rs

View check run for this annotation

Codecov / codecov/patch

rocketmq-broker/src/broker_error.rs#L61

Added line #L61 was not covered by tests
}

#[cfg(test)]
mod tests {
use rocketmq_remoting::remoting_error::RemotingError;
Expand Down
5 changes: 3 additions & 2 deletions rocketmq-broker/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,10 @@
| RequestCode::SendMessageV2
| RequestCode::SendBatchMessage
| RequestCode::ConsumerSendMsgBack => {
self.send_message_processor
return self
.send_message_processor

Check warning on line 121 in rocketmq-broker/src/processor.rs

View check run for this annotation

Codecov / codecov/patch

rocketmq-broker/src/processor.rs#L120-L121

Added lines #L120 - L121 were not covered by tests
.process_request(channel, ctx, request_code, request)
.await
.await;

Check warning on line 123 in rocketmq-broker/src/processor.rs

View check run for this annotation

Codecov / codecov/patch

rocketmq-broker/src/processor.rs#L123

Added line #L123 was not covered by tests
}

RequestCode::SendReplyMessage | RequestCode::SendReplyMessageV2 => {
Expand Down
48 changes: 25 additions & 23 deletions rocketmq-broker/src/processor/send_message_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,13 @@
ctx: ConnectionHandlerContext,
request_code: RequestCode,
request: RemotingCommand,
) -> Option<RemotingCommand> {
) -> rocketmq_remoting::Result<Option<RemotingCommand>> {

Check warning on line 113 in rocketmq-broker/src/processor/send_message_processor.rs

View check run for this annotation

Codecov / codecov/patch

rocketmq-broker/src/processor/send_message_processor.rs#L113

Added line #L113 was not covered by tests
match request_code {
RequestCode::ConsumerSendMsgBack => {
//need to optimize
self.inner
.consumer_send_msg_back(&channel, &ctx, &request)
.unwrap()
.map_err(Into::into)

Check warning on line 119 in rocketmq-broker/src/processor/send_message_processor.rs

View check run for this annotation

Codecov / codecov/patch

rocketmq-broker/src/processor/send_message_processor.rs#L119

Added line #L119 was not covered by tests
}
_ => {
let mut request_header = parse_request_header(&request, request_code).unwrap(); //need to optimize
Expand All @@ -129,7 +129,7 @@
&mapping_context,
);
if let Some(rewrite_result) = rewrite_result {
return Some(rewrite_result);
return Ok(Some(rewrite_result));

Check warning on line 132 in rocketmq-broker/src/processor/send_message_processor.rs

View check run for this annotation

Codecov / codecov/patch

rocketmq-broker/src/processor/send_message_processor.rs#L132

Added line #L132 was not covered by tests
}

let send_message_context =
Expand All @@ -145,28 +145,30 @@
};
if request_header.batch.is_none() || !request_header.batch.unwrap() {
//handle single message
self.send_message(
&channel,
&ctx,
request,
send_message_context,
request_header,
mapping_context,
execute_send_message_hook_after,
)
.await
Ok(self
.send_message(
&channel,
&ctx,
request,
send_message_context,
request_header,
mapping_context,
execute_send_message_hook_after,
)
.await)

Check warning on line 158 in rocketmq-broker/src/processor/send_message_processor.rs

View check run for this annotation

Codecov / codecov/patch

rocketmq-broker/src/processor/send_message_processor.rs#L148-L158

Added lines #L148 - L158 were not covered by tests
} else {
//handle batch message
self.send_batch_message(
&channel,
&ctx,
request,
send_message_context,
request_header,
mapping_context,
execute_send_message_hook_after,
)
.await
Ok(self
.send_batch_message(
&channel,
&ctx,
request,
send_message_context,
request_header,
mapping_context,
execute_send_message_hook_after,
)
.await)

Check warning on line 171 in rocketmq-broker/src/processor/send_message_processor.rs

View check run for this annotation

Codecov / codecov/patch

rocketmq-broker/src/processor/send_message_processor.rs#L161-L171

Added lines #L161 - L171 were not covered by tests
}
}
}
Expand Down
Loading