diff --git a/include/dwarfs/writer/internal/metadata_freezer.h b/include/dwarfs/writer/internal/metadata_freezer.h index 1f6af39fe..be54dd5de 100644 --- a/include/dwarfs/writer/internal/metadata_freezer.h +++ b/include/dwarfs/writer/internal/metadata_freezer.h @@ -22,11 +22,14 @@ #pragma once #include +#include #include #include namespace dwarfs { +class logger; + namespace thrift::metadata { class metadata; } @@ -35,8 +38,24 @@ namespace writer::internal { class metadata_freezer { public: - static std::pair, std::vector> - freeze(const thrift::metadata::metadata& data); + metadata_freezer(logger& lgr); + ~metadata_freezer(); + + std::pair, std::vector> + freeze(thrift::metadata::metadata const& data) const { + return impl_->freeze(data); + } + + class impl { + public: + virtual ~impl() = default; + + virtual std::pair, std::vector> + freeze(thrift::metadata::metadata const& data) const = 0; + }; + + private: + std::unique_ptr impl_; }; } // namespace writer::internal diff --git a/src/writer/internal/metadata_freezer.cpp b/src/writer/internal/metadata_freezer.cpp index 36a2438f3..b06e0ae6d 100644 --- a/src/writer/internal/metadata_freezer.cpp +++ b/src/writer/internal/metadata_freezer.cpp @@ -22,6 +22,8 @@ #include #include +#include + #include #include @@ -59,11 +61,33 @@ freeze_to_buffer(const T& x) { return {schema_buffer, data_buffer}; } +template +class metadata_freezer_ : public metadata_freezer::impl { + public: + explicit metadata_freezer_(logger& lgr) + : LOG_PROXY_INIT(lgr) {} + + std::pair, std::vector> + freeze(thrift::metadata::metadata const& data) const override { + auto ti = LOG_TIMED_VERBOSE; + auto rv = freeze_to_buffer(data); + + ti << "freezing metadata to " << rv.second.size() << " bytes..."; + + return rv; + } + + private: + LOG_PROXY_DECL(LoggerPolicy); +}; + } // namespace -std::pair, std::vector> -metadata_freezer::freeze(const thrift::metadata::metadata& data) { - return freeze_to_buffer(data); -} +metadata_freezer::metadata_freezer(logger& lgr) + : impl_{ + make_unique_logging_object( + lgr)} {} + +metadata_freezer::~metadata_freezer() = default; } // namespace dwarfs::writer::internal diff --git a/src/writer/scanner.cpp b/src/writer/scanner.cpp index e37ed421a..0683818a2 100644 --- a/src/writer/scanner.cpp +++ b/src/writer/scanner.cpp @@ -887,7 +887,7 @@ void scanner_::scan( mdb.set_total_hardlink_size(prog.hardlink_size); mdb.gather_global_entry_data(ge_data); - auto [schema, data] = metadata_freezer::freeze(mdb.build()); + auto [schema, data] = metadata_freezer(LOG_GET_LOGGER).freeze(mdb.build()); LOG_VERBOSE << "uncompressed metadata size: " << size_with_unit(data.size());