Skip to content

Commit

Permalink
Chore: remove MessageSummary for RaftMsg, use Display instaed
Browse files Browse the repository at this point in the history
  • Loading branch information
drmingdrmer committed Mar 30, 2024
1 parent cfd0c6b commit 817feeb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion openraft/src/core/raft_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,7 @@ where
// TODO: Make this method non-async. It does not need to run any async command in it.
#[tracing::instrument(level = "debug", skip(self, msg), fields(state = debug(self.engine.state.server_state), id=display(self.id)))]
pub(crate) async fn handle_api_msg(&mut self, msg: RaftMsg<C>) {
tracing::debug!("recv from rx_api: {}", msg.summary());
tracing::debug!("recv from rx_api: {}", msg);

match msg {
RaftMsg::AppendEntries { rpc, tx } => {
Expand Down
36 changes: 19 additions & 17 deletions openraft/src/core/raft_msg/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::collections::BTreeMap;
use std::fmt;

use crate::core::raft_msg::external_command::ExternalCommand;
use crate::error::CheckIsLeaderError;
Expand Down Expand Up @@ -103,36 +104,37 @@ where C: RaftTypeConfig
},
}

impl<C> MessageSummary<RaftMsg<C>> for RaftMsg<C>
impl<C> fmt::Display for RaftMsg<C>
where C: RaftTypeConfig
{
fn summary(&self) -> String {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
RaftMsg::AppendEntries { rpc, .. } => {
format!("AppendEntries: {}", rpc.summary())
// TODO: avoid using summary()
write!(f, "AppendEntries: {}", rpc.summary())
}
RaftMsg::RequestVote { rpc, .. } => {
format!("RequestVote: {}", rpc.summary())
write!(f, "RequestVote: {}", rpc)
}
RaftMsg::BeginReceivingSnapshot { .. } => {
write!(f, "BeginReceivingSnapshot")
}
RaftMsg::BeginReceivingSnapshot { .. } => "BeginReceivingSnapshot".to_string(),
RaftMsg::InstallFullSnapshot { vote, snapshot, .. } => {
format!("InstallFullSnapshot: vote: {}, snapshot: {}", vote, snapshot)
write!(f, "InstallFullSnapshot: vote: {}, snapshot: {}", vote, snapshot)
}
RaftMsg::ClientWriteRequest { .. } => "ClientWriteRequest".to_string(),
RaftMsg::CheckIsLeaderRequest { .. } => "CheckIsLeaderRequest".to_string(),
RaftMsg::ClientWriteRequest { .. } => write!(f, "ClientWriteRequest"),
RaftMsg::CheckIsLeaderRequest { .. } => write!(f, "CheckIsLeaderRequest"),
RaftMsg::Initialize { members, .. } => {
format!("Initialize: {:?}", members)
// TODO: avoid using Debug
write!(f, "Initialize: {:?}", members)
}
RaftMsg::ChangeMembership {
changes: members,
retain,
..
} => {
format!("ChangeMembership: members: {:?}, retain: {}", members, retain,)
RaftMsg::ChangeMembership { changes, retain, .. } => {
// TODO: avoid using Debug
write!(f, "ChangeMembership: members: {:?}, retain: {}", changes, retain,)
}
RaftMsg::ExternalCoreRequest { .. } => "External Request".to_string(),
RaftMsg::ExternalCoreRequest { .. } => write!(f, "External Request"),
RaftMsg::ExternalCommand { cmd } => {
format!("ExternalCommand: {:?}", cmd)
write!(f, "ExternalCommand: {}", cmd)
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions openraft/src/raft/raft_inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use crate::type_config::alias::OneshotReceiverOf;
use crate::type_config::alias::OneshotSenderOf;
use crate::AsyncRuntime;
use crate::Config;
use crate::MessageSummary;
use crate::OptionalSend;
use crate::RaftMetrics;
use crate::RaftTypeConfig;
Expand Down Expand Up @@ -63,7 +62,7 @@ where C: RaftTypeConfig
T: OptionalSend,
{
let sum = if tracing::enabled!(Level::DEBUG) {
Some(mes.summary())
Some(mes.to_string())
} else {
None
};
Expand Down

0 comments on commit 817feeb

Please sign in to comment.