risingwave_ctl/cmd_impl/hummock/
list_version.rs1use risingwave_pb::hummock::PinnedVersionsSummary;
16use risingwave_rpc_client::HummockMetaClient;
17
18use crate::CtlContext;
19
20pub async fn list_version(
21 context: &CtlContext,
22 verbose: bool,
23 verbose_key_range: bool,
24) -> anyhow::Result<()> {
25 let meta_client = context.meta_client().await?;
26 let mut version = meta_client.get_current_version().await?;
27
28 if verbose && verbose_key_range {
29 println!("{:#?}", version);
30 } else if verbose {
31 version.levels.iter_mut().for_each(|(_cg_id, levels)| {
32 {
34 let l0 = &mut levels.l0;
35 for sub_level in &mut l0.sub_levels {
36 for t in &mut sub_level.table_infos {
37 t.remove_key_range();
38 }
39 }
40 }
41
42 for level in &mut levels.levels {
44 for t in &mut level.table_infos {
45 t.remove_key_range();
46 }
47 }
48 });
49
50 println!("{:#?}", version);
51 } else {
52 println!("Version {}", version.id);
53
54 for (cg, levels) in &version.levels {
55 println!("CompactionGroup {}", cg);
56
57 {
59 for sub_level in levels.l0.sub_levels.iter().rev() {
60 println!(
61 "sub_level_id {} type {} sst_num {} size {}",
62 sub_level.sub_level_id,
63 sub_level.level_type.as_str_name(),
64 sub_level.table_infos.len(),
65 sub_level.total_file_size
66 )
67 }
68 }
69
70 for level in &levels.levels {
71 println!(
72 "level_idx {} type {} sst_num {} size {}",
73 level.level_idx,
74 level.level_type.as_str_name(),
75 level.table_infos.len(),
76 level.total_file_size
77 )
78 }
79 }
80 }
81
82 Ok(())
83}
84
85pub async fn list_pinned_versions(context: &CtlContext) -> anyhow::Result<()> {
86 let meta_client = context.meta_client().await?;
87 let PinnedVersionsSummary {
88 mut pinned_versions,
89 workers,
90 } = meta_client
91 .risectl_get_pinned_versions_summary()
92 .await?
93 .summary
94 .unwrap();
95 pinned_versions.sort_by_key(|v| v.min_pinned_id);
96 for pinned_version in pinned_versions {
97 match workers.get(&pinned_version.context_id) {
98 None => {
99 println!(
100 "Worker {} may have been dropped, min_pinned_version_id {}",
101 pinned_version.context_id, pinned_version.min_pinned_id
102 );
103 }
104 Some(worker) => {
105 println!(
106 "Worker {} type {} min_pinned_version_id {}",
107 pinned_version.context_id,
108 worker.r#type().as_str_name(),
109 pinned_version.min_pinned_id
110 );
111 }
112 }
113 }
114 Ok(())
115}
116
117pub async fn rebuild_table_stats(context: &CtlContext) -> anyhow::Result<()> {
118 let meta_client = context.meta_client().await?;
119 meta_client.risectl_rebuild_table_stats().await?;
120 Ok(())
121}