From 2eb8b428cc51dea11d9578e30b0144a0027a05d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arpad=20M=C3=BCller?= Date: Fri, 7 Jun 2024 22:12:04 +0200 Subject: [PATCH] Also support the generation-less legacy naming scheme --- pageserver/ctl/src/layers.rs | 29 ++++++++++++++++++----------- pageserver/src/tenant/blob_io.rs | 27 +++++++++++++-------------- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/pageserver/ctl/src/layers.rs b/pageserver/ctl/src/layers.rs index b254305376..3c7bc935a0 100644 --- a/pageserver/ctl/src/layers.rs +++ b/pageserver/ctl/src/layers.rs @@ -312,17 +312,24 @@ pub(crate) async fn main(cmd: &LayerCmd) -> Result<()> { let Some(file_name) = file_key.object_name() else { continue; }; - // Split off the final part. Sometimes this cuts off actually important pieces in case of legacy layer files, but usually it doesn't. - let Some(file_without_generation) = file_name.rsplit_once('-') else { - continue; - }; - let Ok(LayerName::Image(_layer_file_name)) = - LayerName::from_str(file_without_generation.0) - else { - // Skipping because it's either not a layer or an image layer - //println!("object {file_name}: not an image layer"); - continue; - }; + match LayerName::from_str(file_name) { + Ok(LayerName::Delta(_)) => continue, + Ok(LayerName::Image(_)) => (), + Err(_e) => { + // Split off the final part. We ensured above that this is not turning a + // generation-less delta layer file name into an image layer file name. + let Some(file_without_generation) = file_name.rsplit_once('-') else { + continue; + }; + let Ok(LayerName::Image(_layer_file_name)) = + LayerName::from_str(file_without_generation.0) + else { + // Skipping because it's either not a layer or an image layer + //println!("object {file_name}: not an image layer"); + continue; + }; + } + } let json_file_path = layers_dir.join(format!("{file_name}.json")); if tokio::fs::try_exists(&json_file_path).await? { //println!("object {file_name}: report already created"); diff --git a/pageserver/src/tenant/blob_io.rs b/pageserver/src/tenant/blob_io.rs index f3b33a6c1c..ec22114c73 100644 --- a/pageserver/src/tenant/blob_io.rs +++ b/pageserver/src/tenant/blob_io.rs @@ -269,20 +269,19 @@ impl BlobWriter { use ImageCompressionAlgorithm::*; let (high_bit_mask, len_written, srcbuf) = match algorithm { Some(ZstdLow | Zstd | ZstdHigh) => { - let mut encoder = - if matches!(algorithm, Some(ZstdLow)) { - async_compression::tokio::write::ZstdEncoder::with_quality( - Vec::new(), - Level::Precise(1), - ) - } else if matches!(algorithm, Some(ZstdHigh)) { - async_compression::tokio::write::ZstdEncoder::with_quality( - Vec::new(), - Level::Precise(6), - ) - } else { - async_compression::tokio::write::ZstdEncoder::new(Vec::new()) - }; + let mut encoder = if matches!(algorithm, Some(ZstdLow)) { + async_compression::tokio::write::ZstdEncoder::with_quality( + Vec::new(), + Level::Precise(1), + ) + } else if matches!(algorithm, Some(ZstdHigh)) { + async_compression::tokio::write::ZstdEncoder::with_quality( + Vec::new(), + Level::Precise(6), + ) + } else { + async_compression::tokio::write::ZstdEncoder::new(Vec::new()) + }; let slice = srcbuf.slice(..); encoder.write_all(&slice[..]).await.unwrap(); encoder.flush().await.unwrap();