mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-01-05 21:02:58 +00:00
refactor(storage): Simplify debug output of some structs (#1028)
* refactor: Simplify debug output of RegionImpl * feat: Simplify memtable debug output
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
|
||||
use std::cmp::Ordering;
|
||||
use std::collections::{btree_map, BTreeMap};
|
||||
use std::fmt;
|
||||
use std::ops::Bound;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering as AtomicOrdering};
|
||||
use std::sync::{Arc, RwLock};
|
||||
@@ -37,7 +38,6 @@ type RwLockMap = RwLock<BTreeMap<InnerKey, RowValue>>;
|
||||
/// A simple memtable implementation based on std's [`BTreeMap`].
|
||||
///
|
||||
/// Mainly for test purpose, don't use in production.
|
||||
#[derive(Debug)]
|
||||
pub struct BTreeMemtable {
|
||||
id: MemtableId,
|
||||
schema: RegionSchemaRef,
|
||||
@@ -56,6 +56,20 @@ impl BTreeMemtable {
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for BTreeMemtable {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let len = self.map.read().unwrap().len();
|
||||
|
||||
f.debug_struct("BTreeMemtable")
|
||||
.field("id", &self.id)
|
||||
// Only show StoreSchema
|
||||
.field("schema", &self.schema)
|
||||
.field("rows", &len)
|
||||
.field("estimated_bytes", &self.estimated_bytes)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl Memtable for BTreeMemtable {
|
||||
fn id(&self) -> MemtableId {
|
||||
self.id
|
||||
|
||||
@@ -15,7 +15,9 @@
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
mod writer;
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::fmt;
|
||||
use std::sync::Arc;
|
||||
|
||||
use async_trait::async_trait;
|
||||
@@ -50,7 +52,6 @@ use crate::wal::Wal;
|
||||
use crate::write_batch::WriteBatch;
|
||||
|
||||
/// [Region] implementation.
|
||||
#[derive(Debug)]
|
||||
pub struct RegionImpl<S: LogStore> {
|
||||
inner: Arc<RegionInner<S>>,
|
||||
}
|
||||
@@ -63,6 +64,21 @@ impl<S: LogStore> Clone for RegionImpl<S> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: LogStore> fmt::Debug for RegionImpl<S> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
f.debug_struct("RegionImpl")
|
||||
.field("id", &self.inner.shared.id)
|
||||
.field("name", &self.inner.shared.name)
|
||||
.field("wal", &self.inner.wal)
|
||||
.field("flush_strategy", &self.inner.flush_strategy)
|
||||
.field("flush_scheduler", &self.inner.flush_scheduler)
|
||||
.field("compaction_scheduler", &self.inner.compaction_scheduler)
|
||||
.field("sst_layer", &self.inner.sst_layer)
|
||||
.field("manifest", &self.inner.manifest)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<S: LogStore> Region for RegionImpl<S> {
|
||||
type Error = Error;
|
||||
@@ -454,7 +470,6 @@ impl SharedData {
|
||||
|
||||
pub type SharedDataRef = Arc<SharedData>;
|
||||
|
||||
#[derive(Debug)]
|
||||
struct RegionInner<S: LogStore> {
|
||||
shared: SharedDataRef,
|
||||
writer: RegionWriterRef,
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use std::fmt;
|
||||
use std::sync::Arc;
|
||||
|
||||
use common_error::prelude::*;
|
||||
@@ -32,7 +33,7 @@ use crate::schema::{StoreSchema, StoreSchemaRef};
|
||||
///
|
||||
/// The user schema is the schema that only contains columns that user could visit,
|
||||
/// as well as what the schema user created.
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
#[derive(PartialEq, Eq)]
|
||||
pub struct RegionSchema {
|
||||
/// Schema that only contains columns that user defined, excluding internal columns
|
||||
/// that are reserved and used by the storage engine.
|
||||
@@ -48,6 +49,14 @@ pub struct RegionSchema {
|
||||
columns: ColumnsMetadataRef,
|
||||
}
|
||||
|
||||
impl fmt::Debug for RegionSchema {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
f.debug_struct("RegionSchema")
|
||||
.field("columns", &self.columns)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl RegionSchema {
|
||||
pub fn new(columns: ColumnsMetadataRef, version: u32) -> Result<RegionSchema> {
|
||||
let user_schema = Arc::new(build_user_schema(&columns, version)?);
|
||||
|
||||
Reference in New Issue
Block a user