From 9012a18fa1f5f52288b5ee0519ed18215b228dee Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Sat, 14 Sep 2024 14:18:39 +0000 Subject: [PATCH] Revert "WIP" This reverts commit 709a6ad29ba528a84f7fb461a345df4cb6f5fc00. --- pageserver/src/tenant/storage_layer.rs | 38 ++++++++++++++++++-------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/pageserver/src/tenant/storage_layer.rs b/pageserver/src/tenant/storage_layer.rs index 17e11a0ce3..a79487b9a5 100644 --- a/pageserver/src/tenant/storage_layer.rs +++ b/pageserver/src/tenant/storage_layer.rs @@ -88,13 +88,17 @@ pub(crate) struct VectoredValueReconstructState { Lsn, tokio::sync::oneshot::Receiver>, )>, + pub(crate) img: Option<( + Lsn, + tokio::sync::oneshot::Receiver>, + )>, pub(crate) situation: ValueReconstructSituation, } impl VectoredValueReconstructState { fn get_cached_lsn(&self) -> Option { - None + self.img.as_ref().map(|img| img.0) } } @@ -104,7 +108,6 @@ pub(crate) async fn convert( ) -> Result { let mut to = ValueReconstructState::default(); - let mut inited = false; for (lsn, fut) in from.records { match fut.await { Ok(res) => match res { @@ -112,18 +115,13 @@ pub(crate) async fn convert( let value = Value::des(&bytes) .map_err(|err| PageReconstructError::Other(err.into()))?; - match (inited, value) { - (true, _) => { - panic!("multiple will_init records, plan was wrong"); - } - (false, Value::WalRecord(rec)) => { - inited = rec.will_init(); + match value { + Value::WalRecord(rec) => { to.records.push((lsn, rec)); - } - (false, Value::Image(img)) => { + }, + Value::Image(img) => { assert!(to.img.is_none()); to.img = Some((lsn, img)); - inited = true; } } } @@ -136,7 +134,23 @@ pub(crate) async fn convert( } } } - // do not assert inited=true here because it's kinda legitimate to ask for key that doesn't exist + + if to.img.is_none() && from.img.is_some() { + let (lsn, fut) = from.img.expect("Has an image"); + match fut.await { + Ok(res) => match res { + Ok(bytes) => { + to.img = Some((lsn, bytes)); + } + Err(err) => { + return Err(PageReconstructError::Other(err.into())); + } + }, + Err(err) => { + return Err(PageReconstructError::Other(err.into())); + } + } + } Ok(to) }