move lru cachers to pbs-tools
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
38629c3961
commit
6c221244df
|
@ -7,8 +7,8 @@ use std::collections::HashMap;
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
use super::lru_cache::LruCache;
|
use crate::broadcast_future::BroadcastFuture;
|
||||||
use super::BroadcastFuture;
|
use crate::lru_cache::LruCache;
|
||||||
|
|
||||||
/// Interface for asynchronously getting values on cache misses.
|
/// Interface for asynchronously getting values on cache misses.
|
||||||
pub trait AsyncCacher<K, V: Clone>: Sync + Send {
|
pub trait AsyncCacher<K, V: Clone>: Sync + Send {
|
|
@ -19,5 +19,8 @@ pub mod tokio;
|
||||||
pub mod xattr;
|
pub mod xattr;
|
||||||
pub mod zip;
|
pub mod zip;
|
||||||
|
|
||||||
|
pub mod async_lru_cache;
|
||||||
|
pub mod lru_cache;
|
||||||
|
|
||||||
mod command;
|
mod command;
|
||||||
pub use command::{command_output, command_output_as_string, run_command};
|
pub use command::{command_output, command_output_as_string, run_command};
|
||||||
|
|
|
@ -13,9 +13,9 @@ use tokio::io::{AsyncRead, AsyncSeek, ReadBuf};
|
||||||
use proxmox::io_format_err;
|
use proxmox::io_format_err;
|
||||||
use proxmox::sys::error::io_err_other;
|
use proxmox::sys::error::io_err_other;
|
||||||
|
|
||||||
|
use pbs_datastore::index::IndexFile;
|
||||||
use pbs_datastore::read_chunk::AsyncReadChunk;
|
use pbs_datastore::read_chunk::AsyncReadChunk;
|
||||||
use super::IndexFile;
|
use pbs_tools::async_lru_cache::{AsyncCacher, AsyncLruCache};
|
||||||
use crate::tools::async_lru_cache::{AsyncCacher, AsyncLruCache};
|
|
||||||
|
|
||||||
struct AsyncChunkCacher<T> {
|
struct AsyncChunkCacher<T> {
|
||||||
reader: Arc<T>,
|
reader: Arc<T>,
|
||||||
|
|
|
@ -11,6 +11,7 @@ use pxar::accessor::{MaybeReady, ReadAt, ReadAtOperation};
|
||||||
use pbs_datastore::dynamic_index::DynamicIndexReader;
|
use pbs_datastore::dynamic_index::DynamicIndexReader;
|
||||||
use pbs_datastore::read_chunk::ReadChunk;
|
use pbs_datastore::read_chunk::ReadChunk;
|
||||||
use pbs_datastore::index::IndexFile;
|
use pbs_datastore::index::IndexFile;
|
||||||
|
use pbs_tools::lru_cache::LruCache;
|
||||||
|
|
||||||
struct CachedChunk {
|
struct CachedChunk {
|
||||||
range: Range<u64>,
|
range: Range<u64>,
|
||||||
|
@ -39,7 +40,7 @@ pub struct BufferedDynamicReader<S> {
|
||||||
buffered_chunk_idx: usize,
|
buffered_chunk_idx: usize,
|
||||||
buffered_chunk_start: u64,
|
buffered_chunk_start: u64,
|
||||||
read_offset: u64,
|
read_offset: u64,
|
||||||
lru_cache: crate::tools::lru_cache::LruCache<usize, CachedChunk>,
|
lru_cache: LruCache<usize, CachedChunk>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ChunkCacher<'a, S> {
|
struct ChunkCacher<'a, S> {
|
||||||
|
@ -47,7 +48,7 @@ struct ChunkCacher<'a, S> {
|
||||||
index: &'a DynamicIndexReader,
|
index: &'a DynamicIndexReader,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, S: ReadChunk> crate::tools::lru_cache::Cacher<usize, CachedChunk> for ChunkCacher<'a, S> {
|
impl<'a, S: ReadChunk> pbs_tools::lru_cache::Cacher<usize, CachedChunk> for ChunkCacher<'a, S> {
|
||||||
fn fetch(&mut self, index: usize) -> Result<Option<CachedChunk>, Error> {
|
fn fetch(&mut self, index: usize) -> Result<Option<CachedChunk>, Error> {
|
||||||
let info = match self.index.chunk_info(index) {
|
let info = match self.index.chunk_info(index) {
|
||||||
Some(info) => info,
|
Some(info) => info,
|
||||||
|
@ -70,7 +71,7 @@ impl<S: ReadChunk> BufferedDynamicReader<S> {
|
||||||
buffered_chunk_idx: 0,
|
buffered_chunk_idx: 0,
|
||||||
buffered_chunk_start: 0,
|
buffered_chunk_start: 0,
|
||||||
read_offset: 0,
|
read_offset: 0,
|
||||||
lru_cache: crate::tools::lru_cache::LruCache::new(32),
|
lru_cache: LruCache::new(32),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,8 +38,6 @@ pub use memcom::Memcom;
|
||||||
|
|
||||||
pub mod logrotate;
|
pub mod logrotate;
|
||||||
pub mod loopdev;
|
pub mod loopdev;
|
||||||
pub mod lru_cache;
|
|
||||||
pub mod async_lru_cache;
|
|
||||||
pub mod serde_filter;
|
pub mod serde_filter;
|
||||||
pub mod statistics;
|
pub mod statistics;
|
||||||
pub mod subscription;
|
pub mod subscription;
|
||||||
|
|
Loading…
Reference in New Issue