From 76777f58128c4e49286564317845c90237f553a4 Mon Sep 17 00:00:00 2001 From: Konstantin Knizhnik Date: Tue, 21 Dec 2021 15:43:15 +0300 Subject: [PATCH] Add utility for dumping/editing metadata file (#1031) --- pageserver/src/bin/update_metadata.rs | 72 +++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 pageserver/src/bin/update_metadata.rs diff --git a/pageserver/src/bin/update_metadata.rs b/pageserver/src/bin/update_metadata.rs new file mode 100644 index 0000000000..2d90dbbf70 --- /dev/null +++ b/pageserver/src/bin/update_metadata.rs @@ -0,0 +1,72 @@ +//! Main entry point for the edit_metadata executable +//! +//! A handy tool for debugging, that's all. +use anyhow::Result; +use clap::{App, Arg}; +use pageserver::layered_repository::metadata::TimelineMetadata; +use std::path::PathBuf; +use std::str::FromStr; +use zenith_utils::lsn::Lsn; +use zenith_utils::GIT_VERSION; + +fn main() -> Result<()> { + let arg_matches = App::new("Zenith update metadata utility") + .about("Dump or update metadata file") + .version(GIT_VERSION) + .arg( + Arg::with_name("path") + .help("Path to metadata file") + .required(true), + ) + .arg( + Arg::with_name("disk_lsn") + .short("d") + .long("disk_lsn") + .takes_value(true) + .help("Replace disk constistent lsn"), + ) + .arg( + Arg::with_name("prev_lsn") + .short("p") + .long("prev_lsn") + .takes_value(true) + .help("Previous record LSN"), + ) + .get_matches(); + + let path = PathBuf::from(arg_matches.value_of("path").unwrap()); + let metadata_bytes = std::fs::read(&path)?; + let mut meta = TimelineMetadata::from_bytes(&metadata_bytes)?; + println!("Current metadata:\n{:?}", &meta); + + let mut update_meta = false; + + if let Some(disk_lsn) = arg_matches.value_of("disk_lsn") { + meta = TimelineMetadata::new( + Lsn::from_str(disk_lsn)?, + meta.prev_record_lsn(), + meta.ancestor_timeline(), + meta.ancestor_lsn(), + meta.latest_gc_cutoff_lsn(), + meta.initdb_lsn(), + ); + update_meta = true; + } + + if let Some(prev_lsn) = arg_matches.value_of("prev_lsn") { + meta = TimelineMetadata::new( + meta.disk_consistent_lsn(), + Some(Lsn::from_str(prev_lsn)?), + meta.ancestor_timeline(), + meta.ancestor_lsn(), + meta.latest_gc_cutoff_lsn(), + meta.initdb_lsn(), + ); + update_meta = true; + } + if update_meta { + let metadata_bytes = meta.to_bytes()?; + std::fs::write(&path, &metadata_bytes)?; + } + Ok(()) +}