-
Notifications
You must be signed in to change notification settings - Fork 89
feat(clp-s-ffi-sfa): Expose file list and range info metadata in ClpArchiveReader; Refactor and clean up unit tests.
#2093
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
base: main
Are you sure you want to change the base?
Changes from 6 commits
7f4bec7
0743b83
0440655
36a4e6d
bffd4cc
771d56e
1961fba
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 |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| #include <exception> | ||
| #include <memory> | ||
| #include <new> | ||
| #include <string> | ||
| #include <string_view> | ||
| #include <utility> | ||
| #include <vector> | ||
|
|
@@ -12,6 +13,7 @@ | |
| #include <ystdlib/error_handling/Result.hpp> | ||
|
|
||
| #include <clp/BufferReader.hpp> | ||
| #include <clp_s/archive_constants.hpp> | ||
| #include <clp_s/ArchiveReader.hpp> | ||
| #include <clp_s/ffi/sfa/SfaErrorCode.hpp> | ||
| #include <clp_s/InputConfig.hpp> | ||
|
|
@@ -27,7 +29,9 @@ auto ClpArchiveReader::create(std::string_view archive_path) -> Result<ClpArchiv | |
| auto path{get_path_object_for_raw_path(archive_path)}; | ||
| reader = std::make_unique<clp_s::ArchiveReader>(); | ||
| reader->open(path, NetworkAuthOption{}); | ||
| return ClpArchiveReader{std::move(reader), nullptr}; | ||
| auto clp_archive_reader{ClpArchiveReader{std::move(reader), nullptr}}; | ||
| YSTDLIB_ERROR_HANDLING_TRYV(clp_archive_reader.precompute_archive_metadata()); | ||
| return clp_archive_reader; | ||
| } catch (std::bad_alloc const&) { | ||
| SPDLOG_ERROR( | ||
| "Failed to create ClpArchiveReader for archive {}: out of memory.", | ||
|
|
@@ -57,7 +61,11 @@ auto ClpArchiveReader::create(std::vector<char>&& archive_data) -> Result<ClpArc | |
|
|
||
| archive_reader = std::make_unique<clp_s::ArchiveReader>(); | ||
| archive_reader->open(reader, cDefaultArchiveId); | ||
| return ClpArchiveReader{std::move(archive_reader), std::move(archive_data_owner)}; | ||
| auto clp_archive_reader{ | ||
| ClpArchiveReader{std::move(archive_reader), std::move(archive_data_owner)} | ||
| }; | ||
| YSTDLIB_ERROR_HANDLING_TRYV(clp_archive_reader.precompute_archive_metadata()); | ||
| return clp_archive_reader; | ||
| } catch (std::bad_alloc const&) { | ||
| SPDLOG_ERROR("Failed to create ClpArchiveReader: out of memory."); | ||
| return SfaErrorCode{SfaErrorCodeEnum::NoMemory}; | ||
|
|
@@ -72,9 +80,7 @@ ClpArchiveReader::ClpArchiveReader( | |
| std::shared_ptr<std::vector<char>> archive_data | ||
| ) | ||
| : m_archive_reader{std::move(reader)}, | ||
| m_archive_data{std::move(archive_data)} { | ||
| precompute_archive_metadata(); | ||
| } | ||
| m_archive_data{std::move(archive_data)} {} | ||
|
|
||
| ClpArchiveReader::ClpArchiveReader(ClpArchiveReader&& rhs) noexcept { | ||
| move_from(rhs); | ||
|
|
@@ -107,19 +113,46 @@ auto ClpArchiveReader::close() noexcept -> void { | |
| m_archive_reader.reset(); | ||
| } | ||
| m_event_count = 0; | ||
| m_file_names.clear(); | ||
| m_file_infos.clear(); | ||
| } | ||
|
|
||
| auto ClpArchiveReader::move_from(ClpArchiveReader& rhs) noexcept -> void { | ||
| m_archive_reader = std::move(rhs.m_archive_reader); | ||
| m_archive_data = std::move(rhs.m_archive_data); | ||
| m_event_count = std::exchange(rhs.m_event_count, 0); | ||
| m_file_names = std::move(rhs.m_file_names); | ||
| m_file_infos = std::move(rhs.m_file_infos); | ||
| } | ||
|
|
||
| auto ClpArchiveReader::precompute_archive_metadata() -> void { | ||
| auto ClpArchiveReader::precompute_archive_metadata() -> Result<void> { | ||
| auto const& range_index{m_archive_reader->get_range_index()}; | ||
| m_file_names.reserve(range_index.size()); | ||
| m_file_infos.reserve(range_index.size()); | ||
|
|
||
| uint64_t prev_end_idx{0}; | ||
| for (auto const& range : range_index) { | ||
| m_event_count += static_cast<uint64_t>(range.end_index - range.start_index); | ||
| auto const start_idx{static_cast<uint64_t>(range.start_index)}; | ||
| auto const end_idx{static_cast<uint64_t>(range.end_index)}; | ||
| if (start_idx >= end_idx || start_idx != prev_end_idx) { | ||
|
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. We need to confirm with @gibber9809
Also, @gibber9809 might also want to verify if other
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. Yeah it is valid for If you think that |
||
| return SfaErrorCode{SfaErrorCodeEnum::MalformedRangeIndex}; | ||
| } | ||
| m_event_count += end_idx - start_idx; | ||
|
|
||
| auto const filename_it{ | ||
| range.fields.find(std::string{clp_s::constants::range_index::cFilename}) | ||
| }; | ||
| if (range.fields.end() == filename_it || false == filename_it->is_string()) { | ||
| return SfaErrorCode{SfaErrorCodeEnum::MalformedRangeIndex}; | ||
| } | ||
|
Comment on lines
+142
to
+147
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. Is it guaranteed that every rangeindexentry always has a filename?
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. Need to ask Devin offline.
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. If the range index exists for the archive Granted, the range index reading code currently doesn't validate that these fields exist -- might be worth adding extra validation there to flag corruption so that this code can be simpler. |
||
| auto const filename{filename_it->get<std::string>()}; | ||
|
|
||
| m_file_names.push_back(filename); | ||
| m_file_infos.emplace_back(filename, start_idx, end_idx); | ||
|
|
||
| prev_end_idx = end_idx; | ||
| } | ||
|
|
||
| return ystdlib::error_handling::success(); | ||
| } | ||
| } // namespace clp_s::ffi::sfa | ||
Uh oh!
There was an error while loading. Please reload this page.