Skip to content

Commit

Permalink
switch to 2021 edition of Rust (openzfs#21)
Browse files Browse the repository at this point in the history
Make 2 changes that are not strictly required but make sense given the
changes in the 2021 edition:

1. TryFrom/TryInto no longer need to be imported, as they are part of
the standard prelude.  Remove the redundant `use` statements.

2. When possible, closures capture members of local variables, rather
than the entire variable.  This can cause the non-captured members to be
dropped later than in the 2018 edition.  In our case (in
ZettaCache::open()), this doesn't really matter, but it brought to my
attention that we're cloning and then discarding a bunch of the members
of ZettaCache (without using them).  So I changed this to just clone the
few members that are actually needed by the closures.
  • Loading branch information
ahrens authored Nov 19, 2021
1 parent 1de6fdd commit 62c1c01
Show file tree
Hide file tree
Showing 16 changed files with 16 additions and 25 deletions.
2 changes: 1 addition & 1 deletion cmd/zfs_object_agent/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "zoa_test"
version = "0.1.0"
authors = ["Delphix"]
edition = "2018"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
4 changes: 2 additions & 2 deletions cmd/zfs_object_agent/object_perf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "zfs_object_perf"
version = "0.1.0"
authors = ["Delphix"]
edition = "2018"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand All @@ -15,4 +15,4 @@ futures = "0.3.16"
serde = { version = "1.0.125", features = ["derive"] }
uuid = {version = "0.8"}
tokio = { version = "1.4", features = ["full"] }
zettaobject = { path = "../zettaobject" }
zettaobject = { path = "../zettaobject" }
1 change: 0 additions & 1 deletion cmd/zfs_object_agent/object_perf/src/s3perf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use metered::hdr_histogram::AtomicHdrHistogram;
use metered::metered;
use metered::time_source::StdInstantMicros;
use std::cmp::max;
use std::convert::TryInto;
use std::error::Error;
use std::string::String;
use std::sync::Arc;
Expand Down
2 changes: 1 addition & 1 deletion cmd/zfs_object_agent/server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "zfs_object_agent"
version = "0.1.0"
authors = ["Delphix"]
edition = "2018"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
2 changes: 1 addition & 1 deletion cmd/zfs_object_agent/util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "util"
version = "0.1.0"
authors = ["Delphix"]
edition = "2018"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
Expand Down
2 changes: 0 additions & 2 deletions cmd/zfs_object_agent/util/src/from64.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::convert::TryInto;

/// Conversions that are safe assuming that we are on LP64 (usize == u64)
pub trait From64<A> {
fn from64(a: A) -> Self;
Expand Down
4 changes: 2 additions & 2 deletions cmd/zfs_object_agent/zcdb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "zcachedb"
version = "0.1.0"
authors = ["Delphix"]
edition = "2018"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand All @@ -12,4 +12,4 @@ git-version = "0.3.5"
libc = "0.2"
log = "0.4"
tokio = { version = "1.4", features = ["full"] }
zettacache = { path = "../zettacache" }
zettacache = { path = "../zettacache" }
2 changes: 1 addition & 1 deletion cmd/zfs_object_agent/zettacache/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "zettacache"
version = "0.1.0"
authors = ["Delphix"]
edition = "2018"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
2 changes: 0 additions & 2 deletions cmd/zfs_object_agent/zettacache/src/block_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ use num::Num;
use num::NumCast;
use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
use std::convert::TryFrom;
use std::convert::TryInto;
use std::io::Read;
use std::io::Write;
use std::os::unix::prelude::AsRawFd;
Expand Down
1 change: 0 additions & 1 deletion cmd/zfs_object_agent/zettacache/src/block_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use roaring::RoaringBitmap;
use serde::{Deserialize, Serialize};
use std::cmp::{self, min};
use std::collections::{BTreeMap, BTreeSet, HashSet};
use std::convert::TryFrom;
use std::ops::Bound::*;
use std::sync::Arc;
use std::time::Instant;
Expand Down
12 changes: 6 additions & 6 deletions cmd/zfs_object_agent/zettacache/src/zettacache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use more_asserts::*;
use serde::{Deserialize, Serialize};
use std::collections::btree_map;
use std::collections::BTreeMap;
use std::convert::TryFrom;
use std::ops::Bound::{Excluded, Unbounded};
use std::pin::Pin;
use std::sync::Arc;
Expand Down Expand Up @@ -685,17 +684,18 @@ impl ZettaCache {
my_cache.checkpoint_task(merge_rx, merge_index).await;
});

let my_cache = this.clone();
let state = this.state.clone();
let metrics = this.metrics.clone();
tokio::spawn(async move {
let mut interval = tokio::time::interval(Duration::from_secs(10));
loop {
interval.tick().await;
debug!("metrics: {:#?}", my_cache.metrics);
my_cache.state.lock().await.block_access.dump_metrics();
debug!("metrics: {:#?}", metrics);
state.lock().await.block_access.dump_metrics();
}
});

let my_cache = this.clone();
let state = this.state.clone();
tokio::spawn(async move {
// XXX maybe we should bump the atime after a set number of
// accesses, so each histogram bucket starts with the same count.
Expand All @@ -704,7 +704,7 @@ impl ZettaCache {
let mut interval = tokio::time::interval(Duration::from_secs(10));
loop {
interval.tick().await;
let mut state = my_cache.state.lock().await;
let mut state = state.lock().await;
state.atime = state.atime.next();
}
});
Expand Down
2 changes: 1 addition & 1 deletion cmd/zfs_object_agent/zettaobject/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "zettaobject"
version = "0.1.0"
authors = ["Delphix"]
edition = "2018"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
1 change: 0 additions & 1 deletion cmd/zfs_object_agent/zettaobject/src/data_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use log::*;
use more_asserts::*;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::convert::{TryFrom, TryInto};
use std::fmt;
use std::fmt::Display;
use std::time::Instant;
Expand Down
1 change: 0 additions & 1 deletion cmd/zfs_object_agent/zettaobject/src/object_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use rusoto_s3::{
ListObjectsV2Request, ObjectIdentifier, PutObjectError, PutObjectOutput, PutObjectRequest,
S3Client, S3,
};
use std::convert::TryFrom;
use std::error::Error;
use std::fmt::Formatter;
use std::iter;
Expand Down
1 change: 0 additions & 1 deletion cmd/zfs_object_agent/zettaobject/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ use std::borrow::Borrow;
use std::cmp::{max, min};
use std::collections::hash_map;
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
use std::convert::{TryFrom, TryInto};
use std::fmt;
use std::fmt::Display;
use std::mem;
Expand Down
2 changes: 1 addition & 1 deletion cmd/zfs_object_agent/zoa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "zoa"
version = "0.1.0"
authors = ["Delphix"]
edition = "2018"
edition = "2021"
build = "src/build.rs"

[build-dependencies]
Expand Down

0 comments on commit 62c1c01

Please sign in to comment.