From 10ee8f79816c59b93ae77536004a2c9d1c3964ce Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Tue, 29 Aug 2023 11:04:16 +0000 Subject: [PATCH] FileBlockReaderFile is not needed, was doing all the sync IO --- pageserver/src/tenant/block_io.rs | 24 +++++++++++++----------- pageserver/src/virtual_file.rs | 5 ++++- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/pageserver/src/tenant/block_io.rs b/pageserver/src/tenant/block_io.rs index a15f77c7de..fd13227843 100644 --- a/pageserver/src/tenant/block_io.rs +++ b/pageserver/src/tenant/block_io.rs @@ -74,7 +74,7 @@ impl<'a> Deref for BlockLease<'a> { /// Unlike traits, we also support the read function to be async though. pub(crate) enum BlockReaderRef<'a> { FileBlockReaderVirtual(&'a FileBlockReader), - FileBlockReaderFile(&'a FileBlockReader), + // FileBlockReaderFile(&'a FileBlockReader), EphemeralFile(&'a EphemeralFile), Adapter(Adapter<&'a DeltaLayerInner>), #[cfg(test)] @@ -87,7 +87,7 @@ impl<'a> BlockReaderRef<'a> { use BlockReaderRef::*; match self { FileBlockReaderVirtual(r) => r.read_blk(blknum).await, - FileBlockReaderFile(r) => r.read_blk(blknum).await, + // FileBlockReaderFile(r) => r.read_blk(blknum).await, EphemeralFile(r) => r.read_blk(blknum).await, Adapter(r) => r.read_blk(blknum).await, #[cfg(test)] @@ -158,13 +158,15 @@ impl FileBlockReader { } } +use crate::page_cache::PageWriteGuard; + macro_rules! impls { (FileBlockReader<$ty:ty>) => { impl FileBlockReader<$ty> { /// Read a page from the underlying file into given buffer. - fn fill_buffer(&self, buf: &mut [u8], blkno: u32) -> Result<(), std::io::Error> { + async fn fill_buffer(&self, buf: PageWriteGuard<'static>, blkno: u32) -> Result, std::io::Error> { assert!(buf.len() == PAGE_SZ); - self.file.read_exact_at(buf, blkno as u64 * PAGE_SZ as u64) + self.file.read_exact_at_async(buf, blkno as u64 * PAGE_SZ as u64).await } /// Read a block. /// @@ -187,7 +189,7 @@ macro_rules! impls { ReadBufResult::Found(guard) => break Ok(guard.into()), ReadBufResult::NotFound(mut write_guard) => { // Read the page from disk into the buffer - self.fill_buffer(write_guard.deref_mut(), blknum)?; + let mut write_guard = self.fill_buffer(write_guard, blknum).await?; write_guard.mark_valid(); // Swap for read lock @@ -200,14 +202,14 @@ macro_rules! impls { }; } -impls!(FileBlockReader); +// impls!(FileBlockReader); impls!(FileBlockReader); -impl BlockReader for FileBlockReader { - fn block_cursor(&self) -> BlockCursor<'_> { - BlockCursor::new(BlockReaderRef::FileBlockReaderFile(self)) - } -} +// impl BlockReader for FileBlockReader { +// fn block_cursor(&self) -> BlockCursor<'_> { +// BlockCursor::new(BlockReaderRef::FileBlockReaderFile(self)) +// } +// } impl BlockReader for FileBlockReader { fn block_cursor(&self) -> BlockCursor<'_> { diff --git a/pageserver/src/virtual_file.rs b/pageserver/src/virtual_file.rs index 197e13d19a..79de388cc2 100644 --- a/pageserver/src/virtual_file.rs +++ b/pageserver/src/virtual_file.rs @@ -261,7 +261,10 @@ impl VirtualFile { } fn read_at(&self, buf: &mut [u8], offset: u64) -> Result { - let result = self.with_file("read", |file| file.read_at(buf, offset))?; + let result = self.with_file("read", |file| { + tracing::info!("sync read\n{}", std::backtrace::Backtrace::force_capture()); + file.read_at(buf, offset) + })?; if let Ok(size) = result { STORAGE_IO_SIZE .with_label_values(&["read", &self.tenant_id, &self.timeline_id])