fix uring Sync,Sync unsafe impl

This commit is contained in:
Pere Diaz Bou
2025-03-04 17:44:30 +00:00
parent 47cd54a7fe
commit d1c7d758c4
2 changed files with 12 additions and 5 deletions

View File

@@ -8,6 +8,7 @@ use std::io::ErrorKind;
use std::os::fd::AsFd;
use std::os::unix::io::AsRawFd;
use std::rc::Rc;
use std::sync::Arc;
use thiserror::Error;
use tracing::{debug, trace};
@@ -35,6 +36,9 @@ pub struct UringIO {
inner: Rc<RefCell<InnerUringIO>>,
}
unsafe impl Send for UringIO {}
unsafe impl Sync for UringIO {}
struct WrappedIOUring {
ring: io_uring::IoUring,
pending_ops: usize,
@@ -132,7 +136,7 @@ impl WrappedIOUring {
}
impl IO for UringIO {
fn open_file(&self, path: &str, flags: OpenFlags, direct: bool) -> Result<Rc<dyn File>> {
fn open_file(&self, path: &str, flags: OpenFlags, direct: bool) -> Result<Arc<dyn File>> {
trace!("open_file(path = {})", path);
let file = std::fs::File::options()
.read(true)
@@ -148,7 +152,7 @@ impl IO for UringIO {
Err(error) => debug!("Error {error:?} returned when setting O_DIRECT flag to read file. The performance of the system may be affected"),
}
}
let uring_file = Rc::new(UringFile {
let uring_file = Arc::new(UringFile {
io: self.inner.clone(),
file,
});
@@ -203,6 +207,9 @@ pub struct UringFile {
file: std::fs::File,
}
unsafe impl Send for UringFile {}
unsafe impl Sync for UringFile {}
impl File for UringFile {
fn lock_file(&self, exclusive: bool) -> Result<()> {
let fd = self.file.as_fd();
@@ -260,7 +267,7 @@ impl File for UringFile {
Ok(())
}
fn pwrite(&self, pos: usize, buffer: Rc<RefCell<crate::Buffer>>, c: Completion) -> Result<()> {
fn pwrite(&self, pos: usize, buffer: Arc<RefCell<crate::Buffer>>, c: Completion) -> Result<()> {
let mut io = self.io.borrow_mut();
let fd = io_uring::types::Fd(self.file.as_raw_fd());
let write = {

View File

@@ -172,7 +172,7 @@ impl Database {
buffer_pool,
)?);
let conn = Rc::new(Connection {
db: self.clone(),
_db: self.clone(),
pager: pager.clone(),
schema: self.schema.clone(),
header: self.header.clone(),
@@ -239,7 +239,7 @@ pub fn maybe_init_database_file(file: &Arc<dyn File>, io: &Arc<dyn IO>) -> Resul
}
pub struct Connection {
db: Arc<Database>,
_db: Arc<Database>,
pager: Rc<Pager>,
schema: Arc<RwLock<Schema>>,
header: Arc<Mutex<DatabaseHeader>>,