From 0602b7300106a38bcc8e66e463afbcd10acfda23 Mon Sep 17 00:00:00 2001 From: Chongfeng Hu Date: Fri, 10 Jan 2025 11:43:37 -0800 Subject: [PATCH] Add a new command to nimble_dump: stripes_metadata Summary: `stripes_metadata` dumps the stripes metadata information as referenced by the footer: https://www.internalfb.com/code/fbsource/[3a9c4e4b1b7b7e7b22668f54ddc12f0ccfc904b4]/fbcode/dwio/nimble/tablet/Footer.fbs?lines=52 Differential Revision: D68031461 --- dwio/nimble/tools/NimbleDump.cpp | 25 +++++++++++++++++++++++++ dwio/nimble/tools/NimbleDumpLib.cpp | 25 +++++++++++++++++++++++-- dwio/nimble/tools/NimbleDumpLib.h | 1 + 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/dwio/nimble/tools/NimbleDump.cpp b/dwio/nimble/tools/NimbleDump.cpp index 44914c0..54e363c 100644 --- a/dwio/nimble/tools/NimbleDump.cpp +++ b/dwio/nimble/tools/NimbleDump.cpp @@ -314,6 +314,31 @@ int main(int argc, char* argv[]) { ); // clang-format on + app.addCommand( + "stripes_metadata", + "", + "Print stripes metadata information", + "Prints stripes metadata information as referenced by the footer.", + [](const po::variables_map& options, + const std::vector& /*args*/) { + nimble::tools::NimbleDumpLib{ + std::cout, options["file"].as()} + .emitStripesMetadata(options["no_header"].as()); + }, + positionalArgs) + // clang-format off + .add_options() + ( + "file", + po::value()->required(), + "Nimble file path. Can be a local path or a Warm Storage path." + )( + "no_header,n", + po::bool_switch()->default_value(false), + "Don't print column names. Default is to include column names." + ); + // clang-format on + app.addAlias("i", "info"); app.addAlias("b", "binary"); app.addAlias("c", "content"); diff --git a/dwio/nimble/tools/NimbleDumpLib.cpp b/dwio/nimble/tools/NimbleDumpLib.cpp index d2037bc..adff1bf 100644 --- a/dwio/nimble/tools/NimbleDumpLib.cpp +++ b/dwio/nimble/tools/NimbleDumpLib.cpp @@ -274,8 +274,8 @@ void NimbleDumpLib::emitInfo() { if (!stripesMetadata) { ostream_ << "0" << std::endl; } else { - ostream_ << commaSeparated(stripesMetadata.value().size()) << " (" - << stripesMetadata.value().compressionType() << ")" << std::endl; + ostream_ << commaSeparated(stripesMetadata->size()) << " (" + << stripesMetadata->compressionType() << ")" << std::endl; } auto stripeGroupsMetadata = tablet->stripeGroupsMetadata(); ostream_ << "Stripe Groups Metadata Size: " @@ -865,4 +865,25 @@ void NimbleDumpLib::emitLayout(bool noHeader, bool compressed) { }); } +void NimbleDumpLib::emitStripesMetadata(bool noHeader) { + TabletReader tabletReader{*pool_, file_.get()}; + TableFormatter formatter( + ostream_, + { + {"Offset", 8, Alignment::Left}, + {"Size", 6, Alignment::Left}, + {"Compression Type", 18, Alignment::Left}, + }, + noHeader); + auto stripesMetadata = tabletReader.stripesMetadata(); + if (!stripesMetadata) { + return; + } + formatter.writeRow({ + commaSeparated(stripesMetadata->offset()), + commaSeparated(stripesMetadata->size()), + toString(stripesMetadata->compressionType()), + }); +} + } // namespace facebook::nimble::tools diff --git a/dwio/nimble/tools/NimbleDumpLib.h b/dwio/nimble/tools/NimbleDumpLib.h index 18ff610..b09df78 100644 --- a/dwio/nimble/tools/NimbleDumpLib.h +++ b/dwio/nimble/tools/NimbleDumpLib.h @@ -43,6 +43,7 @@ class NimbleDumpLib { uint32_t streamId, uint32_t stripeId); void emitLayout(bool noHeader, bool compressed); + void emitStripesMetadata(bool noHeader); private: std::shared_ptr pool_;