Emable iomage layer compression by default

This commit is contained in:
Konstantin Knizhnik
2024-03-12 07:58:57 +02:00
parent 8c7136b057
commit 8c60359ae5
3 changed files with 4 additions and 10 deletions

View File

@@ -237,7 +237,7 @@ impl<const BUFFERED: bool> BlobWriter<BUFFERED> {
(src_buf, Ok(()))
}
pub async fn write_compressed_blob(&mut self, srcbuf: Bytes) -> Result<u64, Error> {
pub async fn write_compressed_blob(&mut self, srcbuf: Bytes, compress: bool) -> Result<u64, Error> {
let offset = self.offset;
let len = srcbuf.len();
@@ -257,7 +257,7 @@ impl<const BUFFERED: bool> BlobWriter<BUFFERED> {
format!("blob too large ({} bytes)", len),
));
}
if len == BLCKSZ as usize {
if compress && len == BLCKSZ as usize {
let compressed = lz4_flex::block::compress(&srcbuf);
if compressed.len() < len {
io_buf.put_u8(LZ4_COMPRESSION);

View File

@@ -546,7 +546,7 @@ impl Default for TenantConf {
max_lsn_wal_lag: NonZeroU64::new(DEFAULT_MAX_WALRECEIVER_LSN_WAL_LAG)
.expect("cannot parse default max walreceiver Lsn wal lag"),
trace_read_requests: false,
compress_image_layer: false,
compress_image_layer: true,
eviction_policy: EvictionPolicy::NoEviction,
min_resident_size_override: None,
evictions_low_residence_duration_metric_threshold: humantime::parse_duration(

View File

@@ -668,13 +668,7 @@ impl ImageLayerWriterInner {
///
async fn put_image(&mut self, key: Key, img: Bytes) -> anyhow::Result<()> {
ensure!(self.key_range.contains(&key));
let off = if self.compression {
self.blob_writer.write_compressed_blob(img).await?
} else {
let (_img, res) = self.blob_writer.write_blob(img).await;
// TODO: re-use the buffer for `img` further upstack
res?
};
let off = self.blob_writer.write_compressed_blob(img, self.compression).await?;
let mut keybuf: [u8; KEY_SIZE] = [0u8; KEY_SIZE];
key.write_to_byte_slice(&mut keybuf);
self.tree.append(&keybuf, off)?;