From 41547582aba869f81086922e53178b38f6fbfcf6 Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Mon, 11 Dec 2023 17:21:29 +0000 Subject: [PATCH] Revert "got meaningful error:" This reverts commit c4ddc6abafcb1bdc8fc9fd00a57fc0d60442866a. --- repro-problem/src/main.rs | 8 ++-- repro-problem/src/virtual_file.rs | 75 ++++++++++++++++--------------- 2 files changed, 42 insertions(+), 41 deletions(-) diff --git a/repro-problem/src/main.rs b/repro-problem/src/main.rs index 17893c13a1..ee665c98c3 100644 --- a/repro-problem/src/main.rs +++ b/repro-problem/src/main.rs @@ -4,8 +4,8 @@ mod virtual_file; #[tokio::main] async fn main() { - let file = VirtualFile::open(camino::Utf8Path::new("foo")) - .await - .unwrap(); - file.read_exact_at(vec![0; 8], 0).await; + + let file = VirtualFile::open(camino::Utf8Path::new("foo")).await.unwrap(); + file.read_exact_at().await; + } diff --git a/repro-problem/src/virtual_file.rs b/repro-problem/src/virtual_file.rs index 79d84ba821..d9e8d500ba 100644 --- a/repro-problem/src/virtual_file.rs +++ b/repro-problem/src/virtual_file.rs @@ -10,7 +10,7 @@ //! This is similar to PostgreSQL's virtual file descriptor facility in //! src/backend/storage/file/fd.c //! -// use crate::page_cache::PageWriteGuard; +use crate::page_cache::PageWriteGuard; use camino::{Utf8Path, Utf8PathBuf}; use once_cell::sync::OnceCell; use std::fs::{self, File}; @@ -574,47 +574,48 @@ impl VirtualFile { // } pub async fn read_exact_at( &self, - buf: Vec, + write_guard: PageWriteGuard<'static>, offset: u64, - ) -> Result, Error> { + ) -> Result, Error> { + let write_guard: PageWriteGuard<'static> = write_guard; let file_guard: FileGuard<'static> = self.lock_file().await?; let system = tokio_epoll_uring::thread_local_system().await; - // struct PageWriteGuardBuf { - // buf: PageWriteGuard<'static>, - // init_up_to: usize, - // } - // unsafe impl tokio_epoll_uring::IoBuf for PageWriteGuardBuf { - // fn stable_ptr(&self) -> *const u8 { - // self.buf.as_ptr() - // } - // fn bytes_init(&self) -> usize { - // self.init_up_to - // } - // fn bytes_total(&self) -> usize { - // self.buf.len() - // } - // } - // unsafe impl tokio_epoll_uring::IoBufMut for PageWriteGuardBuf { - // fn stable_mut_ptr(&mut self) -> *mut u8 { - // self.buf.as_mut_ptr() - // } + struct PageWriteGuardBuf { + buf: PageWriteGuard<'static>, + init_up_to: usize, + } + unsafe impl tokio_epoll_uring::IoBuf for PageWriteGuardBuf { + fn stable_ptr(&self) -> *const u8 { + self.buf.as_ptr() + } + fn bytes_init(&self) -> usize { + self.init_up_to + } + fn bytes_total(&self) -> usize { + self.buf.len() + } + } + unsafe impl tokio_epoll_uring::IoBufMut for PageWriteGuardBuf { + fn stable_mut_ptr(&mut self) -> *mut u8 { + self.buf.as_mut_ptr() + } - // unsafe fn set_init(&mut self, pos: usize) { - // assert!(pos <= self.buf.len()); - // self.init_up_to = pos; - // } - // } - // let buf = PageWriteGuardBuf { - // buf: write_guard, - // init_up_to: 0, - // }; - let ((_, write_guard), res) = system.read(file_guard, offset, buf).await; - // let PageWriteGuardBuf { - // buf: write_guard, - // init_up_to, - // } = buf; + unsafe fn set_init(&mut self, pos: usize) { + assert!(pos <= self.buf.len()); + self.init_up_to = pos; + } + } + let buf = PageWriteGuardBuf { + buf: write_guard, + init_up_to: 0, + }; + let ((_, buf), res) = system.read(file_guard, offset, buf).await; + let PageWriteGuardBuf { + buf: write_guard, + init_up_to, + } = buf; if let Ok(num_read) = res { - // assert!(init_up_to == num_read); // TODO need to deal with short reads here + assert!(init_up_to == num_read); // TODO need to deal with short reads here } res.map(|_| write_guard) .map_err(|e| Error::new(ErrorKind::Other, e))