mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-15 17:32:56 +00:00
Add ZstdHigh compression mode
This commit is contained in:
@@ -470,6 +470,7 @@ pub enum CompactionAlgorithm {
|
||||
#[strum(serialize_all = "kebab-case")]
|
||||
pub enum ImageCompressionAlgorithm {
|
||||
Zstd,
|
||||
ZstdHigh,
|
||||
LZ4,
|
||||
}
|
||||
|
||||
|
||||
@@ -303,6 +303,8 @@ pub(crate) async fn main(cmd: &LayerCmd) -> Result<()> {
|
||||
|
||||
println!("Listing gave {} keys", files_list.keys.len());
|
||||
|
||||
tokio::fs::create_dir_all(&layers_dir).await?;
|
||||
|
||||
let semaphore = Arc::new(Semaphore::new(parallelism.unwrap_or(1) as usize));
|
||||
|
||||
let mut tasks = JoinSet::new();
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
//! len < 128: 0XXXXXXX
|
||||
//! len >= 128: 1XXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
|
||||
//!
|
||||
use async_compression::Level;
|
||||
use bytes::{BufMut, BytesMut};
|
||||
use pageserver_api::models::ImageCompressionAlgorithm;
|
||||
use tokio::io::AsyncWriteExt;
|
||||
@@ -266,9 +267,16 @@ impl<const BUFFERED: bool> BlobWriter<BUFFERED> {
|
||||
const ZSTD: u8 = UNCOMPRESSED | 0x10;
|
||||
const LZ4: u8 = UNCOMPRESSED | 0x20;
|
||||
let (high_bit_mask, len_written, srcbuf) = match algorithm {
|
||||
Some(ImageCompressionAlgorithm::Zstd) => {
|
||||
Some(ImageCompressionAlgorithm::Zstd | ImageCompressionAlgorithm::ZstdHigh) => {
|
||||
let mut encoder =
|
||||
async_compression::tokio::write::ZstdEncoder::new(Vec::new());
|
||||
if matches!(algorithm, Some(ImageCompressionAlgorithm::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();
|
||||
|
||||
@@ -382,6 +382,7 @@ impl ImageLayer {
|
||||
let image_compressions = [
|
||||
None,
|
||||
Some(ImageCompressionAlgorithm::Zstd),
|
||||
Some(ImageCompressionAlgorithm::ZstdHigh),
|
||||
Some(ImageCompressionAlgorithm::LZ4),
|
||||
];
|
||||
let mut stats = Vec::new();
|
||||
|
||||
Reference in New Issue
Block a user