Skip to content
This repository has been archived by the owner on Aug 4, 2024. It is now read-only.

Commit

Permalink
feat(version): impl Trait Display for Version (#36)
Browse files Browse the repository at this point in the history
* feat(cli): add api for printing sst arrangement status

* feat(version): impl Trait `Display` for `Version`

---------

Co-authored-by: Xwg <[email protected]>
Co-authored-by: Kould <[email protected]>
  • Loading branch information
3 people authored Jul 14, 2023
1 parent 11c12e6 commit 73271ae
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
3 changes: 1 addition & 2 deletions src/kernel/lsm/compactor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,6 @@ impl Compactor {
}
}

/// TODO: Manual\Seek Compaction测试
#[cfg(test)]
mod tests {
use crate::kernel::io::{FileExtension, IoFactory, IoType};
Expand Down Expand Up @@ -592,7 +591,7 @@ mod tests {
let version_2 = version_status.current().await;
let level_slice = &version_2.level_slice;

println!("SeekCompaction Test: {:#?}", level_slice);
println!("SeekCompaction Test: {version_2}");
assert!(!level_slice[1].is_empty());
assert!(!level_slice[2].is_empty());

Expand Down
37 changes: 25 additions & 12 deletions src/kernel/lsm/version/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::kernel::lsm::version::edit::{EditType, VersionEdit};
use crate::kernel::lsm::version::meta::VersionMeta;
use crate::kernel::{sorted_gen_list, Result};
use itertools::Itertools;
use std::fmt;
use std::sync::Arc;
use tokio::sync::mpsc::UnboundedSender;
use tracing::{error, info};
Expand Down Expand Up @@ -101,7 +102,7 @@ impl Version {
};

version.apply(vec_log)?;
version_display(&version, "load_from_log");
info!("[Version][load_from_log]: {version}");

Ok(version)
}
Expand Down Expand Up @@ -297,6 +298,29 @@ impl Version {
}
}

impl fmt::Display for Version {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
writeln!(f, "Version: {}", self.version_num)?;

for level in 0..7 {
writeln!(f, "Level {level}:")?;
write!(f, "\t")?;
for scope in &self.level_slice[level] {
write!(
f,
"[gen: {}, scope:({:?},{:?})]\t",
scope.gen(),
scope.start,
scope.end
)?;
}
writeln!(f)?;
}

writeln!(f, "{:#?}", self.meta_data)
}
}

impl Drop for Version {
/// 将此Version可删除的版本号发送
fn drop(&mut self) {
Expand All @@ -312,14 +336,3 @@ impl Drop for Version {
}
}
}

/// 使用特定格式进行display
pub(crate) fn version_display(new_version: &Version, method: &str) {
info!(
"[Version: {}]: version_num: {}, len: {}, size_of_disk: {}",
method,
new_version.version_num,
new_version.len(),
new_version.size_of_disk(),
);
}
4 changes: 2 additions & 2 deletions src/kernel/lsm/version/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::kernel::lsm::table::loader::TableLoader;
use crate::kernel::lsm::version::cleaner::Cleaner;
use crate::kernel::lsm::version::edit::VersionEdit;
use crate::kernel::lsm::version::{
snapshot_gen, version_display, Version, DEFAULT_SS_TABLE_PATH, DEFAULT_VERSION_PATH,
snapshot_gen, Version, DEFAULT_SS_TABLE_PATH, DEFAULT_VERSION_PATH,
};
use crate::kernel::Result;
use itertools::Itertools;
Expand Down Expand Up @@ -83,7 +83,7 @@ impl VersionStatus {
) -> Result<()> {
let mut new_version = Version::clone(self.current().await.as_ref());
let mut inner = self.inner.write().await;
version_display(&new_version, "log_and_apply");
info!("[Version Status][log_and_apply]: {new_version}");

if self.edit_approximate_count.load(Ordering::Relaxed) >= snapshot_threshold {
Self::write_snap_shot(&mut inner, &self.log_factory).await?;
Expand Down

0 comments on commit 73271ae

Please sign in to comment.