Skip to content

Commit

Permalink
In describe_riegeli_file tool, default --show_records_metadata to…
Browse files Browse the repository at this point in the history
… `false`.

Metadata can be large, let’s show the contents only when requested.

Intersperse failures with the rest of the report, so that they can be more
easily attributed to chunks. The convention of formatting failures like comments
with `#` keeps the overall feel of the report as a text proto.

Improve annotations of statuses so that they look more like how `RecordReader`
annotates them.

PiperOrigin-RevId: 604910820
  • Loading branch information
QrczakMK committed Feb 7, 2024
1 parent 10baed7 commit caacf41
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions riegeli/records/tools/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ cc_binary(
"//riegeli/base:arithmetic",
"//riegeli/base:assert",
"//riegeli/base:chain",
"//riegeli/base:status",
"//riegeli/base:types",
"//riegeli/bytes:backward_writer",
"//riegeli/bytes:chain_backward_writer",
Expand Down
23 changes: 15 additions & 8 deletions riegeli/records/tools/describe_riegeli_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "riegeli/base/arithmetic.h"
#include "riegeli/base/assert.h"
#include "riegeli/base/chain.h"
#include "riegeli/base/status.h"
#include "riegeli/base/types.h"
#include "riegeli/bytes/backward_writer.h"
#include "riegeli/bytes/chain_backward_writer.h"
Expand All @@ -59,7 +60,7 @@
#include "riegeli/records/tools/riegeli_summary.pb.h"
#include "riegeli/varint/varint_reading.h"

ABSL_FLAG(bool, show_records_metadata, true,
ABSL_FLAG(bool, show_records_metadata, false,
"If true, show parsed file metadata.");
ABSL_FLAG(bool, show_record_sizes, false,
"If true, show the list of record sizes in each chunk.");
Expand Down Expand Up @@ -275,7 +276,7 @@ absl::Status DescribeTransposedChunk(
return absl::OkStatus();
}

void DescribeFile(absl::string_view filename, Writer& report, Writer& errors) {
void DescribeFile(absl::string_view filename, Writer& report) {
WriteLine("file {", report);
WriteLine(" filename: \"", absl::Utf8SafeCEscape(filename), '"', report);
DefaultChunkReader<FdReader<>> chunk_reader(std::forward_as_tuple(filename));
Expand All @@ -294,7 +295,7 @@ void DescribeFile(absl::string_view filename, Writer& report, Writer& errors) {
if (ABSL_PREDICT_FALSE(!chunk_reader.ReadChunk(chunk))) {
SkippedRegion skipped_region;
if (chunk_reader.Recover(&skipped_region)) {
WriteLine(skipped_region.message(), errors);
WriteLine(" # FILE CORRUPTED: ", skipped_region.ToString(), report);
continue;
}
break;
Expand Down Expand Up @@ -326,16 +327,24 @@ void DescribeFile(absl::string_view filename, Writer& report, Writer& errors) {
default:
break;
}
if (ABSL_PREDICT_FALSE(!status.ok())) WriteLine(status.message(), errors);
if (ABSL_PREDICT_FALSE(!status.ok())) {
WriteLine(" # FILE CORRUPTED: ",
Annotate(chunk_reader.AnnotateStatus(status),
absl::StrCat("at record ", chunk_begin, "/0"))
.message(),
report);
}
}
WriteLine(" chunk {", report);
TextPrintToWriter(chunk_summary, TextWriter<>(&report), print_options)
.IgnoreError();
WriteLine(" }", report);
}
if (!chunk_reader.Close()) {
WriteLine(" # FILE READ ERROR: ", chunk_reader.status().message(), report);
}
WriteLine('}', report);
report.Flush();
if (!chunk_reader.Close()) WriteLine(chunk_reader.status().message(), errors);
}

const char kUsage[] =
Expand All @@ -351,10 +360,8 @@ int main(int argc, char** argv) {
absl::SetProgramUsageMessage(riegeli::tools::kUsage);
const std::vector<char*> args = absl::ParseCommandLine(argc, argv);
riegeli::StdOut std_out;
riegeli::StdErr std_err;
for (size_t i = 1; i < args.size(); ++i) {
riegeli::tools::DescribeFile(args[i], std_out, std_err);
riegeli::tools::DescribeFile(args[i], std_out);
}
std_out.Close();
std_err.Close();
}

0 comments on commit caacf41

Please sign in to comment.