move chunk_stat, read_chunk to pbs-datastore

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller
2021-07-08 09:17:28 +02:00
parent ae24382634
commit e64f38cb6b
8 changed files with 72 additions and 56 deletions

View File

@ -0,0 +1,43 @@
pub struct ChunkStat {
pub size: u64,
pub compressed_size: u64,
pub disk_size: u64,
pub chunk_count: usize,
pub duplicate_chunks: usize,
start_time: std::time::SystemTime,
}
impl ChunkStat {
pub fn new(size: u64) -> Self {
ChunkStat {
size,
compressed_size: 0,
disk_size: 0,
chunk_count: 0,
duplicate_chunks: 0,
start_time: std::time::SystemTime::now(),
}
}
}
impl std::fmt::Debug for ChunkStat {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
let avg = ((self.size as f64)/(self.chunk_count as f64)) as usize;
let compression = (self.compressed_size*100)/(self.size as u64);
let rate = (self.disk_size*100)/(self.size as u64);
let elapsed = self.start_time.elapsed().unwrap();
let elapsed = (elapsed.as_secs() as f64) +
(elapsed.subsec_millis() as f64)/1000.0;
let write_speed = ((self.size as f64)/(1024.0*1024.0))/elapsed;
write!(f, "Size: {}, average chunk size: {}, compression rate: {}%, disk_size: {} ({}%), speed: {:.2} MB/s",
self.size, avg, compression, self.disk_size, rate, write_speed)
}
}

View File

@ -182,6 +182,7 @@ pub mod backup_info;
pub mod catalog;
pub mod checksum_reader;
pub mod checksum_writer;
pub mod chunk_stat;
pub mod chunk_store;
pub mod chunker;
pub mod crypt_config;
@ -194,6 +195,7 @@ pub mod file_formats;
pub mod index;
pub mod key_derivation;
pub mod manifest;
pub mod read_chunk;
pub mod task;
pub use backup_info::{BackupDir, BackupGroup, BackupInfo};

View File

@ -0,0 +1,29 @@
use std::future::Future;
use std::pin::Pin;
use anyhow::Error;
use crate::data_blob::DataBlob;
/// The ReadChunk trait allows reading backup data chunks (local or remote)
pub trait ReadChunk {
/// Returns the encoded chunk data
fn read_raw_chunk(&self, digest: &[u8; 32]) -> Result<DataBlob, Error>;
/// Returns the decoded chunk data
fn read_chunk(&self, digest: &[u8; 32]) -> Result<Vec<u8>, Error>;
}
pub trait AsyncReadChunk: Send {
/// Returns the encoded chunk data
fn read_raw_chunk<'a>(
&'a self,
digest: &'a [u8; 32],
) -> Pin<Box<dyn Future<Output = Result<DataBlob, Error>> + Send + 'a>>;
/// Returns the decoded chunk data
fn read_chunk<'a>(
&'a self,
digest: &'a [u8; 32],
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, Error>> + Send + 'a>>;
}