Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into rkuris/proof-node-typ…
Browse files Browse the repository at this point in the history
…e-deets
  • Loading branch information
rkuris committed Aug 28, 2023
2 parents a53eb56 + 42111f1 commit 3a81c47
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 24 deletions.
2 changes: 1 addition & 1 deletion firewood/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ futures = "0.3.24"
hex = "0.4.3"
lru = "0.11.0"
metered = "0.9.0"
nix = "0.26.1"
nix = {version = "0.27.1", features = ["fs", "uio"]}
parking_lot = "0.12.1"
primitive-types = { version = "0.12.0", features = ["impl-rlp"] }
rlp = "0.5.2"
Expand Down
3 changes: 2 additions & 1 deletion firewood/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use std::{
io::{Cursor, Write},
mem::size_of,
num::NonZeroUsize,
os::fd::AsFd,
path::Path,
sync::Arc,
thread::JoinHandle,
Expand Down Expand Up @@ -407,7 +408,7 @@ impl Db {
let root_hash_path = file::touch_dir("root_hash", &db_path)?;

let file0 = crate::file::File::new(0, SPACE_RESERVED, &merkle_meta_path)?;
let fd0 = file0.get_fd();
let fd0 = file0.as_fd();

if reset {
// initialize dbparams
Expand Down
29 changes: 13 additions & 16 deletions firewood/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@

// Copied from CedrusDB

use std::os::fd::IntoRawFd;
pub(crate) use std::os::unix::io::RawFd as Fd;
use std::ops::Deref;
use std::os::fd::OwnedFd;

use std::path::{Path, PathBuf};
use std::{io::ErrorKind, os::unix::prelude::OpenOptionsExt};

use nix::unistd::close;

pub struct File {
fd: Fd,
fd: OwnedFd,
}

#[derive(PartialEq, Eq)]
Expand All @@ -25,7 +24,7 @@ impl File {
rootpath: PathBuf,
fname: &str,
options: Options,
) -> Result<Fd, std::io::Error> {
) -> Result<OwnedFd, std::io::Error> {
let mut filepath = rootpath;
filepath.push(fname);
Ok(std::fs::File::options()
Expand All @@ -34,10 +33,10 @@ impl File {
.write(true)
.mode(0o600)
.open(filepath)?
.into_raw_fd())
.into())
}

pub fn create_file(rootpath: PathBuf, fname: &str) -> Result<Fd, std::io::Error> {
pub fn create_file(rootpath: PathBuf, fname: &str) -> Result<OwnedFd, std::io::Error> {
let mut filepath = rootpath;
filepath.push(fname);
Ok(std::fs::File::options()
Expand All @@ -46,7 +45,7 @@ impl File {
.write(true)
.mode(0o600)
.open(filepath)?
.into_raw_fd())
.into())
}

fn _get_fname(fid: u64) -> String {
Expand All @@ -65,15 +64,13 @@ impl File {
};
Ok(File { fd })
}

pub fn get_fd(&self) -> Fd {
self.fd
}
}

impl Drop for File {
fn drop(&mut self) {
close(self.fd).unwrap();
impl Deref for File {
type Target = OwnedFd;

fn deref(&self) -> &Self::Target {
&self.fd
}
}

Expand Down
10 changes: 8 additions & 2 deletions firewood/src/storage/buffer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Disk buffer for staging in memory pages and flushing them to disk.
use std::fmt::Debug;
use std::ops::IndexMut;
use std::os::fd::{AsFd, AsRawFd};
use std::path::{Path, PathBuf};
use std::rc::Rc;
use std::sync::Arc;
Expand Down Expand Up @@ -227,7 +228,12 @@ fn schedule_write(
.unwrap()
.get_file(fid)
.unwrap();
aiomgr.write(file.get_fd(), offset & fmask, p.staging_data.clone(), None)
aiomgr.write(
file.as_raw_fd(),
offset & fmask,
p.staging_data.clone(),
None,
)
};

let task = {
Expand Down Expand Up @@ -304,7 +310,7 @@ async fn init_wal(
e, final_path
))
})?
.get_fd(),
.as_fd(),
&redo.data,
(offset & file_mask) as nix::libc::off_t,
)
Expand Down
7 changes: 4 additions & 3 deletions firewood/src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::{
fmt::{self, Debug},
num::NonZeroUsize,
ops::{Deref, DerefMut},
os::fd::{AsFd, AsRawFd},
path::PathBuf,
sync::Arc,
};
Expand Down Expand Up @@ -779,7 +780,7 @@ impl CachedSpaceInner {
let mut page: Page = Page::new([0; PAGE_SIZE as usize]);

nix::sys::uio::pread(
file.get_fd(),
file.as_fd(),
page.deref_mut(),
(poff & (file_size - 1)) as nix::libc::off_t,
)
Expand Down Expand Up @@ -901,7 +902,7 @@ impl FilePool {
rootdir: rootdir.to_path_buf(),
};
let f0 = s.get_file(0)?;
if flock(f0.get_fd(), FlockArg::LockExclusiveNonblock).is_err() {
if flock(f0.as_raw_fd(), FlockArg::LockExclusiveNonblock).is_err() {
return Err(StoreError::Init("the store is busy".into()));
}
Ok(s)
Expand Down Expand Up @@ -931,7 +932,7 @@ impl FilePool {
impl Drop for FilePool {
fn drop(&mut self) {
let f0 = self.get_file(0).unwrap();
flock(f0.get_fd(), FlockArg::UnlockNonblock).ok();
flock(f0.as_raw_fd(), FlockArg::UnlockNonblock).ok();
}
}

Expand Down
2 changes: 1 addition & 1 deletion growth-ring/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ scan_fmt = "0.2.6"
regex = "1.6.0"
async-trait = "0.1.57"
futures = "0.3.24"
nix = "0.26.2"
nix = {version = "0.27.1", features = ["fs", "uio"]}
libc = "0.2.133"
bytemuck = {version = "1.13.1", features = ["derive"]}
thiserror = "1.0.40"
Expand Down

0 comments on commit 3a81c47

Please sign in to comment.