0g-storage-node/node/chunk_pool/src/lib.rs
peilun-conflux 4eb2a50b0e
Use inner lock in storage and use async lock. (#92)
* Use inner lock in storage.

* Remove mut.

* Remove async lock for storage.

* Fix tests and warnings.

* Use spawn_blocking for storage task.

* Fix clippy.

* Finalize the new tx at last.

* Revert "Finalize the new tx at last."

This reverts commit b56ad5582d.

* Wait for old same-root txs to finalize.

* Use async storage in miner.

* Update rust version to 1.79.0.

* Use Vec to avoid stack overflow.

* Fix unused warning.

* Fix clippy.

* Fix test warning.

* Fix test.

* fmt.

* Use async storage in pruner.

* nit.
2024-06-29 17:08:02 +08:00

41 lines
1.1 KiB
Rust

#[macro_use]
extern crate tracing;
mod handler;
mod mem_pool;
pub use handler::{ChunkPoolHandler, ChunkPoolMessage};
pub use mem_pool::{FileID, MemoryChunkPool, SegmentInfo};
use std::sync::Arc;
use std::time::Duration;
use storage_async::ShardConfig;
#[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,
pub shard_config: ShardConfig,
}
impl Config {
pub fn expiration_time(&self) -> Duration {
Duration::from_secs(self.expiration_time_secs)
}
}
pub fn unbounded(
config: Config,
log_store: Arc<storage_async::Store>,
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)
}