Repository navigation
feat: cache immutable manifest content per table #875
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 all commits
9b02ccc
1812a51
69da203
182ce44
8ff9a61
2cd135e
9b01988
b448a52
2ca730b
ef627f9
57dac00
94195fd
01ccbf1
8d1eb0e
f0e17f0
e4c55ab
dd0c9b9
7ff8312
a4d9203
e3e6de0
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 |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ | |
| #include <limits> | ||
| #include <mutex> | ||
| #include <optional> | ||
| #include <utility> | ||
| #include <vector> | ||
|
|
||
| #include <arrow/buffer.h> | ||
|
|
@@ -35,6 +36,7 @@ | |
| #include "iceberg/arrow/arrow_io_internal.h" | ||
| #include "iceberg/arrow/arrow_io_util.h" | ||
| #include "iceberg/arrow/arrow_status_internal.h" | ||
| #include "iceberg/content_cache_internal.h" | ||
| #include "iceberg/util/macros.h" | ||
|
|
||
| namespace iceberg::arrow { | ||
|
|
@@ -411,7 +413,7 @@ class ArrowPositionOutputStream : public PositionOutputStream { | |
| int64_t closed_position_ = 0; | ||
| }; | ||
|
|
||
| class ArrowInputFile : public InputFile { | ||
| class ArrowInputFile : public iceberg::internal::InputFileWithStoragePath { | ||
| public: | ||
| ArrowInputFile(std::shared_ptr<::arrow::fs::FileSystem> fs, std::string location, | ||
| std::string path, std::optional<int64_t> file_size) | ||
|
|
@@ -421,14 +423,45 @@ class ArrowInputFile : public InputFile { | |
| file_size_(file_size) {} | ||
|
|
||
| std::string_view location() const override { return location_; } | ||
| std::optional<std::string_view> storage_path() const override { | ||
| const auto type = fs_->type_name(); | ||
| // Local paths can have symlinks, and a custom filesystem defines its own aliases. | ||
| if (type != "s3" && type != "mock") return std::nullopt; | ||
| // Ignore boundary slashes for invalidation, where extra matches are harmless. | ||
| std::string_view key(path_); | ||
| const auto first = key.find_first_not_of('/'); | ||
| if (first == std::string_view::npos) return std::nullopt; | ||
| return key.substr(first, key.find_last_not_of('/') - first + 1); | ||
| } | ||
|
|
||
| Result<int64_t> Size() const override { | ||
| if (file_size_.has_value()) { | ||
| return *file_size_; | ||
| } | ||
| ::arrow::fs::FileInfo file_info(path_, ::arrow::fs::FileType::File); | ||
| ICEBERG_ARROW_ASSIGN_OR_RETURN(auto input, fs_->OpenInputFile(file_info)); | ||
| ICEBERG_ARROW_ASSIGN_OR_RETURN(auto size, input->GetSize()); | ||
| ICEBERG_ARROW_ASSIGN_OR_RETURN(auto info, fs_->GetFileInfo(path_)); | ||
|
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. A file can still open when GetFileInfo fails or reports Unknown. Please keep the open/get-size/close fallback for these cases and cover a readable file whose stat fails. |
||
| if (info.type() == ::arrow::fs::FileType::NotFound) { | ||
| return IOError("File does not exist: {}", location_); | ||
| } | ||
| if (info.type() != ::arrow::fs::FileType::File) { | ||
| return IOError("Not a regular file: {}", location_); | ||
| } | ||
| if (info.size() != ::arrow::fs::kNoSize) { | ||
| file_size_ = info.size(); | ||
| return *file_size_; | ||
| } | ||
| // Some filesystems report a file without a size. | ||
| ICEBERG_ARROW_ASSIGN_OR_RETURN(auto input, fs_->OpenInputFile(info)); | ||
| auto size_result = input->GetSize(); | ||
| auto close_status = input->Close(); | ||
| if (!size_result.ok() && !close_status.ok()) { | ||
| auto status = size_result.status().WithMessage( | ||
| size_result.status().message(), | ||
| "; additionally failed to close file: ", close_status.ToString()); | ||
| ICEBERG_ARROW_RETURN_NOT_OK(status); | ||
| } | ||
| ICEBERG_ARROW_ASSIGN_OR_RETURN(auto size, std::move(size_result)); | ||
| ICEBERG_ARROW_RETURN_NOT_OK(close_status); | ||
| file_size_ = size; | ||
|
manuzhang marked this conversation as resolved.
Resolved
|
||
| return size; | ||
| } | ||
|
|
||
|
|
@@ -445,7 +478,9 @@ class ArrowInputFile : public InputFile { | |
| std::shared_ptr<::arrow::fs::FileSystem> fs_; | ||
| std::string location_; | ||
| std::string path_; | ||
| std::optional<int64_t> file_size_; | ||
| // Set by Size() so a later Open() can skip the size lookup. Not synchronized: like | ||
| // other InputFile handles, this one is not shared across threads. | ||
| mutable std::optional<int64_t> file_size_; | ||
| }; | ||
|
|
||
| class ArrowOutputFile : public OutputFile { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,13 +48,15 @@ Result<std::shared_ptr<RestTable>> RestTable::Make( | |
| std::shared_ptr<Catalog> catalog, std::string full_name, | ||
| std::shared_ptr<MetricsReporter> reporter, RestScanContext rest_context, | ||
| std::unique_ptr<Labels> labels) { | ||
| ICEBERG_PRECHECK(io != nullptr, "FileIO cannot be null"); | ||
| if (metadata == nullptr) { | ||
| return InvalidArgument("Metadata cannot be null"); | ||
| } | ||
| return std::shared_ptr<RestTable>(new RestTable( | ||
| auto table = std::shared_ptr<RestTable>(new RestTable( | ||
|
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. We can revert this line of change. |
||
| std::move(identifier), std::move(metadata), std::move(metadata_location), | ||
| std::move(io), std::move(catalog), std::move(full_name), std::move(reporter), | ||
| std::move(rest_context), std::move(labels))); | ||
| return table; | ||
| } | ||
|
|
||
| Result<std::unique_ptr<DataTableScanBuilder>> RestTable::NewScan() const { | ||
|
|
||
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.
Is
file-ioa better home for these texts?