mirror of
https://github.com/tursodatabase/limbo.git
synced 2025-08-04 18:18:03 +00:00
O_DIRECT disable on WAL
This commit is contained in:
parent
94a45eab9e
commit
e2276c2e9d
10 changed files with 31 additions and 17 deletions
|
@ -15,7 +15,9 @@ impl Database {
|
|||
#[wasm_bindgen(constructor)]
|
||||
pub fn new(path: &str) -> Database {
|
||||
let io = Arc::new(PlatformIO { vfs: VFS::new() });
|
||||
let file = io.open_file(path, limbo_core::OpenFlags::None).unwrap();
|
||||
let file = io
|
||||
.open_file(path, limbo_core::OpenFlags::None, false)
|
||||
.unwrap();
|
||||
let page_io = Rc::new(DatabaseStorage::new(file));
|
||||
let wal = Rc::new(RefCell::new(Wal {}));
|
||||
let inner = limbo_core::Database::open(io, page_io, wal).unwrap();
|
||||
|
@ -87,7 +89,12 @@ pub struct PlatformIO {
|
|||
}
|
||||
|
||||
impl limbo_core::IO for PlatformIO {
|
||||
fn open_file(&self, path: &str, _flags: OpenFlags) -> Result<Rc<dyn limbo_core::File>> {
|
||||
fn open_file(
|
||||
&self,
|
||||
path: &str,
|
||||
_flags: OpenFlags,
|
||||
_direct: bool,
|
||||
) -> Result<Rc<dyn limbo_core::File>> {
|
||||
let fd = self.vfs.open(path);
|
||||
Ok(Rc::new(File {
|
||||
vfs: VFS::new(),
|
||||
|
|
|
@ -13,7 +13,7 @@ pub mod tests {
|
|||
// Parent process opens the file
|
||||
let io1 = create_io().expect("Failed to create IO");
|
||||
let _file1 = io1
|
||||
.open_file(&path, crate::io::OpenFlags::None)
|
||||
.open_file(&path, crate::io::OpenFlags::None, false)
|
||||
.expect("Failed to open file in parent process");
|
||||
|
||||
let current_exe = std::env::current_exe().expect("Failed to get current executable path");
|
||||
|
@ -38,7 +38,7 @@ pub mod tests {
|
|||
if std::env::var("RUST_TEST_CHILD_PROCESS").is_ok() {
|
||||
let path = std::env::var("RUST_TEST_FILE_PATH")?;
|
||||
let io = create_io()?;
|
||||
match io.open_file(&path, crate::io::OpenFlags::None) {
|
||||
match io.open_file(&path, crate::io::OpenFlags::None, false) {
|
||||
Ok(_) => std::process::exit(0),
|
||||
Err(_) => std::process::exit(1),
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ impl DarwinIO {
|
|||
}
|
||||
|
||||
impl IO for DarwinIO {
|
||||
fn open_file(&self, path: &str, flags: OpenFlags) -> Result<Rc<dyn File>> {
|
||||
fn open_file(&self, path: &str, flags: OpenFlags, _direct: bool) -> Result<Rc<dyn File>> {
|
||||
trace!("open_file(path = {})", path);
|
||||
let file = std::fs::File::options()
|
||||
.read(true)
|
||||
|
|
|
@ -13,7 +13,7 @@ impl GenericIO {
|
|||
}
|
||||
|
||||
impl IO for GenericIO {
|
||||
fn open_file(&self, path: &str, flags: OpenFlags) -> Result<Rc<dyn File>> {
|
||||
fn open_file(&self, path: &str, flags: OpenFlags, _direct: bool) -> Result<Rc<dyn File>> {
|
||||
trace!("open_file(path = {})", path);
|
||||
let file = std::fs::File::open(path)?;
|
||||
Ok(Rc::new(GenericFile {
|
||||
|
|
|
@ -119,7 +119,7 @@ impl WrappedIOUring {
|
|||
}
|
||||
|
||||
impl IO for LinuxIO {
|
||||
fn open_file(&self, path: &str, flags: OpenFlags) -> Result<Rc<dyn File>> {
|
||||
fn open_file(&self, path: &str, flags: OpenFlags, direct: bool) -> Result<Rc<dyn File>> {
|
||||
trace!("open_file(path = {})", path);
|
||||
let file = std::fs::File::options()
|
||||
.read(true)
|
||||
|
@ -129,10 +129,12 @@ impl IO for LinuxIO {
|
|||
// Let's attempt to enable direct I/O. Not all filesystems support it
|
||||
// so ignore any errors.
|
||||
let fd = file.as_raw_fd();
|
||||
match nix::fcntl::fcntl(fd, FcntlArg::F_SETFL(OFlag::O_DIRECT)) {
|
||||
Ok(_) => {},
|
||||
Err(error) => debug!("Error {error:?} returned when setting O_DIRECT flag to read file. The performance of the system may be affected"),
|
||||
};
|
||||
if direct {
|
||||
match nix::fcntl::fcntl(fd, FcntlArg::F_SETFL(OFlag::O_DIRECT)) {
|
||||
Ok(_) => {},
|
||||
Err(error) => debug!("Error {error:?} returned when setting O_DIRECT flag to read file. The performance of the system may be affected"),
|
||||
};
|
||||
}
|
||||
let linux_file = Rc::new(LinuxFile {
|
||||
io: self.inner.clone(),
|
||||
file,
|
||||
|
|
|
@ -24,7 +24,7 @@ pub enum OpenFlags {
|
|||
}
|
||||
|
||||
pub trait IO {
|
||||
fn open_file(&self, path: &str, flags: OpenFlags) -> Result<Rc<dyn File>>;
|
||||
fn open_file(&self, path: &str, flags: OpenFlags, direct: bool) -> Result<Rc<dyn File>>;
|
||||
|
||||
fn run_once(&self) -> Result<()>;
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ impl WindowsIO {
|
|||
}
|
||||
|
||||
impl IO for WindowsIO {
|
||||
fn open_file(&self, path: &str, flags: OpenFlags) -> Result<Rc<dyn File>> {
|
||||
fn open_file(&self, path: &str, flags: OpenFlags, direct: bool) -> Result<Rc<dyn File>> {
|
||||
trace!("open_file(path = {})", path);
|
||||
let file = std::fs::File::options()
|
||||
.read(true)
|
||||
|
|
|
@ -65,7 +65,7 @@ pub struct Database {
|
|||
impl Database {
|
||||
#[cfg(feature = "fs")]
|
||||
pub fn open_file(io: Arc<dyn IO>, path: &str) -> Result<Rc<Database>> {
|
||||
let file = io.open_file(path, io::OpenFlags::None)?;
|
||||
let file = io.open_file(path, io::OpenFlags::None, true)?;
|
||||
let page_io = Rc::new(FileStorage::new(file));
|
||||
let wal_path = format!("{}-wal", path);
|
||||
let db_header = Pager::begin_open(page_io.clone())?;
|
||||
|
|
|
@ -255,7 +255,7 @@ impl WalFile {
|
|||
if self.file.borrow().is_none() {
|
||||
match self
|
||||
.io
|
||||
.open_file(&self.wal_path, crate::io::OpenFlags::Create)
|
||||
.open_file(&self.wal_path, crate::io::OpenFlags::Create, false)
|
||||
{
|
||||
Ok(file) => {
|
||||
if file.size()? > 0 {
|
||||
|
|
|
@ -94,8 +94,13 @@ impl SimulatorIO {
|
|||
}
|
||||
|
||||
impl IO for SimulatorIO {
|
||||
fn open_file(&self, path: &str, flags: OpenFlags) -> Result<Rc<dyn limbo_core::File>> {
|
||||
let inner = self.inner.open_file(path, flags)?;
|
||||
fn open_file(
|
||||
&self,
|
||||
path: &str,
|
||||
flags: OpenFlags,
|
||||
_direct: bool,
|
||||
) -> Result<Rc<dyn limbo_core::File>> {
|
||||
let inner = self.inner.open_file(path, flags, false)?;
|
||||
let file = Rc::new(SimulatorFile {
|
||||
inner,
|
||||
fault: RefCell::new(false),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue