Skip to content

Commit

Permalink
Bump nix, rand, and more (#164)
Browse files Browse the repository at this point in the history
Signed-off-by: Chojan Shang <psiace@outlook.com>
  • Loading branch information
Chojan Shang authored Dec 6, 2021
1 parent e87faf7 commit 5d3c072
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 28 deletions.
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"

Expand Down
31 changes: 13 additions & 18 deletions src/file_pipe_log/log_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<P: ?Sized + NixPath>(path: &P) -> IoResult<Self> {
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
Expand All @@ -63,7 +58,7 @@ impl LogFd {

pub fn create<P: ?Sized + NixPath>(path: &P) -> IoResult<Self> {
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
Expand All @@ -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")]
{
Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -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<usize> {
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)
Expand All @@ -146,15 +141,15 @@ 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"))
}

#[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")]
{
Expand Down
6 changes: 3 additions & 3 deletions stress/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 2 additions & 2 deletions stress/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion tests/benches/bench_recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fn generate(cfg: &Config) -> Result<TempDir> {
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 {
Expand Down

0 comments on commit 5d3c072

Please sign in to comment.