diff --git a/pageserver/src/lib.rs b/pageserver/src/lib.rs index 4a688d36d4..83f549d7e8 100644 --- a/pageserver/src/lib.rs +++ b/pageserver/src/lib.rs @@ -47,7 +47,7 @@ pub const COMPRESSED_STORAGE_FORMAT_VERSION: u16 = 4; /// Page image compression algorithm pub const NO_COMPRESSION: u8 = 0; -pub const LZ4_COMPRESSION: u8 = 0; +pub const LZ4_COMPRESSION: u8 = 1; pub const DEFAULT_PG_VERSION: u32 = 15; diff --git a/pageserver/src/tenant/blob_io.rs b/pageserver/src/tenant/blob_io.rs index c3cd337d0b..5b6ce25781 100644 --- a/pageserver/src/tenant/blob_io.rs +++ b/pageserver/src/tenant/blob_io.rs @@ -240,7 +240,7 @@ impl BlobWriter { pub async fn write_compressed_blob( &mut self, srcbuf: Bytes, - compress: bool, + new_format: bool, ) -> Result { let offset = self.offset; @@ -251,7 +251,9 @@ impl BlobWriter { let mut is_compressed = false; if len < 128 { // Short blob. Write a 1-byte length header - io_buf.put_u8(NO_COMPRESSION); + if new_format { + io_buf.put_u8(NO_COMPRESSION); + } io_buf.put_u8(len as u8); } else { // Write a 4-byte length header @@ -261,7 +263,7 @@ impl BlobWriter { format!("blob too large ({} bytes)", len), )); } - if compress && len == BLCKSZ as usize { + if new_format && len == BLCKSZ as usize { let compressed = lz4_flex::block::compress(&srcbuf); if compressed.len() < len { io_buf.put_u8(LZ4_COMPRESSION); @@ -271,12 +273,14 @@ impl BlobWriter { io_buf.extend_from_slice(&compressed[..]); is_compressed = true; } - if is_compressed { + } + if !is_compressed { + if new_format { io_buf.put_u8(NO_COMPRESSION); - let mut len_buf = (len as u32).to_be_bytes(); - len_buf[0] |= 0x80; - io_buf.extend_from_slice(&len_buf[..]); } + let mut len_buf = (len as u32).to_be_bytes(); + len_buf[0] |= 0x80; + io_buf.extend_from_slice(&len_buf[..]); } } let (io_buf, hdr_res) = self.write_all(io_buf).await;