aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex <alex@adnab.me>2023-01-26 21:10:21 +0000
committerAlex <alex@adnab.me>2023-01-26 21:10:21 +0000
commitf2c256cac4e599335d592dd580011cf15f278a51 (patch)
tree8a7e90cf4bcf40ef7513e9ffaa636a012ebcc4a9
parenta08e01f17a9e4bb80880e28a4a28b2d88a9aec83 (diff)
parentd6af95d20520eec64e5e4c0c873c6e3a8ac1509d (diff)
downloadgarage-f2c256cac4e599335d592dd580011cf15f278a51.tar.gz
garage-f2c256cac4e599335d592dd580011cf15f278a51.zip
Merge pull request 'Many clippy lints fixed' (#488) from k2v-watch-range-2 into main
Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/garage/pulls/488
-rw-r--r--src/api/admin/api_server.rs2
-rw-r--r--src/api/admin/bucket.rs4
-rw-r--r--src/api/s3/bucket.rs2
-rw-r--r--src/api/s3/post_object.rs2
-rw-r--r--src/block/metrics.rs2
-rw-r--r--src/block/rc.rs14
-rw-r--r--src/block/repair.rs4
-rw-r--r--src/garage/cli/cmd.rs2
-rw-r--r--src/garage/cli/init.rs4
-rw-r--r--src/garage/cli/util.rs2
-rw-r--r--src/garage/tests/k2v/poll.rs7
-rw-r--r--src/garage/tests/s3/website.rs6
-rw-r--r--src/model/garage.rs2
-rw-r--r--src/model/k2v/item_table.rs3
-rw-r--r--src/model/k2v/rpc.rs6
-rw-r--r--src/model/k2v/seen.rs8
-rw-r--r--src/model/s3/object_table.rs1
-rw-r--r--src/rpc/consul.rs2
-rw-r--r--src/rpc/system.rs4
19 files changed, 40 insertions, 37 deletions
diff --git a/src/api/admin/api_server.rs b/src/api/admin/api_server.rs
index 7a534f32..a115d732 100644
--- a/src/api/admin/api_server.rs
+++ b/src/api/admin/api_server.rs
@@ -103,7 +103,7 @@ impl AdminApiServer {
.bucket_helper()
.resolve_global_bucket_name(&domain_string)
.await?
- .ok_or_else(|| HelperError::NoSuchBucket(domain_string))?;
+ .ok_or(HelperError::NoSuchBucket(domain_string))?;
let bucket = self
.garage
diff --git a/src/api/admin/bucket.rs b/src/api/admin/bucket.rs
index 65034852..e60f07ca 100644
--- a/src/api/admin/bucket.rs
+++ b/src/api/admin/bucket.rs
@@ -167,7 +167,7 @@ async fn bucket_info_results(
let quotas = state.quotas.get();
let res =
GetBucketInfoResult {
- id: hex::encode(&bucket.id),
+ id: hex::encode(bucket.id),
global_aliases: state
.aliases
.items()
@@ -575,6 +575,6 @@ pub async fn handle_local_unalias_bucket(
// ---- HELPER ----
fn parse_bucket_id(id: &str) -> Result<Uuid, Error> {
- let id_hex = hex::decode(&id).ok_or_bad_request("Invalid bucket id")?;
+ let id_hex = hex::decode(id).ok_or_bad_request("Invalid bucket id")?;
Ok(Uuid::try_from(&id_hex).ok_or_bad_request("Invalid bucket id")?)
}
diff --git a/src/api/s3/bucket.rs b/src/api/s3/bucket.rs
index 8471385f..733981e1 100644
--- a/src/api/s3/bucket.rs
+++ b/src/api/s3/bucket.rs
@@ -305,7 +305,7 @@ fn parse_create_bucket_xml(xml_bytes: &[u8]) -> Option<Option<String>> {
let mut ret = None;
for item in cbc.children() {
if item.has_tag_name("LocationConstraint") {
- if ret != None {
+ if ret.is_some() {
return None;
}
ret = Some(item.text()?.to_string());
diff --git a/src/api/s3/post_object.rs b/src/api/s3/post_object.rs
index da542526..f2098ab0 100644
--- a/src/api/s3/post_object.rs
+++ b/src/api/s3/post_object.rs
@@ -140,7 +140,7 @@ pub async fn handle_post_object(
.await?;
let decoded_policy = BASE64_STANDARD
- .decode(&policy)
+ .decode(policy)
.ok_or_bad_request("Invalid policy")?;
let decoded_policy: Policy =
serde_json::from_slice(&decoded_policy).ok_or_bad_request("Invalid policy")?;
diff --git a/src/block/metrics.rs b/src/block/metrics.rs
index 500022fc..6659df32 100644
--- a/src/block/metrics.rs
+++ b/src/block/metrics.rs
@@ -38,7 +38,7 @@ impl BlockManagerMetrics {
.u64_value_observer("block.compression_level", move |observer| {
match compression_level {
Some(v) => observer.observe(v as u64, &[]),
- None => observer.observe(0 as u64, &[]),
+ None => observer.observe(0_u64, &[]),
}
})
.with_description("Garage compression level for node")
diff --git a/src/block/rc.rs b/src/block/rc.rs
index 8dae3960..94cb5eea 100644
--- a/src/block/rc.rs
+++ b/src/block/rc.rs
@@ -24,9 +24,9 @@ impl BlockRc {
tx: &mut db::Transaction,
hash: &Hash,
) -> db::TxOpResult<bool> {
- let old_rc = RcEntry::parse_opt(tx.get(&self.rc, &hash)?);
+ let old_rc = RcEntry::parse_opt(tx.get(&self.rc, hash)?);
match old_rc.increment().serialize() {
- Some(x) => tx.insert(&self.rc, &hash, x)?,
+ Some(x) => tx.insert(&self.rc, hash, x)?,
None => unreachable!(),
};
Ok(old_rc.is_zero())
@@ -39,10 +39,10 @@ impl BlockRc {
tx: &mut db::Transaction,
hash: &Hash,
) -> db::TxOpResult<bool> {
- let new_rc = RcEntry::parse_opt(tx.get(&self.rc, &hash)?).decrement();
+ let new_rc = RcEntry::parse_opt(tx.get(&self.rc, hash)?).decrement();
match new_rc.serialize() {
- Some(x) => tx.insert(&self.rc, &hash, x)?,
- None => tx.remove(&self.rc, &hash)?,
+ Some(x) => tx.insert(&self.rc, hash, x)?,
+ None => tx.remove(&self.rc, hash)?,
};
Ok(matches!(new_rc, RcEntry::Deletable { .. }))
}
@@ -57,10 +57,10 @@ impl BlockRc {
pub(crate) fn clear_deleted_block_rc(&self, hash: &Hash) -> Result<(), Error> {
let now = now_msec();
self.rc.db().transaction(|mut tx| {
- let rcval = RcEntry::parse_opt(tx.get(&self.rc, &hash)?);
+ let rcval = RcEntry::parse_opt(tx.get(&self.rc, hash)?);
match rcval {
RcEntry::Deletable { at_time } if now > at_time => {
- tx.remove(&self.rc, &hash)?;
+ tx.remove(&self.rc, hash)?;
}
_ => (),
};
diff --git a/src/block/repair.rs b/src/block/repair.rs
index 064cc005..d4593dbf 100644
--- a/src/block/repair.rs
+++ b/src/block/repair.rs
@@ -466,11 +466,11 @@ impl BlockStoreIterator {
let ent_type = data_dir_ent.file_type().await?;
let name = name.strip_suffix(".zst").unwrap_or(&name);
- if name.len() == 2 && hex::decode(&name).is_ok() && ent_type.is_dir() {
+ if name.len() == 2 && hex::decode(name).is_ok() && ent_type.is_dir() {
let path = data_dir_ent.path();
self.path.push(ReadingDir::Pending(path));
} else if name.len() == 64 {
- if let Ok(h) = hex::decode(&name) {
+ if let Ok(h) = hex::decode(name) {
let mut hash = [0u8; 32];
hash.copy_from_slice(&h);
return Ok(Some(hash.into()));
diff --git a/src/garage/cli/cmd.rs b/src/garage/cli/cmd.rs
index af7f1aa1..0d735885 100644
--- a/src/garage/cli/cmd.rs
+++ b/src/garage/cli/cmd.rs
@@ -60,7 +60,7 @@ pub async fn cmd_status(rpc_cli: &Endpoint<SystemRpc, ()>, rpc_host: NodeID) ->
println!("==== HEALTHY NODES ====");
let mut healthy_nodes =
- vec!["ID\tHostname\tAddress\tTags\tZone\tCapacity\tDataAvail\tMetaAvail".to_string()];
+ vec!["ID\tHostname\tAddress\tTags\tZone\tCapacity\tDataAvail".to_string()];
for adv in status.iter().filter(|adv| adv.is_up) {
match layout.roles.get(&adv.id) {
Some(NodeRoleV(Some(cfg))) => {
diff --git a/src/garage/cli/init.rs b/src/garage/cli/init.rs
index 511b53a6..20813f1c 100644
--- a/src/garage/cli/init.rs
+++ b/src/garage/cli/init.rs
@@ -14,11 +14,11 @@ pub fn node_id_command(config_file: PathBuf, quiet: bool) -> Result<(), Error> {
garage_rpc::system::read_node_id(&config.metadata_dir).err_context(READ_KEY_ERROR)?;
let idstr = if let Some(addr) = config.rpc_public_addr {
- let idstr = format!("{}@{}", hex::encode(&node_id), addr);
+ let idstr = format!("{}@{}", hex::encode(node_id), addr);
println!("{}", idstr);
idstr
} else {
- let idstr = hex::encode(&node_id);
+ let idstr = hex::encode(node_id);
println!("{}", idstr);
if !quiet {
diff --git a/src/garage/cli/util.rs b/src/garage/cli/util.rs
index 230ce3de..2c6be2f4 100644
--- a/src/garage/cli/util.rs
+++ b/src/garage/cli/util.rs
@@ -229,7 +229,7 @@ pub fn find_matching_node(
) -> Result<Uuid, Error> {
let mut candidates = vec![];
for c in cand {
- if hex::encode(&c).starts_with(&pattern) && !candidates.contains(&c) {
+ if hex::encode(c).starts_with(pattern) && !candidates.contains(&c) {
candidates.push(c);
}
}
diff --git a/src/garage/tests/k2v/poll.rs b/src/garage/tests/k2v/poll.rs
index f54cc5d4..5280255a 100644
--- a/src/garage/tests/k2v/poll.rs
+++ b/src/garage/tests/k2v/poll.rs
@@ -1,3 +1,4 @@
+use base64::prelude::*;
use hyper::{Method, StatusCode};
use std::time::Duration;
@@ -160,7 +161,7 @@ async fn test_poll_range() {
json!(
{
"items": [
- {"sk": "test1", "ct": ct, "v": [base64::encode(b"Initial value")]},
+ {"sk": "test1", "ct": ct, "v": [BASE64_STANDARD.encode(b"Initial value")]},
],
"seenMarker": seen_marker,
}
@@ -212,7 +213,7 @@ async fn test_poll_range() {
assert_json_eq!(&json_res["items"][0]["sk"], json!("test1"));
assert_json_eq!(
&json_res["items"][0]["v"],
- json!([base64::encode(b"New value")])
+ json!([BASE64_STANDARD.encode(b"New value")])
);
// Now we will add a value on a different key
@@ -259,6 +260,6 @@ async fn test_poll_range() {
assert_json_eq!(&json_res["items"][0]["sk"], json!("test2"));
assert_json_eq!(
&json_res["items"][0]["v"],
- json!([base64::encode(b"Other value")])
+ json!([BASE64_STANDARD.encode(b"Other value")])
);
}
diff --git a/src/garage/tests/s3/website.rs b/src/garage/tests/s3/website.rs
index f57e31ee..4e136e1b 100644
--- a/src/garage/tests/s3/website.rs
+++ b/src/garage/tests/s3/website.rs
@@ -57,7 +57,7 @@ async fn test_website() {
Request::builder()
.method("GET")
.uri(format!("http://127.0.0.1:{}/check", ctx.garage.admin_port))
- .header("domain", format!("{}", BCKT_NAME))
+ .header("domain", BCKT_NAME.to_string())
.body(Body::empty())
.unwrap()
};
@@ -92,7 +92,7 @@ async fn test_website() {
Request::builder()
.method("GET")
.uri(format!("http://127.0.0.1:{}/check", ctx.garage.admin_port))
- .header("domain", format!("{}", BCKT_NAME))
+ .header("domain", BCKT_NAME.to_string())
.body(Body::empty())
.unwrap()
};
@@ -121,7 +121,7 @@ async fn test_website() {
Request::builder()
.method("GET")
.uri(format!("http://127.0.0.1:{}/check", ctx.garage.admin_port))
- .header("domain", format!("{}", BCKT_NAME))
+ .header("domain", BCKT_NAME.to_string())
.body(Body::empty())
.unwrap()
};
diff --git a/src/model/garage.rs b/src/model/garage.rs
index 4716954a..92cab17c 100644
--- a/src/model/garage.rs
+++ b/src/model/garage.rs
@@ -159,7 +159,7 @@ impl Garage {
};
let network_key = NetworkKey::from_slice(
- &hex::decode(&config.rpc_secret.as_ref().unwrap()).expect("Invalid RPC secret key")[..],
+ &hex::decode(config.rpc_secret.as_ref().unwrap()).expect("Invalid RPC secret key")[..],
)
.expect("Invalid RPC secret key");
diff --git a/src/model/k2v/item_table.rs b/src/model/k2v/item_table.rs
index 28646f37..84c05db5 100644
--- a/src/model/k2v/item_table.rs
+++ b/src/model/k2v/item_table.rs
@@ -269,6 +269,7 @@ impl CountedItem for K2VItem {
&self.partition.partition_key
}
+ #[allow(clippy::bool_to_int_with_if)]
fn counts(&self) -> Vec<(&'static str, i64)> {
let values = self.values();
@@ -313,7 +314,7 @@ mod tests {
values: vec![(6, DvvsValue::Value(vec![16])), (7, DvvsValue::Deleted)],
};
- let mut e3 = e1.clone();
+ let mut e3 = e1;
e3.merge(&e2);
assert_eq!(e2, e3);
}
diff --git a/src/model/k2v/rpc.rs b/src/model/k2v/rpc.rs
index 117103b6..37e142f6 100644
--- a/src/model/k2v/rpc.rs
+++ b/src/model/k2v/rpc.rs
@@ -37,7 +37,7 @@ use crate::k2v::sub::*;
const POLL_RANGE_EXTRA_DELAY: Duration = Duration::from_millis(200);
-const TIMESTAMP_KEY: &'static [u8] = b"timestamp";
+const TIMESTAMP_KEY: &[u8] = b"timestamp";
/// RPC messages for K2V
#[derive(Debug, Serialize, Deserialize)]
@@ -418,7 +418,7 @@ impl K2VRpcHandler {
.data
.update_entry_with(&item.partition, &item.sort_key, |tx, ent| {
let old_local_timestamp = tx
- .get(&local_timestamp_tree, TIMESTAMP_KEY)?
+ .get(local_timestamp_tree, TIMESTAMP_KEY)?
.and_then(|x| x.try_into().ok())
.map(u64::from_be_bytes)
.unwrap_or_default();
@@ -438,7 +438,7 @@ impl K2VRpcHandler {
);
tx.insert(
- &local_timestamp_tree,
+ local_timestamp_tree,
TIMESTAMP_KEY,
u64::to_be_bytes(new_local_timestamp),
)?;
diff --git a/src/model/k2v/seen.rs b/src/model/k2v/seen.rs
index 51098710..8fe3a582 100644
--- a/src/model/k2v/seen.rs
+++ b/src/model/k2v/seen.rs
@@ -63,7 +63,7 @@ impl RangeSeenMarker {
None => {
self.items.insert(item.sort_key.clone(), cc.vector_clock);
}
- Some(ent) => *ent = vclock_max(&ent, &cc.vector_clock),
+ Some(ent) => *ent = vclock_max(ent, &cc.vector_clock),
}
}
}
@@ -71,7 +71,7 @@ impl RangeSeenMarker {
pub fn canonicalize(&mut self) {
let self_vc = &self.vector_clock;
- self.items.retain(|_sk, vc| vclock_gt(&vc, self_vc))
+ self.items.retain(|_sk, vc| vclock_gt(vc, self_vc))
}
pub fn encode(&mut self) -> Result<String, Error> {
@@ -84,7 +84,7 @@ impl RangeSeenMarker {
/// Decode from msgpack+zstd+b64 representation, returns None on error.
pub fn decode(s: &str) -> Option<Self> {
- let bytes = BASE64_STANDARD.decode(&s).ok()?;
+ let bytes = BASE64_STANDARD.decode(s).ok()?;
let bytes = zstd::stream::decode_all(&mut &bytes[..]).ok()?;
nonversioned_decode(&bytes).ok()
}
@@ -99,7 +99,7 @@ impl RangeSeenMarker {
&& self
.items
.get(&item.sort_key)
- .map(|vc| vclock_gt(&cc.vector_clock, &vc))
+ .map(|vc| vclock_gt(&cc.vector_clock, vc))
.unwrap_or(true)
}
}
diff --git a/src/model/s3/object_table.rs b/src/model/s3/object_table.rs
index 518acc95..29614dc5 100644
--- a/src/model/s3/object_table.rs
+++ b/src/model/s3/object_table.rs
@@ -355,6 +355,7 @@ impl CountedItem for Object {
fn counts(&self) -> Vec<(&'static str, i64)> {
let versions = self.versions();
+ #[allow(clippy::bool_to_int_with_if)]
let n_objects = if versions.iter().any(|v| v.is_data()) {
1
} else {
diff --git a/src/rpc/consul.rs b/src/rpc/consul.rs
index b1772a1a..f85f789c 100644
--- a/src/rpc/consul.rs
+++ b/src/rpc/consul.rs
@@ -113,7 +113,7 @@ impl ConsulDiscovery {
let pubkey = ent
.node_meta
.get("pubkey")
- .and_then(|k| hex::decode(&k).ok())
+ .and_then(|k| hex::decode(k).ok())
.and_then(|k| NodeID::from_slice(&k[..]));
if let (Some(ip), Some(pubkey)) = (ip, pubkey) {
ret.push((pubkey, SocketAddr::new(ip, ent.service_port)));
diff --git a/src/rpc/system.rs b/src/rpc/system.rs
index e0ced8cc..b42e49fc 100644
--- a/src/rpc/system.rs
+++ b/src/rpc/system.rs
@@ -215,7 +215,7 @@ pub fn gen_node_key(metadata_dir: &Path) -> Result<NodeKey, Error> {
} else {
if !metadata_dir.exists() {
info!("Metadata directory does not exist, creating it.");
- std::fs::create_dir(&metadata_dir)?;
+ std::fs::create_dir(metadata_dir)?;
}
info!("Generating new node key pair.");
@@ -419,7 +419,7 @@ impl System {
.get(&n.id.into())
.cloned()
.map(|(_, st)| st)
- .unwrap_or(NodeStatus::unknown()),
+ .unwrap_or_else(NodeStatus::unknown),
})
.collect::<Vec<_>>();
known_nodes