Repository navigation
Conversation
Track entry weights, support eviction on resize, and grow storage on demand. Co-authored-by: Codex <codex@openai.com>
Sync the weighted LRU implementation and tests with the standalone patch in apache#1174. Co-authored-by: Codex <codex@openai.com>
Co-authored-by: Codex <codex@openai.com>
Co-authored-by: Codex <codex@openai.com>
Use typed cache properties and keep the process capacity configurable through the runtime setter. Reject deletes on the cache adapter and keep older input handles from restoring invalidated bytes. Co-authored-by: Codex <codex@openai.com>
Co-authored-by: Codex <codex@openai.com>
Co-authored-by: Codex <codex@openai.com>
| } | ||
| int64_t size; | ||
| if (length) { | ||
| size = static_cast<int64_t>(*length); |
There was a problem hiding this comment.
FileIO can ignore this length hint. A short hint then stores a prefix as the whole file, so a later unhinted read returns truncated content. Please pass the hint to the backend and use the returned InputFile's Size() for admission and read-ahead.
| if (content_) { | ||
| return std::make_unique<CachedSeekableInputStream>(content_); | ||
| } | ||
| if (auto cached = cache_->Find(location_)) { |
There was a problem hiding this comment.
This handle fixes Size() at construction, while Open() can use a later cache entry. After invalidation and a warm read of a differently sized replacement, this lookup can return the new bytes with the old size. Please require a matching generation and length on the second lookup and cover opening the old handle after the replacement is warm.
| auto& item = candidate.emplace_front(nullptr, std::forward<V>(value)); | ||
| auto [it, inserted] = map_.try_emplace(std::forward<K>(key)); | ||
| item.key = &it->first; | ||
| try { |
There was a problem hiding this comment.
Both callers already know the weight: one per memoized entry or the file size in bytes. Could Replace() take the weight directly, defaulting to 1, so we can remove the throwing callback and rollback path?
|
|
||
| // Apply a new limit immediately, evicting least recently used entries as needed. | ||
| void Resize(int64_t max_weight) { | ||
| ICEBERG_DCHECK(max_weight >= 0, "Cache maximum weight must be non-negative"); |
There was a problem hiding this comment.
A negative limit can drive eviction past the last entry in release builds because this DCHECK is compiled out. Can we validate the limit at the configuration boundary, or return InvalidArgument from Resize() if it accepts unchecked input?
| Result<std::unique_ptr<OutputFile>> NewOutputFile(std::string location) override { | ||
| return io_->NewOutputFile(std::move(location)); | ||
| } | ||
| Status DeleteFile(const std::string& /*location*/) override { |
There was a problem hiding this comment.
Could we give manifest cleanup a single operation that deletes through storage and invalidates the cache? Today every cleanup caller has to remember both steps.
| return GlobalContentCacheRegistry()->SetCapacity(max_caches); | ||
| } | ||
|
|
||
| std::shared_ptr<FileIO> ContentCache::Wrap(std::shared_ptr<FileIO> io) { |
There was a problem hiding this comment.
A cache can be bound to several FileIOs, and a hit is keyed only by location before storage resolution. Could we make the same-storage-namespace requirement explicit at this binding point? Otherwise a rebind to a different backend can serve bytes from the previous one.
| void TrimToCapacity() { | ||
| while (std::cmp_greater(entries_.size(), capacity_)) { | ||
| if (auto entry = entries_.back().lock()) { | ||
| entry->files.reset(); |
There was a problem hiding this comment.
This reset can destroy an entire table's LRU under the registry mutex, blocking lookups for other tables. Could we detach the evicted state under the lock and release it after unlocking?
| 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; |
There was a problem hiding this comment.
Could we clear the table’s manifest cache once per cleanup batch? That would handle all path aliases without adding an InputFile subtype.
Validate LRU weights before admission using the same precheck as Resize. Use prechecks for the equivalent Arrow length and read-range guards.
Summary
Add an internal cache for immutable file content. #875 uses it for manifest files and lists when a table enables caching.
InvalidArgumentbefore the cache changes. Original LRU allocation review.ContentCache::SetGlobalCapacityadjusts the limit immediately and reports the supplied value when it rejects a nonpositive limit. feat: cache immutable manifest content per table #875 exposes this asTable::SetManifestCacheLimit. Global eviction review.Scope
Changes to S3 FileIO and automatic detection of endpoint or prefix rerouting are out of scope for this PR. The bound FileIO must keep each cached location in the same storage namespace for the lifetime of the cache. Credential rotation can reuse the cache when the location still identifies the same immutable object. If a routing change makes the same location refer to a different store, callers must use a fresh cache before reading from that store. Reusing the old cache can serve bytes from the previous store.
Validation
All 473 tests in
util_testand 118 inarrow_testpassed locally. The delete-and-recreate and nested fresh-write regressions both failed on the previous revision. An earlier local run passed all 44 S3 tests against loopback MinIO using a separate S3-enabled Arrow 23.0.1 build and matching AWS SDK. Regression coverage includes theInvalidArgumenterror and property name for malformed numeric settings, identical locations on distinct backends, invalid storage-reported sizes, cold short hints, nested wrappers, alias overwrites, partial writes and deletes, concurrent insertion, and eviction order. An earlier release-mode run passed all 15 LRU and memoization tests with-DNDEBUG. The move regression reproduced a stale weight on the previous revision and now checks that both move construction and move assignment leave the source cache empty and reusable. All repository pre-commit hooks passed.