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

chore(deps): bump clippy-utilities from 0.1.0 to 0.2.0 #721

Merged
merged 1 commit into from
Mar 25, 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
20 changes: 7 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions crates/curp/src/client/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ use std::{sync::Arc, time::Duration};
use futures::Future;
use tracing::{debug, warn};

use crate::rpc::{connect::ConnectApi, CurpError, Redirect};

use super::state::State;
use crate::rpc::{connect::ConnectApi, CurpError, Redirect};

/// Stream client config
#[derive(Debug)]
Expand Down
2 changes: 1 addition & 1 deletion crates/xline-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ keywords = ["Client", "Xline", "RPC"]

[dependencies]
anyhow = "1.0.81"
clippy-utilities = "0.1.0"
clippy-utilities = "0.2.0"
curp = { path = "../curp" }
futures = "0.3.25"
getrandom = "0.2"
Expand Down
4 changes: 2 additions & 2 deletions crates/xline-client/src/lease_gen.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::sync::atomic::{AtomicU64, Ordering};

use clippy_utilities::Cast;
use clippy_utilities::NumericCast;

/// Generator of unique lease id
/// Note that this Lease Id generation method may cause collisions,
Expand Down Expand Up @@ -37,7 +37,7 @@ impl LeaseIdGenerator {
return self.next();
}
// set the highest bit to 0 as we need only need positive values
(id & 0x7fff_ffff_ffff_ffff).cast()
(id & 0x7fff_ffff_ffff_ffff).numeric_cast()
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/xline/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async-trait = "0.1.53"
axum = "0.6.20"
bytes = "1.4.0"
clap = { version = "4", features = ["derive"] }
clippy-utilities = "0.1.0"
clippy-utilities = "0.2.0"
crc32fast = "1.3.2"
crossbeam-skiplist = "0.1.1"
curp = { path = "../curp", version = "0.1.0", features = ["client-metrics"] }
Expand Down
6 changes: 3 additions & 3 deletions crates/xline/src/id_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
time::{SystemTime, UNIX_EPOCH},
};

use clippy_utilities::{Cast, OverflowArithmetic};
use clippy_utilities::{NumericCast, OverflowArithmetic};
use curp::members::ServerId;

/// Generator of unique id
Expand All @@ -30,15 +30,15 @@ impl IdGenerator {
.as_millis();
ts &= (u128::MAX.overflowing_shr(88).0); // lower 40 bits (128 - 40)
ts = ts.overflowing_shl(8).0; // shift left 8 bits
let suffix = AtomicU64::new(ts.cast());
let suffix = AtomicU64::new(ts.numeric_cast());
Self { prefix, suffix }
}

/// Generate next id
pub(crate) fn next(&self) -> i64 {
let suffix = self.suffix.fetch_add(1, Ordering::Relaxed);
let id = self.prefix | suffix;
(id & 0x7fff_ffff_ffff_ffff).cast()
(id & 0x7fff_ffff_ffff_ffff).numeric_cast()
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/xline/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use clippy_utilities::Cast;
use clippy_utilities::NumericCast;
use opentelemetry::{
metrics::{Counter, MetricsError},
KeyValue,
Expand Down Expand Up @@ -68,7 +68,7 @@ impl Metrics {
}

if let Some(limit) = limit {
observer.observe_u64(&fd_limit, limit.cast(), &[]);
observer.observe_u64(&fd_limit, limit.numeric_cast(), &[]);
}
})?;

Expand Down
4 changes: 2 additions & 2 deletions crates/xline/src/restore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::path::{Path, PathBuf};

use anyhow::Result;
use bytes::BytesMut;
use clippy_utilities::Cast;
use clippy_utilities::NumericCast;
use engine::{Engine, EngineType, Snapshot, SnapshotApi, StorageEngine};
use tokio_util::io::read_buf;
use utils::table_names::XLINE_TABLES;
Expand All @@ -22,7 +22,7 @@ pub async fn restore<P: AsRef<Path>, D: Into<PathBuf>>(
let mut snapshot_f = tokio::fs::File::open(snapshot_path).await?;
let tmp_path = format!("/tmp/snapshot-{}", uuid::Uuid::new_v4());
let mut rocks_snapshot = Snapshot::new_for_receiving(EngineType::Rocks((&tmp_path).into()))?;
let mut buf = BytesMut::with_capacity(MAINTENANCE_SNAPSHOT_CHUNK_SIZE.cast());
let mut buf = BytesMut::with_capacity(MAINTENANCE_SNAPSHOT_CHUNK_SIZE.numeric_cast());
while let Ok(n) = read_buf(&mut snapshot_f, &mut buf).await {
if n == 0 {
break;
Expand Down
4 changes: 2 additions & 2 deletions crates/xline/src/server/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ where

/// functions used to estimate request write size
mod size_estimate {
use clippy_utilities::{Cast, OverflowArithmetic};
use clippy_utilities::{NumericCast, OverflowArithmetic};
use xlineapi::{PutRequest, Request, RequestWrapper, TxnRequest};

/// Estimate the put size
Expand All @@ -118,7 +118,7 @@ mod size_estimate {
let kv_size = req.key.len().overflow_add(req.value.len()).overflow_add(32); // size of `KeyValue` struct
1010 // padding(1008) + cf_handle(2)
.overflow_add(rev_size.overflow_mul(2))
.overflow_add(kv_size.cast())
.overflow_add(kv_size.numeric_cast())
}

/// Estimate the txn size
Expand Down
6 changes: 3 additions & 3 deletions crates/xline/src/server/lease_server.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{pin::Pin, sync::Arc, time::Duration};

use async_stream::{stream, try_stream};
use clippy_utilities::Cast;
use clippy_utilities::NumericCast;
use curp::members::ClusterInfo;
use futures::stream::Stream;
use tokio::time;
Expand Down Expand Up @@ -369,8 +369,8 @@ where
let res = LeaseTimeToLiveResponse {
header: Some(self.lease_storage.gen_header()),
id: time_to_live_req.id,
ttl: lease.remaining().as_secs().cast(),
granted_ttl: lease.ttl().as_secs().cast(),
ttl: lease.remaining().as_secs().numeric_cast(),
granted_ttl: lease.ttl().as_secs().numeric_cast(),
keys,
};
return Ok(tonic::Response::new(res));
Expand Down
14 changes: 7 additions & 7 deletions crates/xline/src/server/maintenance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{fmt::Debug, pin::Pin, sync::Arc};

use async_stream::try_stream;
use bytes::BytesMut;
use clippy_utilities::{Cast, OverflowArithmetic};
use clippy_utilities::{NumericCast, OverflowArithmetic};
use curp::{cmd::CommandExecutor as _, members::ClusterInfo, server::RawCurp};
use engine::SnapshotApi;
use futures::stream::Stream;
Expand Down Expand Up @@ -150,13 +150,13 @@ where
let response = StatusResponse {
header: Some(self.header_gen.gen_header()),
version: env!("CARGO_PKG_VERSION").to_owned(),
db_size: size.cast(),
db_size: size.numeric_cast(),
leader: leader.unwrap_or(0), // None means this member believes there is no leader
raft_index: commit_index,
raft_term: term,
raft_applied_index: last_applied,
errors,
db_size_in_use: size.cast(),
db_size_in_use: size.numeric_cast(),
is_learner,
};
Ok(tonic::Response::new(response))
Expand Down Expand Up @@ -251,15 +251,15 @@ fn snapshot_stream<S: StorageApi>(
let mut checksum_gen = Sha256::new();
while remain_size > 0 {
let buf_size = std::cmp::min(MAINTENANCE_SNAPSHOT_CHUNK_SIZE, remain_size);
let mut buf = BytesMut::with_capacity(buf_size.cast());
let mut buf = BytesMut::with_capacity(buf_size.numeric_cast());
remain_size = remain_size.overflow_sub(buf_size);
snapshot.read_buf_exact(&mut buf).await.map_err(|_e| {tonic::Status::internal("snapshot read failed")})?;
// etcd client will use the size of the snapshot to determine whether checksum is included,
// and the check method size % 512 == sha256.size, So we need to pad snapshots to multiples
// of 512 bytes
let padding = MIN_PAGE_SIZE.overflow_sub(buf_size.overflow_rem(MIN_PAGE_SIZE));
if padding != 0 {
buf.extend_from_slice(&vec![0; padding.cast()]);
buf.extend_from_slice(&vec![0; padding.numeric_cast()]);
}
checksum_gen.update(&buf);
yield SnapshotResponse {
Expand Down Expand Up @@ -309,12 +309,12 @@ mod test {
recv_data.append(&mut data?.blob);
}
assert_eq!(
recv_data.len() % MIN_PAGE_SIZE.cast::<usize>(),
recv_data.len() % MIN_PAGE_SIZE.numeric_cast::<usize>(),
Sha256::output_size()
);

let mut snap2 = persistent.get_snapshot(snapshot_path).unwrap();
let size = snap2.size().cast();
let size = snap2.size().numeric_cast();
let mut snap2_data = BytesMut::with_capacity(size);
snap2.read_buf_exact(&mut snap2_data).await.unwrap();
let snap1_data = recv_data[..size].to_vec();
Expand Down
8 changes: 4 additions & 4 deletions crates/xline/src/server/xline_server.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{sync::Arc, time::Duration};

use anyhow::{anyhow, Result};
use clippy_utilities::{Cast, OverflowArithmetic};
use clippy_utilities::{NumericCast, OverflowArithmetic};
use curp::{
client::ClientBuilder as CurpClientBuilder,
members::{get_cluster_info_from_remote, ClusterInfo},
Expand Down Expand Up @@ -187,12 +187,12 @@ impl XlineServer {
heartbeat_interval: Duration,
candidate_timeout_ticks: u8,
) -> Arc<LeaseCollection> {
let min_ttl = 3 * heartbeat_interval * candidate_timeout_ticks.cast() / 2;
let min_ttl = 3 * heartbeat_interval * candidate_timeout_ticks.numeric_cast() / 2;
// Safe ceiling
let min_ttl_secs = min_ttl
.as_secs()
.overflow_add((min_ttl.subsec_nanos() > 0).cast());
Arc::new(LeaseCollection::new(min_ttl_secs.cast()))
.overflow_add(u64::from(min_ttl.subsec_nanos() > 0));
Arc::new(LeaseCollection::new(min_ttl_secs.numeric_cast()))
}

/// Construct underlying storages, including `KvStore`, `LeaseStore`, `AuthStore`
Expand Down
4 changes: 2 additions & 2 deletions crates/xline/src/storage/auth_store/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{
},
};

use clippy_utilities::Cast;
use clippy_utilities::NumericCast;
use itertools::Itertools;
use jsonwebtoken::{DecodingKey, EncodingKey};
use log::debug;
Expand Down Expand Up @@ -294,7 +294,7 @@ where
debug!("handle_auth_status");
AuthStatusResponse {
header: Some(self.header_gen.gen_auth_header()),
auth_revision: self.revision().cast(),
auth_revision: self.revision().numeric_cast(),
enabled: self.is_enabled(),
}
}
Expand Down
14 changes: 7 additions & 7 deletions crates/xline/src/storage/kv_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{
},
};

use clippy_utilities::{Cast, OverflowArithmetic};
use clippy_utilities::{NumericCast, OverflowArithmetic};
use prost::Message;
use tokio::sync::mpsc;
use tracing::{debug, warn};
Expand Down Expand Up @@ -585,12 +585,12 @@ where
&req.key,
&req.range_end,
req.revision,
storage_fetch_limit.cast(),
storage_fetch_limit.numeric_cast(),
req.count_only,
)?;
let mut response = RangeResponse {
header: Some(self.header_gen.gen_header()),
count: total.cast(),
count: total.numeric_cast(),
..RangeResponse::default()
};
if kvs.is_empty() {
Expand All @@ -606,9 +606,9 @@ where
);
Self::sort_kvs(&mut kvs, req.sort_order(), req.sort_target());

if (req.limit > 0) && (kvs.len() > req.limit.cast()) {
if (req.limit > 0) && (kvs.len() > req.limit.numeric_cast()) {
response.more = true;
kvs.truncate(req.limit.cast());
kvs.truncate(req.limit.numeric_cast());
}
if req.keys_only {
kvs.iter_mut().for_each(|kv| kv.value.clear());
Expand Down Expand Up @@ -648,7 +648,7 @@ where
header: Some(self.header_gen.gen_header()),
..DeleteRangeResponse::default()
};
response.deleted = prev_kvs.len().cast();
response.deleted = prev_kvs.len().numeric_cast();
if req.prev_kv {
response.prev_kvs = prev_kvs;
}
Expand Down Expand Up @@ -782,7 +782,7 @@ where
continue;
}
};
sub_revision = sub_revision.overflow_add(events.len().cast());
sub_revision = sub_revision.overflow_add(events.len().numeric_cast());
all_events.append(&mut events);
all_ops.append(&mut ops);
}
Expand Down
Loading
Loading