From 4537c9959fa37db7430e8e85af9f9c2c0806253e Mon Sep 17 00:00:00 2001 From: lxl66566 Date: Thu, 11 Jul 2024 12:13:56 +0800 Subject: [PATCH] fix(client): remove redundant, add missing and other trivial change Signed-off-by: lxl66566 chore(curp): add a missing testcase to lib.rs Signed-off-by: lxl66566 chore(raw_curp): trivial change to functional expression Signed-off-by: lxl66566 --- crates/curp-test-utils/src/lib.rs | 10 +++++----- crates/curp/src/lib.rs | 1 + crates/curp/src/server/mod.rs | 1 - crates/curp/src/server/raw_curp/log.rs | 12 +++++++----- crates/xline-client/src/clients/kv.rs | 1 - crates/xline-client/src/clients/lease.rs | 1 - crates/xline/src/storage/alarm_store.rs | 1 - .../xline/src/storage/compact/periodic_compactor.rs | 6 +----- 8 files changed, 14 insertions(+), 19 deletions(-) diff --git a/crates/curp-test-utils/src/lib.rs b/crates/curp-test-utils/src/lib.rs index 52b62ff49..452b6ca2f 100644 --- a/crates/curp-test-utils/src/lib.rs +++ b/crates/curp-test-utils/src/lib.rs @@ -1,5 +1,4 @@ use std::{ - env, sync::{ atomic::{AtomicBool, Ordering}, Arc, @@ -50,13 +49,14 @@ impl TestRoleChangeInner { } pub fn init_logger() { - if env::var("RUST_LOG").is_err() { - env::set_var("RUST_LOG", "curp=debug,xline=debug"); - } _ = tracing_subscriber::fmt() .with_timer(uptime()) .compact() - .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) + .with_env_filter( + tracing_subscriber::EnvFilter::default() + .add_directive("curp=debug".parse().unwrap()) + .add_directive("xline=debug".parse().unwrap()), + ) .try_init(); } diff --git a/crates/curp/src/lib.rs b/crates/curp/src/lib.rs index e5e5111b6..b64a408bb 100644 --- a/crates/curp/src/lib.rs +++ b/crates/curp/src/lib.rs @@ -247,6 +247,7 @@ mod test { (3, 2, 4), (4, 3, 5), (4, 3, 6), + (6, 4, 8), ]; for (node_cnt, expected) in nodes.into_iter().zip(expected_res.into_iter()) { diff --git a/crates/curp/src/server/mod.rs b/crates/curp/src/server/mod.rs index 10e4b23f4..a1a734fc1 100644 --- a/crates/curp/src/server/mod.rs +++ b/crates/curp/src/server/mod.rs @@ -188,7 +188,6 @@ impl, RC: RoleChange> crate::rpc::Protocol fo } #[instrument(skip_all, name = "lease_keep_alive")] - #[allow(clippy::unimplemented)] async fn lease_keep_alive( &self, request: tonic::Request>, diff --git a/crates/curp/src/server/raw_curp/log.rs b/crates/curp/src/server/raw_curp/log.rs index 5d25e3f3b..472b1d90e 100644 --- a/crates/curp/src/server/raw_curp/log.rs +++ b/crates/curp/src/server/raw_curp/log.rs @@ -168,7 +168,7 @@ impl Log { } let end = self.li_to_pi(self.batch_end[self.first_idx_in_cur_batch - 1]); match end.cmp(&last_index) { - // All the `batch_end[i]` lager than `len - 1` should be reset to zero + // All the `batch_end[i]` larger than `len - 1` should be reset to zero Ordering::Greater => { self.batch_end[self.first_idx_in_cur_batch - 1] = 0; self.first_idx_in_cur_batch -= 1; @@ -197,10 +197,12 @@ impl Log { } // recalculate the `cur_batch_size` - self.cur_batch_size = 0; - for entry in self.entries.iter().skip(self.first_idx_in_cur_batch) { - self.cur_batch_size += entry.size; - } + self.cur_batch_size = self + .entries + .iter() + .skip(self.first_idx_in_cur_batch) + .map(|entry| entry.size) + .sum(); } /// push a log entry into the back of queue diff --git a/crates/xline-client/src/clients/kv.rs b/crates/xline-client/src/clients/kv.rs index c78e49cba..5da44fd57 100644 --- a/crates/xline-client/src/clients/kv.rs +++ b/crates/xline-client/src/clients/kv.rs @@ -31,7 +31,6 @@ impl Debug for KvClient { #[inline] fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("KvClient") - .field("kv_client", &self.kv_client) .field("kv_client", &self.kv_client) .field("token", &self.token) .finish() diff --git a/crates/xline-client/src/clients/lease.rs b/crates/xline-client/src/clients/lease.rs index 42b7a1e18..06a17b492 100644 --- a/crates/xline-client/src/clients/lease.rs +++ b/crates/xline-client/src/clients/lease.rs @@ -35,7 +35,6 @@ impl Debug for LeaseClient { #[inline] fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("LeaseClient") - .field("lease_client", &self.lease_client) .field("lease_client", &self.lease_client) .field("token", &self.token) .field("id_gen", &self.id_gen) diff --git a/crates/xline/src/storage/alarm_store.rs b/crates/xline/src/storage/alarm_store.rs index 7483f249b..bc739b94d 100644 --- a/crates/xline/src/storage/alarm_store.rs +++ b/crates/xline/src/storage/alarm_store.rs @@ -170,7 +170,6 @@ impl AlarmStore { /// Handle alarm activate request fn handle_alarm_activate(&self, member_id: ServerId, alarm: AlarmType) -> Vec { - let new_alarm = AlarmMember::new(member_id, alarm); self.types .read() .get(&alarm) diff --git a/crates/xline/src/storage/compact/periodic_compactor.rs b/crates/xline/src/storage/compact/periodic_compactor.rs index 1dd502c84..a88859e0a 100644 --- a/crates/xline/src/storage/compact/periodic_compactor.rs +++ b/crates/xline/src/storage/compact/periodic_compactor.rs @@ -1,5 +1,4 @@ use std::{ - cmp::Ordering, sync::{ atomic::{AtomicBool, Ordering::Relaxed}, Arc, @@ -133,10 +132,7 @@ impl PeriodicCompactor { fn sample_config(period: Duration) -> (Duration, usize) { /// one hour duration const ONEHOUR: Duration = Duration::from_secs(3600); - let base_interval = match period.cmp(&ONEHOUR) { - Ordering::Less => period, - Ordering::Equal | Ordering::Greater => ONEHOUR, - }; + let base_interval = period.min(ONEHOUR); let divisor = 10; let check_interval = base_interval .checked_div(divisor)