]> git.proxmox.com Git - proxmox-backup.git/commitdiff
move chunk_stat, read_chunk to pbs-datastore
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Thu, 8 Jul 2021 07:17:28 +0000 (09:17 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Fri, 9 Jul 2021 08:40:14 +0000 (10:40 +0200)
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
pbs-datastore/src/chunk_stat.rs [new file with mode: 0644]
pbs-datastore/src/lib.rs
pbs-datastore/src/read_chunk.rs [new file with mode: 0644]
src/backup/cached_chunk_reader.rs
src/backup/chunk_stat.rs [deleted file]
src/backup/dynamic_index.rs
src/backup/fixed_index.rs
src/backup/mod.rs
src/backup/read_chunk.rs

diff --git a/pbs-datastore/src/chunk_stat.rs b/pbs-datastore/src/chunk_stat.rs
new file mode 100644 (file)
index 0000000..7ae6689
--- /dev/null
@@ -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)
+    }
+}
index cae66905cf73a7cde73fddf4aff845357a142a60..3a5b15a99d4a4b8f1fcd48deb8c96b283b39f2db 100644 (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};
diff --git a/pbs-datastore/src/read_chunk.rs b/pbs-datastore/src/read_chunk.rs
new file mode 100644 (file)
index 0000000..c04a743
--- /dev/null
@@ -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>>;
+}
index c9ca4773aa4d2f62ff8fc0dc3268dd19be3675cb..3798ae4a746ae0263d311c23047a2b214979c23c 100644 (file)
@@ -1,20 +1,22 @@
 //! An async and concurrency safe data reader backed by a local LRU cache.
 
-use anyhow::Error;
-use futures::future::Future;
-use futures::ready;
-use tokio::io::{AsyncRead, AsyncSeek, ReadBuf};
-
+use std::future::Future;
 use std::io::SeekFrom;
 use std::pin::Pin;
 use std::sync::Arc;
 use std::task::{Context, Poll};
 
-use super::{AsyncReadChunk, IndexFile};
-use crate::tools::async_lru_cache::{AsyncCacher, AsyncLruCache};
+use anyhow::Error;
+use futures::ready;
+use tokio::io::{AsyncRead, AsyncSeek, ReadBuf};
+
 use proxmox::io_format_err;
 use proxmox::sys::error::io_err_other;
 
+use pbs_datastore::read_chunk::AsyncReadChunk;
+use super::IndexFile;
+use crate::tools::async_lru_cache::{AsyncCacher, AsyncLruCache};
+
 struct AsyncChunkCacher<T> {
     reader: Arc<T>,
 }
diff --git a/src/backup/chunk_stat.rs b/src/backup/chunk_stat.rs
deleted file mode 100644 (file)
index 7ae6689..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-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)
-    }
-}
index 8321b295a3c1841068621b71f7e143367cd13ba0..4bba6a29440fa578d749fe080789838f492d9c82 100644 (file)
@@ -14,14 +14,13 @@ use proxmox::tools::uuid::Uuid;
 use proxmox::tools::mmap::Mmap;
 use pxar::accessor::{MaybeReady, ReadAt, ReadAtOperation};
 
-use super::chunk_stat::ChunkStat;
-use super::chunk_store::ChunkStore;
-use super::index::ChunkReadInfo;
-use super::read_chunk::ReadChunk;
-use super::Chunker;
-use super::IndexFile;
-use super::{DataBlob, DataChunkBuilder};
-use crate::tools;
+use pbs_datastore::Chunker;
+use pbs_datastore::index::{IndexFile, ChunkReadInfo};
+use pbs_datastore::chunk_stat::ChunkStat;
+use pbs_datastore::data_blob::{DataBlob, DataChunkBuilder};
+use pbs_datastore::chunk_store::ChunkStore;
+use pbs_datastore::read_chunk::ReadChunk;
+use pbs_tools::process_locker::ProcessLockSharedGuard;
 
 /// Header format definition for dynamic index files (`.dixd`)
 #[repr(C)]
@@ -480,7 +479,7 @@ impl<R: ReadChunk> ReadAt for LocalDynamicReadAt<R> {
 /// Create dynamic index files (`.dixd`)
 pub struct DynamicIndexWriter {
     store: Arc<ChunkStore>,
-    _lock: tools::ProcessLockSharedGuard,
+    _lock: ProcessLockSharedGuard,
     writer: BufWriter<File>,
     closed: bool,
     filename: PathBuf,
index ebf644564f407d3866ebf45e3b57c5846db2934b..518a5b0dd06c5590c52de618eeb36f5c6ffe4c36 100644 (file)
@@ -1,18 +1,17 @@
-use anyhow::{bail, format_err, Error};
-use std::io::{Seek, SeekFrom};
-
-use super::chunk_stat::*;
-use super::chunk_store::*;
-use super::{ChunkReadInfo, IndexFile};
-use crate::tools;
-
 use std::fs::File;
 use std::io::Write;
 use std::os::unix::io::AsRawFd;
 use std::path::{Path, PathBuf};
 use std::sync::Arc;
+use std::io::{Seek, SeekFrom};
+
+use anyhow::{bail, format_err, Error};
 
-use super::ChunkInfo;
+use pbs_datastore::chunk_stat::ChunkStat;
+use pbs_datastore::chunk_store::ChunkStore;
+use pbs_datastore::data_blob::ChunkInfo;
+use pbs_datastore::index::{ChunkReadInfo, IndexFile};
+use pbs_tools::process_locker::ProcessLockSharedGuard;
 
 use proxmox::tools::io::ReadExt;
 use proxmox::tools::Uuid;
@@ -229,7 +228,7 @@ impl IndexFile for FixedIndexReader {
 pub struct FixedIndexWriter {
     store: Arc<ChunkStore>,
     file: File,
-    _lock: tools::ProcessLockSharedGuard,
+    _lock: ProcessLockSharedGuard,
     filename: PathBuf,
     tmp_filename: PathBuf,
     chunk_size: usize,
index 34d1c5ac49ea6c2beb6fa4337a8048cd4d45ab9e..5b597265faf621ddc525b8dd76dc6eaccfbf7feb 100644 (file)
@@ -149,12 +149,16 @@ pub const CATALOG_NAME: &str = "catalog.pcat1.didx";
 
 #[macro_export]
 macro_rules! PROXMOX_BACKUP_PROTOCOL_ID_V1 {
-    () =>  { "proxmox-backup-protocol-v1" }
+    () => {
+        "proxmox-backup-protocol-v1"
+    };
 }
 
 #[macro_export]
 macro_rules! PROXMOX_BACKUP_READER_PROTOCOL_ID_V1 {
-    () =>  { "proxmox-backup-reader-protocol-v1" }
+    () => {
+        "proxmox-backup-reader-protocol-v1"
+    };
 }
 
 /// Unix system user used by proxmox-backup-proxy
@@ -186,6 +190,8 @@ pub use pbs_datastore::checksum_reader;
 pub use pbs_datastore::checksum_reader::*;
 pub use pbs_datastore::checksum_writer;
 pub use pbs_datastore::checksum_writer::*;
+pub use pbs_datastore::chunk_stat;
+pub use pbs_datastore::chunk_stat::*;
 pub use pbs_datastore::chunk_store;
 pub use pbs_datastore::chunk_store::*;
 pub use pbs_datastore::chunker;
@@ -210,13 +216,12 @@ pub use pbs_datastore::key_derivation;
 pub use pbs_datastore::key_derivation::*;
 pub use pbs_datastore::manifest;
 pub use pbs_datastore::manifest::*;
+pub use pbs_datastore::read_chunk::*;
 
 mod chunk_stream;
 pub use chunk_stream::*;
 
-mod chunk_stat;
-pub use chunk_stat::*;
-
+// Split
 mod read_chunk;
 pub use read_chunk::*;
 
@@ -238,6 +243,7 @@ pub use store_progress::*;
 mod verify;
 pub use verify::*;
 
+// Move to client
 mod catalog_shell;
 pub use catalog_shell::*;
 
index 078779de994eb3ef5db68d2374b6b8bd861a0e14..588563c5d46b2f42f0efbe5bfba7c17a46443d43 100644 (file)
@@ -4,18 +4,11 @@ use std::sync::Arc;
 
 use anyhow::{bail, Error};
 
-use super::crypt_config::{CryptConfig, CryptMode};
-use super::data_blob::DataBlob;
-use super::datastore::DataStore;
-
-/// 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>;
+use pbs_datastore::crypt_config::{CryptConfig, CryptMode};
+use pbs_datastore::data_blob::DataBlob;
+use pbs_datastore::read_chunk::{ReadChunk, AsyncReadChunk};
 
-    /// Returns the decoded chunk data
-    fn read_chunk(&self, digest: &[u8; 32]) -> Result<Vec<u8>, Error>;
-}
+use super::datastore::DataStore;
 
 #[derive(Clone)]
 pub struct LocalChunkReader {
@@ -67,20 +60,6 @@ impl ReadChunk for LocalChunkReader {
     }
 }
 
-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>>;
-}
-
 impl AsyncReadChunk for LocalChunkReader {
     fn read_raw_chunk<'a>(
         &'a self,