src/backup/chunk_store.rs: use lz4 for compression

And depend on lz4 lib now.
This commit is contained in:
Dietmar Maurer 2019-02-25 07:26:40 +01:00
parent 2e05a1ca7d
commit 78216a5ab1
3 changed files with 16 additions and 18 deletions

View File

@ -39,3 +39,4 @@ md5 = "0.6"
base64 = "0.10" base64 = "0.10"
pam-sys = "0.5" pam-sys = "0.5"
pam = "0.7" pam = "0.7"
lz4 = "1.23"

2
debian/control vendored
View File

@ -5,6 +5,7 @@ Maintainer: Proxmox Support Team <support@proxmox.com>
Build-Depends: bash-completion, Build-Depends: bash-completion,
debhelper (>= 10), debhelper (>= 10),
libpam0g-dev, libpam0g-dev,
liblz4-dev,
pkg-config, pkg-config,
docutils-doc, docutils-doc,
Standards-Version: 3.9.5 Standards-Version: 3.9.5
@ -16,5 +17,6 @@ Depends: ${shlibs:Depends}, ${misc:Depends},
libjs-extjs (>= 6.0.1), libjs-extjs (>= 6.0.1),
fonts-font-awesome, fonts-font-awesome,
proxmox-widget-toolkit, proxmox-widget-toolkit,
liblz4-1,
Description: Proxmox Backup Server Description: Proxmox Backup Server
This is experimental code used to test Rust. This is experimental code used to test Rust.

View File

@ -1,6 +1,6 @@
use failure::*; use failure::*;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::io::Write; use std::io::{Read, Write};
use std::time::Duration; use std::time::Duration;
use openssl::sha; use openssl::sha;
@ -181,22 +181,10 @@ impl ChunkStore {
let digest_str = tools::digest_to_hex(&digest); let digest_str = tools::digest_to_hex(&digest);
chunk_path.push(&digest_str); chunk_path.push(&digest_str);
let mut f = std::fs::File::open(&chunk_path)?; let f = std::fs::File::open(&chunk_path)?;
let mut decoder = lz4::Decoder::new(f)?;
let stat = nix::sys::stat::fstat(f.as_raw_fd())?; decoder.read_to_end(buffer)?;
let size = stat.st_size as usize;
if buffer.capacity() < size {
let mut newsize = buffer.capacity();
while newsize < size { newsize = newsize << 1; }
let additional = newsize - buffer.len();
buffer.reserve_exact(additional);
}
unsafe { buffer.set_len(size); }
use std::io::Read;
f.read_exact(buffer.as_mut_slice())?;
Ok(()) Ok(())
} }
@ -332,8 +320,15 @@ impl ChunkStore {
let mut tmp_path = chunk_path.clone(); let mut tmp_path = chunk_path.clone();
tmp_path.set_extension("tmp"); tmp_path.set_extension("tmp");
let mut f = std::fs::File::create(&tmp_path)?;
f.write_all(chunk)?; let f = std::fs::File::create(&tmp_path)?;
// fixme: what is the fasted lz4 encoder available (see lzbench)?
let mut encoder = lz4::EncoderBuilder::new().level(1).build(f)?;
encoder.write_all(chunk)?;
let (_, encode_result) = encoder.finish();
encode_result?;
if let Err(err) = std::fs::rename(&tmp_path, &chunk_path) { if let Err(err) = std::fs::rename(&tmp_path, &chunk_path) {
if let Err(_) = std::fs::remove_file(&tmp_path) { /* ignore */ } if let Err(_) = std::fs::remove_file(&tmp_path) { /* ignore */ }