From 8f917f9e4d9d5075b988c83e9f0541d203d2781a Mon Sep 17 00:00:00 2001 From: tison Date: Wed, 9 Sep 2026 14:24:13 +0800 Subject: [PATCH] chore: organize module declarations and re-exports --- cache2/src/config.rs | 32 ++++++++--------- cache2/src/index_storage.rs | 17 +++++---- cache2/src/io_engine.rs | 57 +++++++++++++++-------------- cache2/src/lib.rs | 69 +++++++++++++++++++----------------- cache2/src/region.rs | 8 ++--- cache2/src/region_runtime.rs | 11 +++--- 6 files changed, 97 insertions(+), 97 deletions(-) diff --git a/cache2/src/config.rs b/cache2/src/config.rs index 1130b93..e33f268 100644 --- a/cache2/src/config.rs +++ b/cache2/src/config.rs @@ -24,23 +24,23 @@ use crate::memory::MemoryStore; use crate::recovery::DataGeometry; mod runtime; -mod storage; - -pub use runtime::IoEngine; -pub use runtime::IoMode; -pub(crate) use runtime::IoPoolTopology; -pub use runtime::IoUringConfig; -pub use runtime::IoUringPoolConfig; -pub use runtime::IoUringSqPollConfig; -pub use runtime::L1EvictionPolicy; +pub use self::runtime::IoEngine; +pub use self::runtime::IoMode; +pub(crate) use self::runtime::IoPoolTopology; +pub use self::runtime::IoUringConfig; +pub use self::runtime::IoUringPoolConfig; +pub use self::runtime::IoUringSqPollConfig; +pub use self::runtime::L1EvictionPolicy; #[cfg(test)] -pub(crate) use runtime::MAX_WRITE_FLUSH_THRESHOLD_BYTES; -pub use runtime::PosixIoConfig; -pub use runtime::ReadAdmission; -pub use runtime::RuntimeOptions; -pub(crate) use storage::KEY_HASH_SEED; -pub use storage::StorageLayout; -pub use storage::StorageOptions; +pub(crate) use self::runtime::MAX_WRITE_FLUSH_THRESHOLD_BYTES; +pub use self::runtime::PosixIoConfig; +pub use self::runtime::ReadAdmission; +pub use self::runtime::RuntimeOptions; + +mod storage; +pub(crate) use self::storage::KEY_HASH_SEED; +pub use self::storage::StorageLayout; +pub use self::storage::StorageOptions; /// Complete, immutable configuration for opening a [`crate::Cache`]. /// diff --git a/cache2/src/index_storage.rs b/cache2/src/index_storage.rs index a858ab8..c995743 100644 --- a/cache2/src/index_storage.rs +++ b/cache2/src/index_storage.rs @@ -36,6 +36,14 @@ use std::sync::TryLockError; use std::sync::atomic::AtomicU8; use std::sync::atomic::Ordering; +use self::page_format::PAGE_CHECKSUM_OFFSET; +use self::page_format::encode_page_header; +use self::page_format::page_checksum; +use self::page_format::put_u32; +#[cfg(test)] +use self::page_format::put_u64; +use self::page_format::read_u64; +use self::page_format::validate_page_header; use crate::index::INDEX_CANDIDATES; use crate::index::IndexEntry; use crate::index::MAX_INDEX_PARTITIONS; @@ -45,19 +53,10 @@ use crate::index::index_partition_for; use crate::index::record_size_class_upper_bound; mod page_format; - pub(crate) use self::page_format::INDEX_IMAGE_PAGE_HEADER_SIZE; pub(crate) use self::page_format::INDEX_IMAGE_PAGE_SIZE; pub(crate) use self::page_format::INDEX_IMAGE_SLOT_SIZE; pub(crate) use self::page_format::INDEX_IMAGE_SLOTS_PER_PAGE; -use self::page_format::PAGE_CHECKSUM_OFFSET; -use self::page_format::encode_page_header; -use self::page_format::page_checksum; -use self::page_format::put_u32; -#[cfg(test)] -use self::page_format::put_u64; -use self::page_format::read_u64; -use self::page_format::validate_page_header; /// Upper bound for one underlying warm-image write. /// diff --git a/cache2/src/io_engine.rs b/cache2/src/io_engine.rs index 6f0ced9..168b294 100644 --- a/cache2/src/io_engine.rs +++ b/cache2/src/io_engine.rs @@ -99,6 +99,34 @@ use crate::resources::BufferLease; use crate::resources::CACHE_THREAD_STACK_BYTES; use crate::snapshot::CacheIoDirectionSnapshot; +mod posix; +pub(crate) use self::posix::BackendIoEngine; + +#[cfg(all( + feature = "io-uring", + target_os = "linux", + any( + target_arch = "x86_64", + target_arch = "aarch64", + target_arch = "riscv64", + target_arch = "loongarch64", + target_arch = "powerpc64" + ) +))] +mod uring; +#[cfg(all( + feature = "io-uring", + target_os = "linux", + any( + target_arch = "x86_64", + target_arch = "aarch64", + target_arch = "riscv64", + target_arch = "loongarch64", + target_arch = "powerpc64" + ) +))] +pub(crate) use self::uring::UringIoEngine; + pub(crate) const IO_BUFFER_ALIGNMENT: usize = 4096; pub(crate) const MAX_IO_REQUESTS_PER_ENGINE: usize = 4096; // Common bounded command, completion, and request bookkeeping. Payload @@ -1942,35 +1970,6 @@ impl Drop for RuntimeInner { } } -mod posix; -pub(crate) use posix::BackendIoEngine; - -#[cfg(all( - feature = "io-uring", - target_os = "linux", - any( - target_arch = "x86_64", - target_arch = "aarch64", - target_arch = "riscv64", - target_arch = "loongarch64", - target_arch = "powerpc64" - ) -))] -mod uring; - -#[cfg(all( - feature = "io-uring", - target_os = "linux", - any( - target_arch = "x86_64", - target_arch = "aarch64", - target_arch = "riscv64", - target_arch = "loongarch64", - target_arch = "powerpc64" - ) -))] -pub(crate) use uring::UringIoEngine; - #[cfg(unix)] pub(crate) fn build_file_engine( files: RuntimeFileSet, diff --git a/cache2/src/lib.rs b/cache2/src/lib.rs index 26636d5..d94a888 100644 --- a/cache2/src/lib.rs +++ b/cache2/src/lib.rs @@ -21,42 +21,46 @@ #[cfg(feature = "benchmarking")] #[doc(hidden)] pub mod benchmarking; -pub mod error; -pub use cache::Cache; -pub use cache::CacheTier; -pub use cache::Value; -pub use config::CacheConfig; -pub use config::IoEngine; -pub use config::IoMode; -pub use config::IoUringConfig; -pub use config::IoUringPoolConfig; -pub use config::IoUringSqPollConfig; -pub use config::L1EvictionPolicy; -pub use config::PosixIoConfig; -pub use config::ReadAdmission; -pub use config::RuntimeOptions; -pub use config::StorageLayout; -pub use config::StorageOptions; -pub use error::Error; -pub use error::ErrorKind; -pub use error::ErrorOperation; -pub use error::Result; -pub use snapshot::CacheHealth; -pub use snapshot::CacheIndexSnapshot; -pub use snapshot::CacheIoDirectionSnapshot; -pub use snapshot::CacheIoPathSnapshot; -pub use snapshot::CacheIoSnapshot; -pub use snapshot::CacheL1Snapshot; -pub use snapshot::CacheReclaimSnapshot; -pub use snapshot::CacheSnapshot; -pub use snapshot::DetailedCacheSnapshot; -pub use snapshot::RegionSnapshot; -pub use snapshot::StartupMode; +pub mod error; +pub use self::error::Error; +pub use self::error::ErrorKind; +pub use self::error::ErrorOperation; +pub use self::error::Result; mod cache; -mod checksum; +pub use self::cache::Cache; +pub use self::cache::CacheTier; +pub use self::cache::Value; + mod config; +pub use self::config::CacheConfig; +pub use self::config::IoEngine; +pub use self::config::IoMode; +pub use self::config::IoUringConfig; +pub use self::config::IoUringPoolConfig; +pub use self::config::IoUringSqPollConfig; +pub use self::config::L1EvictionPolicy; +pub use self::config::PosixIoConfig; +pub use self::config::ReadAdmission; +pub use self::config::RuntimeOptions; +pub use self::config::StorageLayout; +pub use self::config::StorageOptions; + +mod snapshot; +pub use self::snapshot::CacheHealth; +pub use self::snapshot::CacheIndexSnapshot; +pub use self::snapshot::CacheIoDirectionSnapshot; +pub use self::snapshot::CacheIoPathSnapshot; +pub use self::snapshot::CacheIoSnapshot; +pub use self::snapshot::CacheL1Snapshot; +pub use self::snapshot::CacheReclaimSnapshot; +pub use self::snapshot::CacheSnapshot; +pub use self::snapshot::DetailedCacheSnapshot; +pub use self::snapshot::RegionSnapshot; +pub use self::snapshot::StartupMode; + +mod checksum; mod eviction; mod format; mod hashing; @@ -77,7 +81,6 @@ mod region_runtime; mod region_staging; mod region_store; mod resources; -mod snapshot; #[cfg(test)] mod fixtures; diff --git a/cache2/src/region.rs b/cache2/src/region.rs index e390c51..ac3c275 100644 --- a/cache2/src/region.rs +++ b/cache2/src/region.rs @@ -19,8 +19,8 @@ //! backend-independent shutdown state machine remains in `region_store`. pub(crate) mod core; -mod file_backend; -pub(crate) use file_backend::FileRegionBackend; -pub(crate) use file_backend::RegionFiles; -pub(crate) use file_backend::SystemRegionFileSystem; +mod file_backend; +pub(crate) use self::file_backend::FileRegionBackend; +pub(crate) use self::file_backend::RegionFiles; +pub(crate) use self::file_backend::SystemRegionFileSystem; diff --git a/cache2/src/region_runtime.rs b/cache2/src/region_runtime.rs index 885067a..898dc41 100644 --- a/cache2/src/region_runtime.rs +++ b/cache2/src/region_runtime.rs @@ -35,16 +35,12 @@ use asyncband::semaphore::OwnedSemaphorePermit; use asyncband::semaphore::Semaphore; use asyncband::watch; -#[cfg(test)] -use crate::config::ReadAdmission; - -mod metrics; - -pub(crate) use self::metrics::ActivityMetrics; use self::metrics::RuntimeMetrics; use crate::config::CacheConfig; use crate::config::IoMode; use crate::config::IoPoolTopology; +#[cfg(test)] +use crate::config::ReadAdmission; use crate::config::RuntimeOptions; use crate::format::MAX_KEY_SIZE; use crate::hashing::route_hash; @@ -94,6 +90,9 @@ use crate::snapshot::CacheIoSnapshot; use crate::snapshot::CacheSnapshot; use crate::snapshot::DetailedCacheSnapshot; +mod metrics; +pub(crate) use self::metrics::ActivityMetrics; + const WRITE_FLUSH_DELAY: Duration = Duration::from_millis(1); const _RETRY_AGE: Duration = Duration::from_micros(50); const LIFECYCLE_RUNNING: u8 = 0;