diff --git a/influxdb_iox/src/commands/debug/dump_catalog.rs b/influxdb_iox/src/commands/debug/dump_catalog.rs index a0e3f43c23..4c70b5a6b4 100644 --- a/influxdb_iox/src/commands/debug/dump_catalog.rs +++ b/influxdb_iox/src/commands/debug/dump_catalog.rs @@ -1,12 +1,10 @@ -use data_types::DatabaseName; +use crate::structopt_blocks::{object_store::ObjectStoreConfig, server_id::ServerIdConfig}; use iox_object_store::IoxObjectStore; use object_store::ObjectStore; use snafu::{OptionExt, ResultExt, Snafu}; use std::{convert::TryFrom, sync::Arc}; use structopt::StructOpt; -use crate::structopt_blocks::{object_store::ObjectStoreConfig, server_id::ServerIdConfig}; - #[derive(Debug, Snafu)] pub enum Error { #[snafu(display("Cannot parse object store config: {}", source))] @@ -17,11 +15,17 @@ pub enum Error { #[snafu(display("No server ID provided"))] NoServerId, - #[snafu(display("Invalid database name: {}", source))] - InvalidDbName { - source: data_types::DatabaseNameError, + #[snafu(display("Can't read server config from object storage: {}", source))] + CantReadServerConfig { source: object_store::Error }, + + #[snafu(display("Error deserializing server config from protobuf: {}", source))] + CantDeserializeServerConfig { + source: generated_types::DecodeError, }, + #[snafu(display("Can't find a database with this name on this server"))] + CantFindDatabase, + #[snafu(display("Cannot open IOx object store: {}", source))] IoxObjectStoreFailure { source: iox_object_store::IoxObjectStoreError, @@ -56,10 +60,11 @@ pub struct Config { #[derive(Debug, StructOpt)] pub struct DumpOptions { - /// Show debug output of `DecodedIoxParquetMetaData` if decoding succeeds, show the decoding error otherwise. + /// Show debug output of `DecodedIoxParquetMetaData` if decoding succeeds, show the decoding + /// error otherwise. /// - /// Since this contains the entire Apache Parquet metadata object this is quite verbose and is usually not - /// recommended. + /// Since this contains the entire Apache Parquet metadata object this is quite verbose and is + /// usually not recommended. #[structopt(long = "--show-parquet-metadata")] show_parquet_metadata: bool, @@ -78,11 +83,12 @@ pub struct DumpOptions { #[structopt(long = "--show-statistics")] show_statistics: bool, - /// Show unparsed `IoxParquetMetaData` -- which are Apache Thrift bytes -- as part of the transaction actions. + /// Show unparsed `IoxParquetMetaData` -- which are Apache Thrift bytes -- as part of the + /// transaction actions. /// - /// Since this binary data is usually quite hard to read, it is recommended to set this to `false` which will - /// replace the actual bytes with `b"metadata omitted"`. Use the other toggles to instead show the content of the - /// Apache Thrift message. + /// Since this binary data is usually quite hard to read, it is recommended to set this to + /// `false` which will replace the actual bytes with `b"metadata omitted"`. Use the other + /// toggles to instead show the content of the Apache Thrift message. #[structopt(long = "--show-unparsed-metadata")] show_unparsed_metadata: bool, } @@ -101,12 +107,25 @@ impl From for parquet_catalog::dump::DumpOptions { pub async fn command(config: Config) -> Result<()> { let object_store = - ObjectStore::try_from(&config.object_store_config).context(ObjectStoreParsing)?; - let database_name = DatabaseName::try_from(config.db_name).context(InvalidDbName)?; + Arc::new(ObjectStore::try_from(&config.object_store_config).context(ObjectStoreParsing)?); let server_id = config.server_id_config.server_id.context(NoServerId)?; - let iox_object_store = IoxObjectStore::load(Arc::new(object_store), server_id, &database_name) + let server_config_bytes = IoxObjectStore::get_server_config_file(&object_store, server_id) .await - .context(IoxObjectStoreFailure)?; + .context(CantReadServerConfig)?; + + let server_config = + generated_types::server_config::decode_persisted_server_config(server_config_bytes) + .context(CantDeserializeServerConfig)?; + + let database_location = server_config + .databases + .get(&config.db_name) + .context(CantFindDatabase)?; + + let iox_object_store = + IoxObjectStore::load_at_root_path(Arc::clone(&object_store), server_id, database_location) + .await + .context(IoxObjectStoreFailure)?; let mut writer = std::io::stdout(); let options = config.dump_options.into();