From f81dfc9bedca36dba1926c1a8d1b9eff687518d6 Mon Sep 17 00:00:00 2001 From: Ning Sun Date: Wed, 27 Jul 2022 15:04:51 +0800 Subject: [PATCH] feat: add fmt::Debug for RegionImpl --- src/log-store/src/fs/log.rs | 1 + src/log-store/src/fs/namespace.rs | 3 ++- src/log-store/src/fs/noop.rs | 4 ++-- src/storage/src/background.rs | 8 +++++--- src/storage/src/engine.rs | 3 +-- src/storage/src/flush.rs | 5 +++-- src/storage/src/manifest/region.rs | 3 ++- src/storage/src/memtable.rs | 5 +++-- src/storage/src/region.rs | 3 +++ src/storage/src/region/tests/flush.rs | 2 +- src/storage/src/region/writer.rs | 2 ++ src/storage/src/sst.rs | 3 ++- src/storage/src/version.rs | 3 ++- src/storage/src/wal.rs | 1 + src/store-api/src/logstore.rs | 2 +- src/store-api/src/logstore/namespace.rs | 2 +- 16 files changed, 32 insertions(+), 18 deletions(-) diff --git a/src/log-store/src/fs/log.rs b/src/log-store/src/fs/log.rs index c110237e3a..dd4da5ab07 100644 --- a/src/log-store/src/fs/log.rs +++ b/src/log-store/src/fs/log.rs @@ -21,6 +21,7 @@ use crate::fs::AppendResponseImpl; type FileMap = BTreeMap; +#[derive(Debug)] pub struct LocalFileLogStore { files: RwLock, active: ArcSwap, diff --git a/src/log-store/src/fs/namespace.rs b/src/log-store/src/fs/namespace.rs index c39f87c967..536f31260d 100644 --- a/src/log-store/src/fs/namespace.rs +++ b/src/log-store/src/fs/namespace.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use store_api::logstore::namespace::Namespace; -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct LocalNamespace { inner: Arc, } @@ -13,6 +13,7 @@ impl Default for LocalNamespace { } } +#[derive(Debug)] struct LocalNamespaceInner { name: String, id: u64, diff --git a/src/log-store/src/fs/noop.rs b/src/log-store/src/fs/noop.rs index 8eba4eb156..cce3131d12 100644 --- a/src/log-store/src/fs/noop.rs +++ b/src/log-store/src/fs/noop.rs @@ -5,8 +5,8 @@ use crate::fs::{entry::EntryImpl, namespace::LocalNamespace, AppendResponseImpl} /// A noop log store which only for test // TODO: Add a test feature -#[derive(Default)] -pub struct NoopLogStore {} +#[derive(Debug, Default)] +pub struct NoopLogStore; #[async_trait::async_trait] impl LogStore for NoopLogStore { diff --git a/src/storage/src/background.rs b/src/storage/src/background.rs index 4329d3eb06..775c0aac1e 100644 --- a/src/storage/src/background.rs +++ b/src/storage/src/background.rs @@ -10,7 +10,7 @@ use snafu::ResultExt; use crate::error::{self, Result}; /// Background job context. -#[derive(Clone, Default)] +#[derive(Clone, Debug, Default)] pub struct Context { inner: Arc, } @@ -34,12 +34,13 @@ impl Context { } } -#[derive(Default)] +#[derive(Debug, Default)] struct ContextInner { cancelled: AtomicBool, } /// Handle to the background job. +#[derive(Debug)] pub struct JobHandle { ctx: Context, handle: JoinHandle>, @@ -71,7 +72,7 @@ type BoxedJob = Box; /// Thread pool that runs all background jobs. #[async_trait] -pub trait JobPool: Send + Sync { +pub trait JobPool: Send + Sync + std::fmt::Debug { /// Submit a job to run in background. /// /// Returns the [JobHandle] to the job. @@ -83,6 +84,7 @@ pub trait JobPool: Send + Sync { pub type JobPoolRef = Arc; +#[derive(Debug)] pub struct JobPoolImpl {} #[async_trait] diff --git a/src/storage/src/engine.rs b/src/storage/src/engine.rs index df4f77ab7e..c85922b0fd 100644 --- a/src/storage/src/engine.rs +++ b/src/storage/src/engine.rs @@ -199,8 +199,7 @@ impl EngineInner { regions.insert(region_name.clone(), region.clone()); } - // TODO(yingwen): Impl Debug format for region and print region info briefly in log. - info!("Storage engine create region {}", region_name); + info!("Storage engine create region {:?}", ®ion); Ok(region) } diff --git a/src/storage/src/flush.rs b/src/storage/src/flush.rs index 0cc51fa2bf..73b7aa70be 100644 --- a/src/storage/src/flush.rs +++ b/src/storage/src/flush.rs @@ -23,7 +23,7 @@ use crate::wal::Wal; /// Default write buffer size (32M). const DEFAULT_WRITE_BUFFER_SIZE: usize = 32 * 1024 * 1024; -pub trait FlushStrategy: Send + Sync { +pub trait FlushStrategy: Send + Sync + std::fmt::Debug { fn should_flush( &self, shared: &SharedDataRef, @@ -113,10 +113,11 @@ pub struct MemtableWithMeta { } #[async_trait] -pub trait FlushScheduler: Send + Sync { +pub trait FlushScheduler: Send + Sync + std::fmt::Debug { async fn schedule_flush(&self, flush_job: Box) -> Result; } +#[derive(Debug)] pub struct FlushSchedulerImpl { job_pool: JobPoolRef, } diff --git a/src/storage/src/manifest/region.rs b/src/storage/src/manifest/region.rs index 3011a2cb9d..9cd3f97371 100644 --- a/src/storage/src/manifest/region.rs +++ b/src/storage/src/manifest/region.rs @@ -18,7 +18,7 @@ use crate::manifest::action::*; use crate::manifest::storage::ManifestObjectStore; use crate::manifest::storage::ObjectStoreLogIterator; -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct RegionManifest { inner: Arc, } @@ -74,6 +74,7 @@ impl Manifest for RegionManifest { } } +#[derive(Debug)] struct RegionManifestInner { region_id: RegionId, store: Arc, diff --git a/src/storage/src/memtable.rs b/src/storage/src/memtable.rs index 0ba18611a9..7d0efd9af6 100644 --- a/src/storage/src/memtable.rs +++ b/src/storage/src/memtable.rs @@ -95,7 +95,7 @@ pub trait BatchIterator: Iterator> + Send + Sync { pub type BatchIteratorPtr = Box; -pub trait MemtableBuilder: Send + Sync { +pub trait MemtableBuilder: Send + Sync + std::fmt::Debug { fn build(&self, id: MemtableId, schema: MemtableSchema) -> MemtableRef; } @@ -136,7 +136,8 @@ impl KeyValues { } } -pub struct DefaultMemtableBuilder {} +#[derive(Debug)] +pub struct DefaultMemtableBuilder; impl MemtableBuilder for DefaultMemtableBuilder { fn build(&self, id: MemtableId, schema: MemtableSchema) -> MemtableRef { diff --git a/src/storage/src/region.rs b/src/storage/src/region.rs index 4303b273a0..cf85676312 100644 --- a/src/storage/src/region.rs +++ b/src/storage/src/region.rs @@ -22,6 +22,7 @@ use crate::wal::Wal; use crate::write_batch::WriteBatch; /// [Region] implementation. +#[derive(Debug)] pub struct RegionImpl { inner: Arc>, } @@ -110,6 +111,7 @@ impl RegionImpl { } /// Shared data of region. +#[derive(Debug)] pub struct SharedData { pub id: RegionId, pub name: String, @@ -119,6 +121,7 @@ pub struct SharedData { pub type SharedDataRef = Arc; +#[derive(Debug)] struct RegionInner { shared: SharedDataRef, writer: RegionWriterRef, diff --git a/src/storage/src/region/tests/flush.rs b/src/storage/src/region/tests/flush.rs index d2623f69e8..5f7a2a7c51 100644 --- a/src/storage/src/region/tests/flush.rs +++ b/src/storage/src/region/tests/flush.rs @@ -47,7 +47,7 @@ impl FlushTester { } } -#[derive(Default)] +#[derive(Debug, Default)] struct FlushSwitch { should_flush: AtomicBool, } diff --git a/src/storage/src/region/writer.rs b/src/storage/src/region/writer.rs index 30d20c288f..f8e6ff0041 100644 --- a/src/storage/src/region/writer.rs +++ b/src/storage/src/region/writer.rs @@ -24,6 +24,7 @@ pub type RegionWriterRef = Arc; // TODO(yingwen): Add benches for write and support group commit to improve write throughput. /// Region writer manages all write operations to the region. +#[derive(Debug)] pub struct RegionWriter { /// Inner writer guarded by write lock, the write lock is used to ensure /// all write operations are serialized. @@ -112,6 +113,7 @@ impl<'a, S: LogStore> WriterContext<'a, S> { } } +#[derive(Debug)] struct WriterInner { memtable_builder: MemtableBuilderRef, last_memtable_id: MemtableId, diff --git a/src/storage/src/sst.rs b/src/storage/src/sst.rs index c8e6ea05b1..0c85a69072 100644 --- a/src/storage/src/sst.rs +++ b/src/storage/src/sst.rs @@ -121,7 +121,7 @@ pub struct WriteOptions { /// Sst access layer. #[async_trait] -pub trait AccessLayer: Send + Sync { +pub trait AccessLayer: Send + Sync + std::fmt::Debug { // Writes SST file with given name and returns the full path. async fn write_sst( &self, @@ -134,6 +134,7 @@ pub trait AccessLayer: Send + Sync { pub type AccessLayerRef = Arc; /// Sst access layer based on local file system. +#[derive(Debug)] pub struct FsAccessLayer { sst_dir: String, object_store: ObjectStore, diff --git a/src/storage/src/version.rs b/src/storage/src/version.rs index 40bb398b8b..763730ffe8 100644 --- a/src/storage/src/version.rs +++ b/src/storage/src/version.rs @@ -24,6 +24,7 @@ use crate::sync::CowCell; const DEFAULT_BUCKET_DURATION: Duration = Duration::from_secs(3600 * 2); /// Controls version of in memory state for a region. +#[derive(Debug)] pub struct VersionControl { // TODO(yingwen): If all modification to version must acquire the region writer lock first, // then we may just use ArcSwap to hold version. But some operations may only require the @@ -116,7 +117,7 @@ type MemtableVersionRef = Arc; type LevelMetasRef = Arc; /// Version contains metadata and state of region. -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct Version { /// Metadata of the region. /// diff --git a/src/storage/src/wal.rs b/src/storage/src/wal.rs index d3d9de4462..9ae5880e19 100644 --- a/src/storage/src/wal.rs +++ b/src/storage/src/wal.rs @@ -15,6 +15,7 @@ use crate::{ write_batch::{codec::WriteBatchArrowEncoder, WriteBatch}, }; +#[derive(Debug)] pub struct Wal { region_id: u32, namespace: S::Namespace, diff --git a/src/store-api/src/logstore.rs b/src/store-api/src/logstore.rs index af1f874922..6894567d17 100644 --- a/src/store-api/src/logstore.rs +++ b/src/store-api/src/logstore.rs @@ -12,7 +12,7 @@ pub mod namespace; /// `LogStore` serves as a Write-Ahead-Log for storage engine. #[async_trait::async_trait] -pub trait LogStore: Send + Sync + 'static { +pub trait LogStore: Send + Sync + 'static + std::fmt::Debug { type Error: ErrorExt + Send + Sync + 'static; type Namespace: Namespace; type Entry: Entry; diff --git a/src/store-api/src/logstore/namespace.rs b/src/store-api/src/logstore/namespace.rs index 1b1919c7c0..a74c0c25a7 100644 --- a/src/store-api/src/logstore/namespace.rs +++ b/src/store-api/src/logstore/namespace.rs @@ -1,4 +1,4 @@ -pub trait Namespace: Send + Sync + Clone { +pub trait Namespace: Send + Sync + Clone + std::fmt::Debug { fn new(name: &str, id: u64) -> Self; fn name(&self) -> &str;