From 6c221244df6c1b273481140deb9a1b4b0746492b Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Tue, 20 Jul 2021 10:57:22 +0200 Subject: [PATCH] move lru cachers to pbs-tools Signed-off-by: Wolfgang Bumiller --- {src/tools => pbs-tools/src}/async_lru_cache.rs | 4 ++-- pbs-tools/src/lib.rs | 3 +++ {src/tools => pbs-tools/src}/lru_cache.rs | 0 src/backup/cached_chunk_reader.rs | 4 ++-- src/backup/dynamic_index.rs | 7 ++++--- src/tools/mod.rs | 2 -- 6 files changed, 11 insertions(+), 9 deletions(-) rename {src/tools => pbs-tools/src}/async_lru_cache.rs (98%) rename {src/tools => pbs-tools/src}/lru_cache.rs (100%) diff --git a/src/tools/async_lru_cache.rs b/pbs-tools/src/async_lru_cache.rs similarity index 98% rename from src/tools/async_lru_cache.rs rename to pbs-tools/src/async_lru_cache.rs index 62e74fcd..315a7862 100644 --- a/src/tools/async_lru_cache.rs +++ b/pbs-tools/src/async_lru_cache.rs @@ -7,8 +7,8 @@ use std::collections::HashMap; use std::future::Future; use std::sync::{Arc, Mutex}; -use super::lru_cache::LruCache; -use super::BroadcastFuture; +use crate::broadcast_future::BroadcastFuture; +use crate::lru_cache::LruCache; /// Interface for asynchronously getting values on cache misses. pub trait AsyncCacher: Sync + Send { diff --git a/pbs-tools/src/lib.rs b/pbs-tools/src/lib.rs index 075b066b..28950787 100644 --- a/pbs-tools/src/lib.rs +++ b/pbs-tools/src/lib.rs @@ -19,5 +19,8 @@ pub mod tokio; pub mod xattr; pub mod zip; +pub mod async_lru_cache; +pub mod lru_cache; + mod command; pub use command::{command_output, command_output_as_string, run_command}; diff --git a/src/tools/lru_cache.rs b/pbs-tools/src/lru_cache.rs similarity index 100% rename from src/tools/lru_cache.rs rename to pbs-tools/src/lru_cache.rs diff --git a/src/backup/cached_chunk_reader.rs b/src/backup/cached_chunk_reader.rs index 3798ae4a..e88003e4 100644 --- a/src/backup/cached_chunk_reader.rs +++ b/src/backup/cached_chunk_reader.rs @@ -13,9 +13,9 @@ use tokio::io::{AsyncRead, AsyncSeek, ReadBuf}; use proxmox::io_format_err; use proxmox::sys::error::io_err_other; +use pbs_datastore::index::IndexFile; use pbs_datastore::read_chunk::AsyncReadChunk; -use super::IndexFile; -use crate::tools::async_lru_cache::{AsyncCacher, AsyncLruCache}; +use pbs_tools::async_lru_cache::{AsyncCacher, AsyncLruCache}; struct AsyncChunkCacher { reader: Arc, diff --git a/src/backup/dynamic_index.rs b/src/backup/dynamic_index.rs index f13d1391..f7e758d2 100644 --- a/src/backup/dynamic_index.rs +++ b/src/backup/dynamic_index.rs @@ -11,6 +11,7 @@ use pxar::accessor::{MaybeReady, ReadAt, ReadAtOperation}; use pbs_datastore::dynamic_index::DynamicIndexReader; use pbs_datastore::read_chunk::ReadChunk; use pbs_datastore::index::IndexFile; +use pbs_tools::lru_cache::LruCache; struct CachedChunk { range: Range, @@ -39,7 +40,7 @@ pub struct BufferedDynamicReader { buffered_chunk_idx: usize, buffered_chunk_start: u64, read_offset: u64, - lru_cache: crate::tools::lru_cache::LruCache, + lru_cache: LruCache, } struct ChunkCacher<'a, S> { @@ -47,7 +48,7 @@ struct ChunkCacher<'a, S> { index: &'a DynamicIndexReader, } -impl<'a, S: ReadChunk> crate::tools::lru_cache::Cacher for ChunkCacher<'a, S> { +impl<'a, S: ReadChunk> pbs_tools::lru_cache::Cacher for ChunkCacher<'a, S> { fn fetch(&mut self, index: usize) -> Result, Error> { let info = match self.index.chunk_info(index) { Some(info) => info, @@ -70,7 +71,7 @@ impl BufferedDynamicReader { buffered_chunk_idx: 0, buffered_chunk_start: 0, read_offset: 0, - lru_cache: crate::tools::lru_cache::LruCache::new(32), + lru_cache: LruCache::new(32), } } diff --git a/src/tools/mod.rs b/src/tools/mod.rs index e3c2811a..6653a492 100644 --- a/src/tools/mod.rs +++ b/src/tools/mod.rs @@ -38,8 +38,6 @@ pub use memcom::Memcom; pub mod logrotate; pub mod loopdev; -pub mod lru_cache; -pub mod async_lru_cache; pub mod serde_filter; pub mod statistics; pub mod subscription;