Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ctl): Support basic sst dump in risectl #3309

Merged
merged 4 commits into from
Jun 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/ctl/src/cmd_impl/hummock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ mod list_version;
pub use list_version::*;
mod list_kv;
pub use list_kv::*;
mod sst_dump;
pub use sst_dump::*;
mod trigger_manual_compaction;
pub use trigger_manual_compaction::*;
70 changes: 70 additions & 0 deletions src/ctl/src/cmd_impl/hummock/sst_dump.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright 2022 Singularity Data
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use risingwave_rpc_client::HummockMetaClient;
use risingwave_storage::monitor::StoreLocalStatistic;

use crate::common::HummockServiceOpts;

pub async fn sst_dump() -> anyhow::Result<()> {
// Retrieves the SSTable store so we can access the SSTableMeta
let hummock_opts = HummockServiceOpts::from_env()?;
let (meta_client, hummock) = hummock_opts.create_hummock_store().await?;
let sstable_store = &*hummock.inner().sstable_store();

// Retrieves the latest HummockVersion from the meta client so we can access the SSTableInfo
let version = meta_client.pin_version(u64::MAX).await?;

for level in version.levels {
for sstable_info in level.table_infos {
let id = sstable_info.id;

let sstable_cache = sstable_store
.sstable(id, &mut StoreLocalStatistic::default())
.await?;
let sstable_meta = &sstable_cache.value().meta;

println!("SST id: {}", id);
println!("-------------------------------------");
println!("File Size: {}", sstable_info.file_size);

if let Some(key_range) = sstable_info.key_range {
println!("Key Range:");
println!(
"\tleft:\t{:?}\n\tright:\t{:?}\n\tinf:\t{:?}",
key_range.left, key_range.right, key_range.inf
);
} else {
println!("Key Range: None");
}

println!("Block Metadata:");
for (i, block_meta) in sstable_meta.block_metas.iter().enumerate() {
println!(
"\tBlock {}, Size: {}, Offset: {}",
i, block_meta.len, block_meta.offset
);
}

println!("Estimated Table Size: {}", sstable_meta.estimated_size);
println!("Bloom Filter Size: {}", sstable_meta.bloom_filter.len());
println!("Key Count: {}", sstable_meta.key_count);
println!("Version: {}", sstable_meta.version);
}
}

meta_client.unpin_version(&[version.id]).await?;

Ok(())
}
2 changes: 2 additions & 0 deletions src/ctl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ enum HummockCommands {
#[clap(short, long = "table-id")]
table_id: Option<u32>,
},
SstDump,
TriggerManualCompaction {
#[clap(short, long = "compaction-group-id", default_value_t = 2)]
compaction_group_id: u64,
Expand All @@ -78,6 +79,7 @@ pub async fn start(opts: CliOpts) -> Result<()> {
Commands::Hummock(HummockCommands::ListKv { epoch, table_id }) => {
tokio::spawn(cmd_impl::hummock::list_kv(epoch, table_id)).await??;
}
Commands::Hummock(HummockCommands::SstDump) => cmd_impl::hummock::sst_dump().await.unwrap(),
Commands::Hummock(HummockCommands::TriggerManualCompaction {
compaction_group_id,
}) => {
Expand Down