From e74a812850fdf057ce413df7ee61617f1ad2c1db Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Wed, 24 Mar 2021 21:50:35 +0200 Subject: [PATCH] Handle WAL redo errors more gracefully. Don't panic, but return an error to the caller, all the way up to the processing node instance that did the GetPage@LSN call. --- launch.sh | 0 src/page_cache.rs | 9 ++++++++- src/page_service.rs | 25 ++++++++++++++++++++----- 3 files changed, 28 insertions(+), 6 deletions(-) mode change 100644 => 100755 launch.sh diff --git a/launch.sh b/launch.sh old mode 100644 new mode 100755 diff --git a/src/page_cache.rs b/src/page_cache.rs index 7e1b1f50b6..997dff98cd 100644 --- a/src/page_cache.rs +++ b/src/page_cache.rs @@ -255,7 +255,14 @@ pub fn get_page_at_lsn(tag: BufferTag, lsn: u64) -> Result while entry_content.apply_pending { entry_content = entry_rc.walredo_condvar.wait(entry_content).unwrap(); } - page_img = entry_content.page_image.as_ref().unwrap().clone(); + + // We should now have a page image. If we don't, it means that WAL redo + // failed to reconstruct it. WAL redo should've logged that error already. + page_img = match &entry_content.page_image { + Some(p) => p.clone(), + None => { return Err("could not apply WAL to reconstruct page image".into()); } + }; + } else { // No base image, and no WAL record. Huh? return Err(format!("no page image or WAL record for requested page"))?; diff --git a/src/page_service.rs b/src/page_service.rs index f811fb260a..8e62a4cf98 100644 --- a/src/page_service.rs +++ b/src/page_service.rs @@ -504,11 +504,26 @@ impl Connection { }; let inf_lsn = 0xffff_ffff_ffff_eeee; - let msg = BeMessage::ZenithReadResponse(ZenithReadResponse { - ok: true, - n_blocks: 0, - page: page_cache::get_page_at_lsn(buf_tag, inf_lsn).unwrap() - }); + + let msg; + { + let p = page_cache::get_page_at_lsn(buf_tag, inf_lsn); + if p.is_ok() { + msg = ZenithReadResponse { + ok: true, + n_blocks: 0, + page: p.unwrap() + }; + } else { + const ZERO_PAGE:[u8; 8192] = [0; 8192]; + msg = ZenithReadResponse { + ok: false, + n_blocks: 0, + page: Bytes::from_static(&ZERO_PAGE) + } + } + } + let msg = BeMessage::ZenithReadResponse(msg); self.write_message(&msg).await?