aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrinity Pointard <trinity.pointard@gmail.com>2021-04-23 21:57:32 +0200
committerAlex Auvolat <alex@adnab.me>2021-05-03 22:11:41 +0200
commit4a1e079e8fe2c17078a274ef17c8d63e9b1bb96e (patch)
tree931ae67ad8f1fc22424c3e21394de188905a9586
parentf5a0cf0414fc3db7affcbe7ffcf4e251a2afd192 (diff)
downloadgarage-4a1e079e8fe2c17078a274ef17c8d63e9b1bb96e.tar.gz
garage-4a1e079e8fe2c17078a274ef17c8d63e9b1bb96e.zip
fix clippy warnings on model
-rw-r--r--src/model/block.rs30
-rw-r--r--src/model/block_ref_table.rs2
-rw-r--r--src/model/bucket_table.rs20
-rw-r--r--src/model/garage.rs10
-rw-r--r--src/model/object_table.rs14
5 files changed, 38 insertions, 38 deletions
diff --git a/src/model/block.rs b/src/model/block.rs
index 5f428fe1..1c9aa08b 100644
--- a/src/model/block.rs
+++ b/src/model/block.rs
@@ -1,4 +1,4 @@
-use std::path::PathBuf;
+use std::path::{Path, PathBuf};
use std::sync::Arc;
use std::time::Duration;
@@ -137,7 +137,7 @@ impl BlockManager {
Message::PutBlock(m) => self.write_block(&m.hash, &m.data).await,
Message::GetBlock(h) => self.read_block(h).await,
Message::NeedBlockQuery(h) => self.need_block(h).await.map(Message::NeedBlockReply),
- _ => Err(Error::BadRPC(format!("Unexpected RPC message"))),
+ _ => Err(Error::BadRPC("Unexpected RPC message".to_string())),
}
}
@@ -280,8 +280,8 @@ impl BlockManager {
if let Err(e) = self.resync_iter(&mut must_exit).await {
warn!("Error in block resync loop: {}", e);
select! {
- _ = tokio::time::sleep(Duration::from_secs(1)).fuse() => (),
- _ = must_exit.changed().fuse() => (),
+ _ = tokio::time::sleep(Duration::from_secs(1)).fuse() => {},
+ _ = must_exit.changed().fuse() => {},
}
}
}
@@ -304,15 +304,15 @@ impl BlockManager {
} else {
let delay = tokio::time::sleep(Duration::from_millis(time_msec - now));
select! {
- _ = delay.fuse() => (),
- _ = self.resync_notify.notified().fuse() => (),
- _ = must_exit.changed().fuse() => (),
+ _ = delay.fuse() => {},
+ _ = self.resync_notify.notified().fuse() => {},
+ _ = must_exit.changed().fuse() => {},
}
}
} else {
select! {
- _ = self.resync_notify.notified().fuse() => (),
- _ = must_exit.changed().fuse() => (),
+ _ = self.resync_notify.notified().fuse() => {},
+ _ = must_exit.changed().fuse() => {},
}
}
Ok(())
@@ -342,7 +342,7 @@ impl BlockManager {
let mut who = self.replication.write_nodes(&hash);
if who.len() < self.replication.write_quorum() {
- return Err(Error::Message(format!("Not trying to offload block because we don't have a quorum of nodes to write to")));
+ return Err(Error::Message("Not trying to offload block because we don't have a quorum of nodes to write to".to_string()));
}
who.retain(|id| *id != self.system.id);
@@ -362,14 +362,14 @@ impl BlockManager {
}
}
_ => {
- return Err(Error::Message(format!(
- "Unexpected response to NeedBlockQuery RPC"
- )));
+ return Err(Error::Message(
+ "Unexpected response to NeedBlockQuery RPC".to_string(),
+ ));
}
}
}
- if need_nodes.len() > 0 {
+ if !need_nodes.is_empty() {
trace!(
"Block {:?} needed by {} nodes, sending",
hash,
@@ -478,7 +478,7 @@ impl BlockManager {
fn repair_aux_read_dir_rec<'a>(
&'a self,
- path: &'a PathBuf,
+ path: &'a Path,
must_exit: &'a watch::Receiver<bool>,
) -> BoxFuture<'a, Result<(), Error>> {
// Lists all blocks on disk and adds them to the resync queue.
diff --git a/src/model/block_ref_table.rs b/src/model/block_ref_table.rs
index 95451e9c..c2d77fd3 100644
--- a/src/model/block_ref_table.rs
+++ b/src/model/block_ref_table.rs
@@ -50,7 +50,7 @@ impl TableSchema for BlockRefTable {
type Filter = DeletedFilter;
fn updated(&self, old: Option<Self::E>, new: Option<Self::E>) {
- let block = &old.as_ref().or(new.as_ref()).unwrap().block;
+ let block = &old.as_ref().or_else(|| new.as_ref()).unwrap().block;
let was_before = old.as_ref().map(|x| !x.deleted.get()).unwrap_or(false);
let is_after = new.as_ref().map(|x| !x.deleted.get()).unwrap_or(false);
if is_after && !was_before {
diff --git a/src/model/bucket_table.rs b/src/model/bucket_table.rs
index 69901b8d..9f89dccc 100644
--- a/src/model/bucket_table.rs
+++ b/src/model/bucket_table.rs
@@ -49,13 +49,6 @@ pub struct BucketParams {
pub website: crdt::LWW<bool>,
}
-impl CRDT for BucketParams {
- fn merge(&mut self, o: &Self) {
- self.authorized_keys.merge(&o.authorized_keys);
- self.website.merge(&o.website);
- }
-}
-
impl BucketParams {
/// Create an empty BucketParams with no authorized keys and no website accesss
pub fn new() -> Self {
@@ -66,6 +59,19 @@ impl BucketParams {
}
}
+impl CRDT for BucketParams {
+ fn merge(&mut self, o: &Self) {
+ self.authorized_keys.merge(&o.authorized_keys);
+ self.website.merge(&o.website);
+ }
+}
+
+impl Default for BucketParams {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl Bucket {
/// Initializes a new instance of the Bucket struct
pub fn new(name: String) -> Self {
diff --git a/src/model/garage.rs b/src/model/garage.rs
index 797a91e5..5c6c21f2 100644
--- a/src/model/garage.rs
+++ b/src/model/garage.rs
@@ -95,7 +95,7 @@ impl Garage {
BlockRefTable {
block_manager: block_manager.clone(),
},
- data_rep_param.clone(),
+ data_rep_param,
system.clone(),
&db,
"block_ref".to_string(),
@@ -121,7 +121,7 @@ impl Garage {
background: background.clone(),
version_table: version_table.clone(),
},
- meta_rep_param.clone(),
+ meta_rep_param,
system.clone(),
&db,
"object".to_string(),
@@ -141,7 +141,7 @@ impl Garage {
info!("Initialize key_table_table...");
let key_table = Table::new(
KeyTable,
- control_rep_param.clone(),
+ control_rep_param,
system.clone(),
&db,
"key".to_string(),
@@ -152,9 +152,9 @@ impl Garage {
let garage = Arc::new(Self {
config,
db,
- system: system.clone(),
- block_manager,
background,
+ system,
+ block_manager,
bucket_table,
key_table,
object_table,
diff --git a/src/model/object_table.rs b/src/model/object_table.rs
index b0611822..f0473836 100644
--- a/src/model/object_table.rs
+++ b/src/model/object_table.rs
@@ -40,6 +40,7 @@ impl Object {
}
/// Adds a version if it wasn't already present
+ #[allow(clippy::result_unit_err)]
pub fn add_version(&mut self, new: ObjectVersion) -> Result<(), ()> {
match self
.versions
@@ -145,18 +146,12 @@ impl ObjectVersion {
/// Is the object version currently being uploaded
pub fn is_uploading(&self) -> bool {
- match self.state {
- ObjectVersionState::Uploading(_) => true,
- _ => false,
- }
+ matches!(self.state, ObjectVersionState::Uploading(_))
}
/// Is the object version completely received
pub fn is_complete(&self) -> bool {
- match self.state {
- ObjectVersionState::Complete(_) => true,
- _ => false,
- }
+ matches!(self.state, ObjectVersionState::Complete(_))
}
/// Is the object version available (received and not a tombstone)
@@ -207,8 +202,7 @@ impl CRDT for Object {
.iter()
.enumerate()
.rev()
- .filter(|(_, v)| v.is_complete())
- .next()
+ .find(|(_, v)| v.is_complete())
.map(|(vi, _)| vi);
if let Some(last_vi) = last_complete {