From 6b96b2dab772b0a6154780ec8b60672c6dff18e4 Mon Sep 17 00:00:00 2001 From: Chojan Shang Date: Sun, 5 Dec 2021 22:06:47 +0800 Subject: [PATCH] Bump nix, rand, and more Signed-off-by: Chojan Shang --- Cargo.toml | 8 ++++---- src/file_pipe_log/log_file.rs | 31 +++++++++++++------------------ stress/Cargo.toml | 6 +++--- stress/src/main.rs | 4 ++-- tests/benches/bench_recovery.rs | 2 +- 5 files changed, 23 insertions(+), 28 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 74e77842..65758482 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,7 +31,7 @@ lazy_static = "1.3" libc = "0.2" log = { version = "0.4", features = ["max_level_trace", "release_max_level_debug"] } lz4-sys = "1.9" -nix = "0.19" +nix = "0.23" num-derive = "0.3" num-traits = "0.2" parking_lot = "0.11" @@ -45,11 +45,11 @@ thiserror = "1.0" [dev-dependencies] criterion = "0.3" ctor = "0.1" -env_logger = "0.7" +env_logger = "0.9" kvproto = { git = "https://github.com/pingcap/kvproto.git", default-features = false, features = ["protobuf-codec"] } raft = { git = "https://github.com/tikv/raft-rs", branch = "master", default-features = false, features = ["protobuf-codec"] } -rand = "0.7" -rand_distr = "0.3" +rand = "0.8" +rand_distr = "0.4" tempfile = "3.1" toml = "0.5" diff --git a/src/file_pipe_log/log_file.rs b/src/file_pipe_log/log_file.rs index f07f6be1..f8ad1a67 100644 --- a/src/file_pipe_log/log_file.rs +++ b/src/file_pipe_log/log_file.rs @@ -30,19 +30,14 @@ const FILE_ALLOCATE_SIZE: usize = 2 * 1024 * 1024; pub struct LogFd(RawFd); fn from_nix_error(e: nix::Error, custom: &'static str) -> std::io::Error { - match e { - nix::Error::Sys(no) => { - let kind = std::io::Error::from(no).kind(); - std::io::Error::new(kind, custom) - } - e => std::io::Error::new(std::io::ErrorKind::Other, format!("{}: {:?}", custom, e)), - } + let kind = std::io::Error::from(e).kind(); + std::io::Error::new(kind, custom) } impl LogFd { pub fn open(path: &P) -> IoResult { fail_point!("log_fd::open::err", |_| { - Err(from_nix_error(nix::Error::invalid_argument(), "fp")) + Err(from_nix_error(nix::Error::EINVAL, "fp")) }); let flags = OFlag::O_RDWR; // Permission 644 @@ -63,7 +58,7 @@ impl LogFd { pub fn create(path: &P) -> IoResult { fail_point!("log_fd::create::err", |_| { - Err(from_nix_error(nix::Error::invalid_argument(), "fp")) + Err(from_nix_error(nix::Error::EINVAL, "fp")) }); let flags = OFlag::O_RDWR | OFlag::O_CREAT; // Permission 644 @@ -74,14 +69,14 @@ impl LogFd { pub fn close(&self) -> IoResult<()> { fail_point!("log_fd::close::err", |_| { - Err(from_nix_error(nix::Error::invalid_argument(), "fp")) + Err(from_nix_error(nix::Error::EINVAL, "fp")) }); close(self.0).map_err(|e| from_nix_error(e, "close")) } pub fn sync(&self) -> IoResult<()> { fail_point!("log_fd::sync::err", |_| { - Err(from_nix_error(nix::Error::invalid_argument(), "fp")) + Err(from_nix_error(nix::Error::EINVAL, "fp")) }); #[cfg(target_os = "linux")] { @@ -97,11 +92,11 @@ impl LogFd { let mut readed = 0; while readed < buf.len() { fail_point!("log_fd::read::err", |_| { - Err(from_nix_error(nix::Error::invalid_argument(), "fp")) + Err(from_nix_error(nix::Error::EINVAL, "fp")) }); let bytes = match pread(self.0, &mut buf[readed..], offset as i64) { Ok(bytes) => bytes, - Err(e) if e.as_errno() == Some(Errno::EAGAIN) => continue, + Err(e) if e == Errno::EAGAIN => continue, Err(e) => return Err(from_nix_error(e, "pread")), }; // EOF @@ -120,7 +115,7 @@ impl LogFd { while written < content.len() { let bytes = match pwrite(self.0, &content[written..], offset as i64) { Ok(bytes) => bytes, - Err(e) if e.as_errno() == Some(Errno::EAGAIN) => continue, + Err(e) if e == Errno::EAGAIN => continue, Err(e) => return Err(from_nix_error(e, "pwrite")), }; if bytes == 0 { @@ -130,14 +125,14 @@ impl LogFd { offset += bytes; } fail_point!("log_fd::write::err", |_| { - Err(from_nix_error(nix::Error::invalid_argument(), "fp")) + Err(from_nix_error(nix::Error::EINVAL, "fp")) }); Ok(written) } pub fn file_size(&self) -> IoResult { fail_point!("log_fd::file_size::err", |_| { - Err(from_nix_error(nix::Error::invalid_argument(), "fp")) + Err(from_nix_error(nix::Error::EINVAL, "fp")) }); lseek(self.0, 0, Whence::SeekEnd) .map(|n| n as usize) @@ -146,7 +141,7 @@ impl LogFd { pub fn truncate(&self, offset: usize) -> IoResult<()> { fail_point!("log_fd::truncate::err", |_| { - Err(from_nix_error(nix::Error::invalid_argument(), "fp")) + Err(from_nix_error(nix::Error::EINVAL, "fp")) }); ftruncate(self.0, offset as i64).map_err(|e| from_nix_error(e, "ftruncate")) } @@ -154,7 +149,7 @@ impl LogFd { #[allow(unused_variables)] pub fn allocate(&self, offset: usize, size: usize) -> IoResult<()> { fail_point!("log_fd::allocate::err", |_| { - Err(from_nix_error(nix::Error::invalid_argument(), "fp")) + Err(from_nix_error(nix::Error::EINVAL, "fp")) }); #[cfg(target_os = "linux")] { diff --git a/stress/Cargo.toml b/stress/Cargo.toml index 6573c04c..704e3769 100644 --- a/stress/Cargo.toml +++ b/stress/Cargo.toml @@ -7,10 +7,10 @@ edition = "2018" [dependencies] clap = "3.0.0-beta.5" const_format = "0.2.13" -hdrhistogram = "6.0" +hdrhistogram = "7.4" parking_lot_core = "0.8" raft = { git = "https://github.com/tikv/raft-rs", branch = "master", default-features = false, features = ["protobuf-codec"] } raft-engine = { path = ".." } -rand = "0.7" -rand_distr = "0.3" +rand = "0.8" +rand_distr = "0.4" statistical = "1.0.0" diff --git a/stress/src/main.rs b/stress/src/main.rs index 930f463a..dafda574 100644 --- a/stress/src/main.rs +++ b/stress/src/main.rs @@ -416,7 +416,7 @@ fn spawn_write( } while !shutdown.load(Ordering::Relaxed) { // TODO(tabokie): scattering regions in one batch - let mut rid = thread_rng().gen_range(0, args.regions / args.write_threads) + let mut rid = thread_rng().gen_range(0..(args.regions / args.write_threads)) * args.write_threads + index; for _ in 0..args.write_region_count { @@ -470,7 +470,7 @@ fn spawn_read( None }; while !shutdown.load(Ordering::Relaxed) { - let rid = thread_rng().gen_range(0, args.regions / args.read_threads) + let rid = thread_rng().gen_range(0..(args.regions / args.read_threads)) * args.read_threads + index; let mut start = Instant::now(); diff --git a/tests/benches/bench_recovery.rs b/tests/benches/bench_recovery.rs index 983488fe..bc33b502 100644 --- a/tests/benches/bench_recovery.rs +++ b/tests/benches/bench_recovery.rs @@ -72,7 +72,7 @@ fn generate(cfg: &Config) -> Result { while dir_size(&path).0 < cfg.total_size.0 { let mut batch = LogBatch::default(); while batch.approximate_size() < cfg.batch_size.0 as usize { - let region_id = rng.gen_range(1, cfg.region_count + 1); + let region_id = rng.gen_range(1..cfg.region_count + 1); let mut item_size = 0; let mut entries = vec![]; while item_size < cfg.item_size.0 {