core/io: Untie MemoryIO's lifetime of the IO layer

This commit is contained in:
Diego Reis
2025-04-04 00:35:36 -03:00
parent 79f8b83cbe
commit d9bf383507
11 changed files with 23 additions and 33 deletions

View File

@@ -177,7 +177,7 @@ impl limbo_core::IO for IO {
todo!();
}
fn get_memory_io(&self) -> Option<Arc<limbo_core::MemoryIO>> {
todo!()
fn get_memory_io(&self) -> Arc<limbo_core::MemoryIO> {
Arc::new(limbo_core::MemoryIO::new())
}
}

View File

@@ -306,8 +306,8 @@ impl limbo_core::IO for PlatformIO {
(random_f64 * i64::MAX as f64) as i64
}
fn get_memory_io(&self) -> Option<Arc<limbo_core::MemoryIO>> {
None // TODO: Make sure if memory isn't needed here
fn get_memory_io(&self) -> Arc<limbo_core::MemoryIO> {
Arc::new(limbo_core::MemoryIO::new())
}
}

View File

@@ -6,14 +6,12 @@ use tracing::{debug, trace};
use super::MemoryIO;
pub struct GenericIO {
memory_io: Arc<MemoryIO>,
}
impl GenericIO {
pub fn new() -> Result<Self> {
debug!("Using IO backend 'generic'");
Ok(Self {
memory_io: Arc::new(MemoryIO::new()),
})
}
}
@@ -55,9 +53,9 @@ impl Clock for GenericIO {
}
}
fn get_memory_io(&self) -> Option<Arc<super::MemoryIO>> {
Some(self.memory_io.clone())
}
fn get_memory_io(&self) -> Arc<MemoryIO> {
Arc::new(MemoryIO::new())
}
}
pub struct GenericFile {

View File

@@ -35,7 +35,6 @@ impl fmt::Display for UringIOError {
pub struct UringIO {
inner: Rc<RefCell<InnerUringIO>>,
memory_io: Arc<MemoryIO>,
}
unsafe impl Send for UringIO {}
@@ -79,7 +78,6 @@ impl UringIO {
debug!("Using IO backend 'io-uring'");
Ok(Self {
inner: Rc::new(RefCell::new(inner)),
memory_io: Arc::new(MemoryIO::new()),
})
}
}
@@ -210,8 +208,8 @@ impl Clock for UringIO {
}
}
fn get_memory_io(&self) -> Option<Arc<MemoryIO>> {
Some(self.memory_io.clone())
fn get_memory_io(&self) -> Arc<MemoryIO> {
Arc::new(MemoryIO::new())
}
}

View File

@@ -59,8 +59,8 @@ impl IO for MemoryIO {
i64::from_ne_bytes(buf)
}
fn get_memory_io(&self) -> Option<Arc<MemoryIO>> {
None
fn get_memory_io(&self) -> Arc<MemoryIO> {
Arc::new(MemoryIO::new())
}
}

View File

@@ -41,7 +41,7 @@ pub trait IO: Clock + Send + Sync {
fn generate_random_number(&self) -> i64;
fn get_memory_io(&self) -> Option<Arc<MemoryIO>>;
fn get_memory_io(&self) -> Arc<MemoryIO>;
}
pub type Complete = dyn Fn(Arc<RefCell<Buffer>>);

View File

@@ -167,7 +167,6 @@ pub struct UnixIO {
poller: PollHandler,
events: EventsHandler,
callbacks: OwnedCallbacks,
memory_io: Arc<MemoryIO>,
}
unsafe impl Send for UnixIO {}
@@ -181,7 +180,6 @@ impl UnixIO {
poller: PollHandler::new(),
events: EventsHandler::new(),
callbacks: OwnedCallbacks::new(),
memory_io: Arc::new(MemoryIO::new()),
})
}
}
@@ -261,8 +259,8 @@ impl IO for UnixIO {
i64::from_ne_bytes(buf)
}
fn get_memory_io(&self) -> Option<Arc<MemoryIO>> {
Some(self.memory_io.clone())
fn get_memory_io(&self) -> Arc<MemoryIO> {
Arc::new(MemoryIO::new())
}
}

View File

@@ -70,8 +70,8 @@ impl VfsMod {
}
}
fn get_memory_io(&self) -> Option<Arc<MemoryIO>> {
None
fn get_memory_io(&self) -> Arc<MemoryIO> {
Arc::new(MemoryIO::new())
}
}

View File

@@ -5,14 +5,12 @@ use std::sync::Arc;
use tracing::{debug, trace};
use super::MemoryIO;
pub struct WindowsIO {
memory_io: Arc<MemoryIO>,
}
impl WindowsIO {
pub fn new() -> Result<Self> {
debug!("Using IO backend 'syscall'");
Ok(Self {
memory_io: Arc::new(MemoryIO::new()),
})
}
}
@@ -53,8 +51,8 @@ impl Clock for WindowsIO {
}
}
fn get_memory_io(&self) -> Option<Arc<MemoryIO>> {
Some(self.memory_io.clone())
fn get_memory_io(&self) -> Arc<MemoryIO> {
Arc::new(MemoryIO::new())
}
}

View File

@@ -38,7 +38,9 @@ use crate::{
vector::{vector32, vector64, vector_distance_cos, vector_extract},
};
use crate::{info, BufferPool, MvCursor, OpenFlags, RefValue, Row, StepResult, TransactionState};
use crate::{
info, BufferPool, MvCursor, OpenFlags, RefValue, Row, StepResult, TransactionState, IO,
};
use super::{
insn::{Cookie, RegisterOrLiteral},
@@ -4523,11 +4525,7 @@ pub fn op_open_ephemeral(
};
let conn = program.connection.upgrade().unwrap();
// Only memory and vfs IOs returns None, so cloning is safe
let io = match conn.pager.io.get_memory_io() {
Some(io) => io,
None => conn.pager.io.clone(),
};
let io = conn.pager.io.get_memory_io();
let file = io.open_file("", OpenFlags::Create, true)?;
let page_io = Arc::new(FileMemoryStorage::new(file));

View File

@@ -98,7 +98,7 @@ impl IO for SimulatorIO {
self.rng.borrow_mut().next_u64() as i64
}
fn get_memory_io(&self) -> Option<Arc<limbo_core::MemoryIO>> {
fn get_memory_io(&self) -> Arc<limbo_core::MemoryIO> {
todo!()
}
}