Line data Source code
1 : use std::collections::HashMap;
2 :
3 : use anyhow::Context;
4 : use camino::Utf8PathBuf;
5 : use pageserver::tenant::remote_timeline_client::index::IndexLayerMetadata;
6 : use pageserver::tenant::storage_layer::LayerFileName;
7 : use pageserver::tenant::{metadata::TimelineMetadata, IndexPart};
8 : use utils::lsn::Lsn;
9 :
10 0 : #[derive(clap::Subcommand)]
11 : pub(crate) enum IndexPartCmd {
12 0 : Dump { path: Utf8PathBuf },
13 : }
14 :
15 0 : pub(crate) async fn main(cmd: &IndexPartCmd) -> anyhow::Result<()> {
16 0 : match cmd {
17 0 : IndexPartCmd::Dump { path } => {
18 0 : let bytes = tokio::fs::read(path).await.context("read file")?;
19 0 : let des: IndexPart = IndexPart::from_s3_bytes(&bytes).context("deserialize")?;
20 0 : #[derive(serde::Serialize)]
21 : struct Output<'a> {
22 : layer_metadata: &'a HashMap<LayerFileName, IndexLayerMetadata>,
23 : disk_consistent_lsn: Lsn,
24 : timeline_metadata: &'a TimelineMetadata,
25 : }
26 :
27 0 : let output = Output {
28 0 : layer_metadata: &des.layer_metadata,
29 0 : disk_consistent_lsn: des.get_disk_consistent_lsn(),
30 0 : timeline_metadata: &des.metadata,
31 0 : };
32 :
33 0 : let output = serde_json::to_string_pretty(&output).context("serialize output")?;
34 0 : println!("{output}");
35 0 : Ok(())
36 : }
37 : }
38 0 : }
|