From f83a71ca6a8cfa90d15a08025a20d49ad26f0238 Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Thu, 5 Oct 2023 18:13:54 +0200 Subject: [PATCH] WIP --- pageserver/src/tenant/block_io.rs | 40 +++++++++---------- .../src/tenant/storage_layer/delta_layer.rs | 18 ++++----- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/pageserver/src/tenant/block_io.rs b/pageserver/src/tenant/block_io.rs index 0617017528..6d51a1d616 100644 --- a/pageserver/src/tenant/block_io.rs +++ b/pageserver/src/tenant/block_io.rs @@ -21,40 +21,40 @@ pub trait BlockReader { /// /// A cursor caches the last accessed page, allowing for faster /// access if the same block is accessed repeatedly. - fn block_cursor(&self) -> BlockCursor<'_>; + fn block_cursor(&self) -> BlockCursor<'_, '_>; } impl BlockReader for &B where B: BlockReader, { - fn block_cursor(&self) -> BlockCursor<'_> { + fn block_cursor(&self) -> BlockCursor<'_, '_> { (*self).block_cursor() } } /// Reference to an in-memory copy of an immutable on-disk block. -pub enum BlockLease<'a> { - PageReadGuard(PageReadGuard<'static>), +pub enum BlockLease<'c, 'a> { + PageReadGuard(PageReadGuard<'c, 'static>), EphemeralFileMutableTail(&'a [u8; PAGE_SZ]), #[cfg(test)] Arc(std::sync::Arc<[u8; PAGE_SZ]>), } -impl From> for BlockLease<'static> { - fn from(value: PageReadGuard<'static>) -> BlockLease<'static> { +impl<'c, 'a> From> for BlockLease<'c, 'a> { + fn from(value: PageReadGuard<'c, 'a>) -> BlockLease<'c, 'a> { BlockLease::PageReadGuard(value) } } #[cfg(test)] -impl<'a> From> for BlockLease<'a> { +impl<'c, 'a> From> for BlockLease<'c, 'a> { fn from(value: std::sync::Arc<[u8; PAGE_SZ]>) -> Self { BlockLease::Arc(value) } } -impl<'a> Deref for BlockLease<'a> { +impl<'c, 'a> Deref for BlockLease<'c, 'a> { type Target = [u8; PAGE_SZ]; fn deref(&self) -> &Self::Target { @@ -71,7 +71,7 @@ impl<'a> Deref for BlockLease<'a> { /// similar to using traits for this purpose. /// /// Unlike traits, we also support the read function to be async though. -pub(crate) enum BlockReaderRef<'a> { +pub(crate) enum BlockReaderRef<'c, 'a> { FileBlockReader(&'a FileBlockReader), EphemeralFile(&'a EphemeralFile), Adapter(Adapter<&'a DeltaLayerInner>), @@ -81,13 +81,13 @@ pub(crate) enum BlockReaderRef<'a> { VirtualFile(&'a VirtualFile), } -impl<'a> BlockReaderRef<'a> { +impl<'c, 'a> BlockReaderRef<'c, 'a> { #[inline(always)] async fn read_blk( &self, blknum: u32, - ctx: &RequestContext, - ) -> Result { + ctx: &'c RequestContext, + ) -> Result, std::io::Error> { use BlockReaderRef::*; match self { FileBlockReader(r) => r.read_blk(blknum, ctx).await, @@ -120,12 +120,12 @@ impl<'a> BlockReaderRef<'a> { /// // do stuff with 'buf' /// ``` /// -pub struct BlockCursor<'a> { - reader: BlockReaderRef<'a>, +pub struct BlockCursor<'c, 'a> { + reader: BlockReaderRef<'c, 'a>, } -impl<'a> BlockCursor<'a> { - pub(crate) fn new(reader: BlockReaderRef<'a>) -> Self { +impl<'c, 'a> BlockCursor<'c, 'a> { + pub(crate) fn new(reader: BlockReaderRef<'c, 'a>) -> Self { BlockCursor { reader } } // Needed by cli @@ -180,11 +180,11 @@ impl FileBlockReader { /// Returns a "lease" object that can be used to /// access to the contents of the page. (For the page cache, the /// lease object represents a lock on the buffer.) - pub async fn read_blk( + pub async fn read_blk<'c>( &self, blknum: u32, - ctx: &RequestContext, - ) -> Result { + ctx: &'c RequestContext, + ) -> Result, std::io::Error> { let cache = page_cache::get(); match cache .read_immutable_buf(self.file_id, blknum, ctx) @@ -206,7 +206,7 @@ impl FileBlockReader { } impl BlockReader for FileBlockReader { - fn block_cursor(&self) -> BlockCursor<'_> { + fn block_cursor(&self) -> BlockCursor<'_, '_> { BlockCursor::new(BlockReaderRef::FileBlockReader(self)) } } diff --git a/pageserver/src/tenant/storage_layer/delta_layer.rs b/pageserver/src/tenant/storage_layer/delta_layer.rs index 8f0f3780c2..538d560298 100644 --- a/pageserver/src/tenant/storage_layer/delta_layer.rs +++ b/pageserver/src/tenant/storage_layer/delta_layer.rs @@ -320,7 +320,7 @@ impl DeltaLayer { let keys = DeltaLayerInner::load_keys(&inner, ctx).await?; // A subroutine to dump a single blob - async fn dump_blob(val: ValueRef<'_>, ctx: &RequestContext) -> Result { + async fn dump_blob(val: ValueRef<'_, '_>, ctx: &RequestContext) -> Result { let buf = val.reader.read_blob(val.blob_ref.pos(), ctx).await?; let val = Value::des(&buf)?; let desc = match val { @@ -549,7 +549,7 @@ impl DeltaLayer { /// Loads all keys stored in the layer. Returns key, lsn, value size and value reference. /// /// The value can be obtained via the [`ValueRef::load`] function. - pub(crate) async fn load_keys(&self, ctx: &RequestContext) -> Result>> { + pub(crate) async fn load_keys<'c>(&self, ctx: &RequestContext) -> Result>> { let inner = self .load(LayerAccessKind::KeyIter, ctx) .await @@ -971,7 +971,7 @@ impl DeltaLayerInner { pub(super) async fn load_keys<'a, 'b, T: AsRef + Clone>( this: &'a T, ctx: &'b RequestContext, - ) -> Result>> { + ) -> Result>> { let dl = this.as_ref(); let file = &dl.file; @@ -1023,24 +1023,24 @@ impl DeltaLayerInner { } /// A set of data associated with a delta layer key and its value -pub struct DeltaEntry<'a> { +pub struct DeltaEntry<'c, 'a> { pub key: Key, pub lsn: Lsn, /// Size of the stored value pub size: u64, /// Reference to the on-disk value - pub val: ValueRef<'a>, + pub val: ValueRef<'c, 'a>, } /// Reference to an on-disk value -pub struct ValueRef<'a> { +pub struct ValueRef<'c, 'a> { blob_ref: BlobRef, - reader: BlockCursor<'a>, + reader: BlockCursor<'c, 'a>, } -impl<'a> ValueRef<'a> { +impl<'c, 'a> ValueRef<'c, 'a> { /// Loads the value from disk - pub async fn load(&self, ctx: &RequestContext) -> Result { + pub async fn load(&self, ctx: &'c RequestContext) -> Result { // theoretically we *could* record an access time for each, but it does not really matter let buf = self.reader.read_blob(self.blob_ref.pos(), ctx).await?; let val = Value::des(&buf)?;