2024-01-03 10:24:52 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate tracing;
|
|
|
|
|
|
|
|
mod handler;
|
|
|
|
mod mem_pool;
|
|
|
|
|
2024-06-07 18:50:36 +00:00
|
|
|
pub use handler::{ChunkPoolHandler, ChunkPoolMessage};
|
2024-01-03 10:24:52 +00:00
|
|
|
pub use mem_pool::{FileID, MemoryChunkPool, SegmentInfo};
|
|
|
|
|
|
|
|
use std::sync::Arc;
|
|
|
|
use std::time::Duration;
|
2024-06-07 18:50:36 +00:00
|
|
|
use storage_async::ShardConfig;
|
2024-01-03 10:24:52 +00:00
|
|
|
|
|
|
|
#[derive(Clone, Copy, Debug)]
|
|
|
|
pub struct Config {
|
|
|
|
pub write_window_size: usize,
|
|
|
|
pub max_cached_chunks_all: usize,
|
|
|
|
pub max_writings: usize,
|
|
|
|
pub expiration_time_secs: u64,
|
2024-06-07 18:50:36 +00:00
|
|
|
pub shard_config: ShardConfig,
|
2024-01-03 10:24:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Config {
|
|
|
|
pub fn expiration_time(&self) -> Duration {
|
|
|
|
Duration::from_secs(self.expiration_time_secs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn unbounded(
|
|
|
|
config: Config,
|
2024-06-29 09:08:02 +00:00
|
|
|
log_store: Arc<storage_async::Store>,
|
2024-01-03 10:24:52 +00:00
|
|
|
network_send: tokio::sync::mpsc::UnboundedSender<network::NetworkMessage>,
|
|
|
|
) -> (Arc<MemoryChunkPool>, ChunkPoolHandler) {
|
|
|
|
let (sender, receiver) = tokio::sync::mpsc::unbounded_channel();
|
|
|
|
|
|
|
|
let mem_pool = Arc::new(MemoryChunkPool::new(config, log_store.clone(), sender));
|
|
|
|
let handler = ChunkPoolHandler::new(receiver, mem_pool.clone(), log_store, network_send);
|
|
|
|
|
|
|
|
(mem_pool, handler)
|
|
|
|
}
|