Repository navigation
feat(clp-s): Expose archive range index metadata in printed archive statistics; Forward archive-level statistics to c++ writers. #1005
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
8e300fa
c425c98
8ff5131
263d51f
20e7e6a
2791749
8e5f865
50ebcaf
9afcff0
9c91ee0
249a5b4
f8b5f74
6ccfa03
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,9 @@ | |
|
|
||
| #include <boost/uuid/uuid.hpp> | ||
| #include <boost/uuid/uuid_io.hpp> | ||
| #include <nlohmann/json.hpp> | ||
|
|
||
| #include "../clp/streaming_archive/Constants.hpp" | ||
| #include "archive_constants.hpp" | ||
| #include "DictionaryWriter.hpp" | ||
| #include "RangeIndexWriter.hpp" | ||
|
|
@@ -31,6 +33,49 @@ struct ArchiveWriterOption { | |
| std::string authoritative_timestamp_namespace; | ||
| }; | ||
|
|
||
| struct ArchiveStats { | ||
| explicit ArchiveStats( | ||
| std::string id, | ||
| epochtime_t begin_timestamp, | ||
| epochtime_t end_timestamp, | ||
| size_t uncompressed_size, | ||
| size_t compressed_size, | ||
| nlohmann::json range_index, | ||
| bool is_split | ||
| ) | ||
| : id{id}, | ||
| begin_timestamp{begin_timestamp}, | ||
| end_timestamp{end_timestamp}, | ||
| uncompressed_size{uncompressed_size}, | ||
| compressed_size{compressed_size}, | ||
| range_index(std::move(range_index)), // Avoid {} to prevent wrapping in JSON array. | ||
| is_split{is_split} {} | ||
|
|
||
|
gibber9809 marked this conversation as resolved.
Resolved
|
||
| [[nodiscard]] auto as_string() const -> std::string { | ||
| namespace Archive = clp::streaming_archive::cMetadataDB::Archive; | ||
| namespace File = clp::streaming_archive::cMetadataDB::File; | ||
| constexpr std::string_view cRangeIndex{"range_index"}; | ||
|
|
||
| nlohmann::json json_msg | ||
| = {{Archive::Id, id}, | ||
| {Archive::BeginTimestamp, begin_timestamp}, | ||
| {Archive::EndTimestamp, end_timestamp}, | ||
| {Archive::UncompressedSize, uncompressed_size}, | ||
| {Archive::Size, compressed_size}, | ||
| {File::IsSplit, is_split}, | ||
| {cRangeIndex, range_index}}; | ||
| return json_msg.dump(-1, ' ', false, nlohmann::json::error_handler_t::ignore); | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
| std::string const id; | ||
| epochtime_t const begin_timestamp{}; | ||
| epochtime_t const end_timestamp{}; | ||
| size_t const uncompressed_size{}; | ||
| size_t const compressed_size{}; | ||
| nlohmann::json const range_index; | ||
| bool const is_split{}; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess the reason you're const qualifying these variables is so that they're not independently modified by a caller? clang-tidy understandably has concerns about const-qualified members, so I wonder if we should just convert
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, this was a rabbit suggestion. I agree it makes sense to just turn it into a full class at this point though. |
||
| }; | ||
|
|
||
| class ArchiveWriter { | ||
| public: | ||
| class OperationFailed : public TraceableException { | ||
|
|
@@ -80,9 +125,11 @@ class ArchiveWriter { | |
| void open(ArchiveWriterOption const& option); | ||
|
|
||
| /** | ||
| * Closes the archive writer | ||
| * Closes the archive writer. | ||
| * @param is_split Whether the last file ingested into the archive is split. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess every archive except the last one is a split? Why do we need this information?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it could be helpful for error handling in some scenarios -- e.g. if some file gets split across two archives and compression fails while the second archive is being compressed we can use this flag to tell that the last file in the first archive hasn't been fully ingested and handle the error appropriately.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How would looking at the printed
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Say a user is ingesting files A and B and we produce two archives, where B is split between the first and the second archive. Consider the scenario where the second archive fails compression such that no archive stats get printed for the second archive. In this scenario, without the is_split flag, the user can see that the first archive contains the files "A" and "B", but has no reliable way of determining that "B" is not fully ingested. However, if they do have the "is_split" flag then they know that they should expect at least one more archive containing the rest of "B". Right now, since we still close/print archive stats for failed archives it's not as useful, but if we improve the error handling in
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have a direct way to figure out which file is split across two archives if one archive contains multiple files
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh the range index is part of the statistics |
||
| * @return Statistics for the newly-written archive. | ||
| */ | ||
| void close(); | ||
| [[nodiscard]] auto close(bool is_split = false) -> ArchiveStats; | ||
|
|
||
| /** | ||
| * Appends a message to the archive writer | ||
|
|
@@ -220,16 +267,20 @@ class ArchiveWriter { | |
| /** | ||
| * Writes the archive to a single file | ||
| * @param files | ||
| * @return The archive range index as a JSON object. | ||
| */ | ||
| void write_single_file_archive(std::vector<ArchiveFileInfo> const& files); | ||
| [[nodiscard]] auto write_single_file_archive(std::vector<ArchiveFileInfo> const& files) | ||
| -> nlohmann::json; | ||
|
|
||
| /** | ||
| * Writes the metadata section of an archive. | ||
| * @param archive_writer | ||
| * @param files | ||
| * @return The archive range index as a JSON object. | ||
| */ | ||
| void | ||
| write_archive_metadata(FileWriter& archive_writer, std::vector<ArchiveFileInfo> const& files); | ||
| [[nodiscard]] auto | ||
| write_archive_metadata(FileWriter& archive_writer, std::vector<ArchiveFileInfo> const& files) | ||
| -> nlohmann::json; | ||
|
|
||
|
gibber9809 marked this conversation as resolved.
Resolved
|
||
| /** | ||
| * Writes the file section of the single file archive | ||
|
|
@@ -245,11 +296,6 @@ class ArchiveWriter { | |
| */ | ||
| void write_archive_header(FileWriter& archive_writer, size_t metadata_section_size); | ||
|
|
||
| /** | ||
| * Prints the archive's statistics (id, uncompressed size, compressed size, etc.) | ||
| */ | ||
| auto print_archive_stats() const -> void; | ||
|
|
||
| static constexpr size_t cReadBlockSize = 4 * 1024; | ||
|
|
||
| size_t m_encoded_message_size{}; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To resolve clang-tidy violation.