From 668bed27348f65cf0020d31ab3cee8bdec363894 Mon Sep 17 00:00:00 2001 From: tison Date: Sun, 14 Apr 2024 17:34:24 +0800 Subject: [PATCH] Rollback impl AssertSend (#542) Signed-off-by: tison --- src/raft.rs | 4 +++- src/raft_log.rs | 18 ++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/raft.rs b/src/raft.rs index b63e3fd1..1eeacd9d 100644 --- a/src/raft.rs +++ b/src/raft.rs @@ -284,7 +284,9 @@ impl DerefMut for Raft { } } -impl Raft {} +#[allow(dead_code)] // ensure Raft is always Send +trait AssertSend: Send {} +impl AssertSend for Raft {} fn new_message(to: u64, field_type: MessageType, from: Option) -> Message { let mut m = Message::default(); diff --git a/src/raft_log.rs b/src/raft_log.rs index 5f437108..4a7c8b8d 100644 --- a/src/raft_log.rs +++ b/src/raft_log.rs @@ -15,9 +15,11 @@ // limitations under the License. use std::cmp; +use std::fmt::{Display, Formatter}; use slog::warn; use slog::Logger; +use slog::{debug, info, trace}; use crate::config::Config; use crate::eraftpb::{Entry, Snapshot}; @@ -25,11 +27,8 @@ use crate::errors::{Error, Result, StorageError}; use crate::log_unstable::Unstable; use crate::storage::{GetEntriesContext, GetEntriesFor, Storage}; use crate::util; - pub use crate::util::NO_LIMIT; -use slog::{debug, info, trace}; - /// Raft log implementation pub struct RaftLog { /// Contains all stable entries since the last snapshot. @@ -69,12 +68,10 @@ pub struct RaftLog { pub max_apply_unpersisted_log_limit: u64, } -impl ToString for RaftLog -where - T: Storage, -{ - fn to_string(&self) -> String { - format!( +impl Display for RaftLog { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!( + f, "committed={}, persisted={}, applied={}, unstable.offset={}, unstable.entries.len()={}", self.committed, self.persisted, @@ -728,6 +725,8 @@ mod test { panic::{self, AssertUnwindSafe}, }; + use protobuf::Message as PbMessage; + use crate::config::Config; use crate::default_logger; use crate::eraftpb; @@ -735,7 +734,6 @@ mod test { use crate::raft_log::{self, RaftLog}; use crate::storage::{GetEntriesContext, MemStorage}; use crate::NO_LIMIT; - use protobuf::Message as PbMessage; fn new_entry(index: u64, term: u64) -> eraftpb::Entry { let mut e = eraftpb::Entry::default();