Repository navigation
Conversation
…e HEAD
Opening an object went through a HEAD (getObjectMetadata) on every read to learn
its size and ETag, and the result was not cached process-wide, so a scan
re-HEADed every candidate file on every query (traced: ~1 S3 HeadObject per
candidate file, e.g. ~1900 HEADs to read ~550 files). The HEAD is also
mandatory-before-cache-lookup, because the filesystem / page / parquet-metadata
caches key on (path, etag) and the etag comes from the HEAD.
Introduce a process-wide identity cache and a single-request metadata fetch:
* `S3::getObjectIdentity` issues one `GetObjectAttributes` request (size + ETag +
multipart part sizes) and falls back to a plain HEAD if the API is
unsupported, denied, or errors - safe against S3-compatible stores. The ETag
is quote-normalized so the GetObjectAttributes and HEAD paths yield the same
identity (they are used as cache keys). Adds the `GetObjectAttributes` wrapper
to `S3::Client` (mirrors `GetObjectTagging`) and the request alias.
* `ObjectStorageIdentityCache` (experimental singleton) maps path ->
{etag, size, part_offsets}. `S3ObjectStorage::getObjectMetadata` consults it on
the identity path (no tags requested): a hit skips the request entirely; a miss
fetches via `getObjectIdentity` and populates it. The tags path and the
credentials-refresh retry are unchanged.
* `ObjectMetadata` gains `part_offsets` (cumulative multipart part offsets),
derived from the per-part sizes; consumers use it to align reads.
* `IcebergDataObjectInfo` no longer pre-populates object metadata from the
manifest, so Iceberg data files also go through this single identity path and
get the real ETag and multipart layout instead of a synthesized identity.
New ProfileEvents: `S3GetObjectAttributes`, `ObjectStorageIdentityCacheHits`,
`ObjectStorageIdentityCacheMisses`.
Note: the identity path returns no user-metadata attributes (GetObjectAttributes
does not provide them); callers that need them still use the tags path. The
cache is an experimental singleton (not Context-managed / not SYSTEM DROP-able)
and should be promoted before productionization.
Signed-off-by: UnamedRus <[email protected]>
(cherry picked from commit e1b807a)
Replace the process-wide map with a size-bounded CacheBase created from `object_storage_identity_cache_policy`, `_size` and `_size_ratio`, resized on config reload, and cleared by `SYSTEM DROP OBJECT STORAGE IDENTITY CACHE`. S3 reads look it up from the global context and fall back to an uncached request when no context exists. Co-authored-by: Cursor <[email protected]>
… IDENTITY CACHE The new `SYSTEM DROP OBJECT STORAGE IDENTITY CACHE` privilege (added with the Context-managed identity cache) adds a row to `SHOW PRIVILEGES`, so the stateless test reference needs the corresponding line. CI report: https://altinity-build-artifacts.s3.amazonaws.com/json.html?PR=2181&sha=5b16210f9e7dbf582ab7e23983337a9244f2b9fe&name_0=PR&name_1=Fast%20test Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Signed-off-by: UnamedRus <[email protected]>
…Attributes behind a read setting Reading object metadata on a lake scan (`StorageObjectStorageSource`) needs the object size and etag (the etag keys the page / filesystem / Parquet-metadata caches). The identity fast path fetched these via `GetObjectAttributes`, which also returns the multipart part layout used for part-aligned reads - but that request is heavier than a plain `HEAD` and is issued per file, so a cold, cache-empty scan paid one `GetObjectAttributes` per object (measured ~2x slower cold on a wide-Iceberg benchmark) for part offsets it usually does not use. Default `S3ObjectStorage::getObjectMetadata` to a plain `HEAD` (size + etag, no part offsets), and add a read setting `object_storage_identity_cache_fetch_part_offsets` (default off) that opts back into `GetObjectAttributes` when part-aligned reads want the layout. A new 3-argument `IObjectStorage::getObjectMetadata` overload carries the flag; its default implementation ignores it, so non-S3 storages and the many callers that do not need part offsets are unchanged. The etag is still returned on both paths, so the object-storage caches keep working. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Signed-off-by: UnamedRus <[email protected]>
The new `ObjectMetadata::part_offsets` field has no default member initializer, so designated initializers of `ObjectMetadata` that omit it (for example in `AzureObjectStorage`) fail with `-Werror,-Wmissing-designated-field-initializers`. Give the field an explicit empty default instead of touching every call site. Co-authored-by: Cursor <[email protected]>
…setting Add the stateless test `05484_object_storage_identity_cache` for the object storage identity cache. It covers a cold read that misses, a warm read that hits without `HeadObject` or `GetObjectAttributes`, the `SYSTEM DROP OBJECT STORAGE IDENTITY CACHE` and `SYSTEM CLEAR OBJECT STORAGE IDENTITY CACHE` commands, and the `object_storage_identity_cache_fetch_part_offsets` setting. The setting was only read in `createReadBuffer`, which runs after the object metadata is already filled, so it never chose `GetObjectAttributes` on the SQL read path. `KeysIterator` now receives the setting and passes it to `getObjectMetadata`, and the empty-metadata branch does the same. Co-authored-by: Cursor <[email protected]>
The identity cache key was the bucket and the object path. Two S3 endpoints can serve buckets with the same name, so a hit from one endpoint answered for the other with its size and ETag. Include the endpoint and the client region in the key. Fields are separated by NUL so that a slash in one field cannot make two keys equal. The new test `05485_object_storage_identity_cache_endpoint_key` reads the same object through `localhost` and `127.0.0.1` and checks that each endpoint misses on its first read and hits on its second. Co-authored-by: Cursor <[email protected]>
The identity cache was keyed by endpoint, region, bucket and path, but nothing removed an entry when this server replaced or deleted the object. A later read then used the old size as the read bound and the old ETag as If-Match, so it returned truncated data or failed the read until eviction or SYSTEM DROP. - A successful single-part or multipart upload stores the new size and ETag, taken from the upload response, in the cache. If the post-upload size check fails, the entry is dropped instead. - A successful copy, a delete, a batch delete (for each key that was removed or already absent), and a conditional delete that reports a token mismatch or not-found drop the entry. - Each key has a generation number. A metadata fetch stores its result only if the generation is unchanged since before its request, so a HEAD that was in flight during a write cannot put the old identity back. - Entries expire after `object_storage_identity_cache_ttl` seconds (default 3600, zero means no expiry). This bounds the staleness when another writer replaces an object. The new test `05486_object_storage_identity_cache_overwrite` inserts a one-row object, overwrites it with three longer rows without clearing the cache, and checks that the next read is a cache hit that returns all three rows. s3_validate_etag_on_read is disabled, so a stale cached size would truncate the read. Co-authored-by: Cursor <[email protected]>
`getObjectIdentity` stripped the quotes from the ETag it read with GetObjectAttributes, and its HEAD fallback did the same. `getObjectInfo` (HEAD) and PutObject keep the quotes. The identity cache stores this value and `ReadBufferFromS3` sends it as `If-Match`, so the two spellings of one object are different bytes. With `object_storage_identity_cache_fetch_part_offsets = 1` the cache held an unquoted ETag, and with `s3_validate_etag_on_read` on the next read of that object could fail although the object did not change. Both paths now store the quoted form. `quoteETag` adds the quotes when they are missing and leaves an already quoted or weak (`W/"..."`) value unchanged. The new test `05487_object_storage_identity_cache_etag_spelling` keeps `s3_validate_etag_on_read` on. It checks that the ETag read through HEAD and through GetObjectAttributes is the same quoted value, and that the following read hits the cache and returns that value. Co-authored-by: Cursor <[email protected]>
`Context::updateObjectStorageIdentityCacheConfiguration` returned at once when the identity cache pointer was unset. Startup leaves the pointer unset when `object_storage_identity_cache_size` is `0`, so a reload that set a non-zero size did nothing and every read stayed uncached until the next process start. A reload now creates the cache when the new size is non-zero, using the reloaded policy, size ratio, and TTL. The size is still capped by the same RAM limit as at startup. A reload that keeps the size at `0` still leaves the cache disabled. The setting description and the `SYSTEM CLEAR|DROP OBJECT STORAGE IDENTITY CACHE` page say that `SYSTEM RELOAD CONFIG` turns the cache on. Co-authored-by: Cursor <[email protected]>
The overwrite fix added a per-key generation map, a TTL with a timestamp on every entry, and a region in the cache key. None of these is needed for the overwrite case: a write, copy, or delete by this server removes the entry, and the next read requests the metadata again. Keeping them made the cache, the S3 write path, and the settings larger than the fix requires. - ObjectStorageIdentityCache is a plain CacheBase again: tryGet and set. The generation map, setIfEpoch, epochOf, replace, invalidate, and the TTL with its timestamp are removed. - The cache key is the endpoint, the bucket, and the path. The region is removed. - A successful upload calls the upload callback without arguments and the callback removes the entry. The size and ETag are no longer copied from the upload response. - A copy, a delete, a batch delete, and a conditional delete remove the entry through invalidateCachedIdentity. - The object_storage_identity_cache_ttl server setting is removed. - Context::setObjectStorageIdentityCache no longer takes a TTL. The reload path that creates the cache when startup left it disabled, and the ETag spelling fix, are unchanged. The test 05486 expects the read after an overwrite to miss and return all three new rows, and the next read to hit. Co-authored-by: Cursor <[email protected]>
…rite A metadata read takes its HEAD before it stores the result. If this server overwrote, copied or deleted the object in that window, the read stored the size and ETag it fetched before the overwrite. The entry was dropped by the overwrite, so nothing removed the stale value again. Each identity-cache key now has a generation. An overwrite, copy or delete bumps it with `invalidate`, which also removes the entry. A metadata read captures the generation before its request and stores the result with `setIfEpoch`, which skips the store when the generation has changed. `clear` drops the generations together with the entries. Add the pause failpoint `object_storage_identity_cache_pause_before_store` between the fetch and the store, and test 05488 uses it to overwrite the object while a read is paused. The next read must miss and return the new rows. Co-authored-by: Cursor <[email protected]>
… cleared `SYSTEM CLEAR OBJECT STORAGE IDENTITY CACHE` removed the per-key generations along with the entries. A key that had been overwritten therefore looked untouched again, and a metadata read that started before the clear and resumed after it could store the size and ETag it had fetched before the overwrite. `clear` now bumps a cache-wide generation and does not reset it. The fetch captures it together with the per-key generation as the new `ObjectStorageIdentityEpoch`, and `setIfEpoch` stores only when both still match. Test 05489 pauses a read after its HEAD, overwrites the object, clears the cache, and resumes the read. The next read must miss and return the new rows. Co-authored-by: Cursor <[email protected]>
Each `invalidate` of a key left a per-key generation record in `epoch_by_key`, and nothing removed it except `clear`. The map grew by one entry for every overwritten, copied or deleted object for the life of the process, outside the cache's size limit. The map is now accounted in bytes and limited to the cache's configured size. When a new record would exceed that limit, the map is dropped and the cache-wide generation is bumped, so every fetch already in flight fails its `setIfEpoch` check and does not store. One record is always kept, so the map never refuses a key even when that single record is larger than the limit. Co-authored-by: Cursor <[email protected]>
The per-key generation map added to keep stale identities out of the identity cache was large and needed its own byte accounting and cap. A single cache-wide epoch covers the same cases with much less code. `invalidate` (overwrite, copy or delete) and `clear` advance the epoch and `invalidate` also removes the entry. A metadata read captures the epoch before its request and stores the result with `setIfEpoch`, which skips the store when the epoch has changed. The epoch is never reset, so a fetch in flight cannot match a later epoch by accident. The trade-off is that any write, copy or delete of any object makes every metadata fetch in flight skip its store. The fetch still returns its result to the caller, and the next read of the key fetches again. Tests 05488 and 05489 keep their scenarios. Only their comments change. Co-authored-by: Cursor <[email protected]>
…ache A read that found the object replaced kept the cached size and ETag. The next read was pinned to that ETag and failed with `S3_OBJECT_CHANGED_DURING_READ` again, and every retry hit the same entry. Nothing in the read path removed it, because a replace made outside this server does not pass through `S3ObjectStorage::writeObject`. `ReadBufferFromS3` now calls a callback when a GET fails `If-Match` or, for an unversioned read, returns a not-found error. `S3ObjectStorage::readObject` passes a callback that invalidates the key, which also advances the cache epoch so a fetch already in flight cannot store the old identity back. `ObjectStorageIdentityCache` also orders stores per key. `beginFetch` hands out a sequence number, and `setIfEpoch` skips a store when a later fetch of the same key has already stored. An older observation therefore cannot overwrite a newer one. Test 05490 replaces the object with a plain PUT, expects the read to fail with `S3_OBJECT_CHANGED_DURING_READ`, and checks that the retry misses, sends a HEAD, and returns the new rows. Co-authored-by: Cursor <[email protected]>
The metadata fetch for a listed `url()` file called the string overload of `getObjectMetadata`. That overload builds a `RelativePathWithMetadata` without `read_source_index`, so `WebObjectStorage::buildURLs` probed every shard. With several shards that expose the same relative path, the size and ETag could come from a different shard than the one that listed the file, and the read bound could be wrong. `IObjectStorage` gains a `getObjectMetadata` overload that takes the whole `RelativePathWithMetadata` and the part-offset flag. Its default forwards to the object overload, so `WebObjectStorage` keeps the index. `S3ObjectStorage` overrides it to pass the flag to its existing fetch. `createReader` and `createReadBuffer` now call this overload. Test 05491 serves the same file from two local HTTP shards with different sizes and checks that the rows from both shards are returned in full. Co-authored-by: Cursor <[email protected]>
A cache hit in `S3ObjectStorage::getObjectMetadata` returned the object with `is_last_modified_known = false`, so the `_time` virtual column became NULL on every read after the first. The identity cache did not store Last-Modified, and leaving the epoch with the flag set would have made the schema and count caches treat the object as older than every cached entry. `ObjectStorageIdentity` now stores the Last-Modified value and whether it is known. The miss path records the HEAD `last_modification_time`. A hit returns the stored time with the flag set. An unknown time still produces an unknown result on hit, so the schema and count caches keep treating the epoch as a missing timestamp. The new field is placed after `fetch_seq`, so the positional initializer for the identity keeps its meaning. Added the test `05492_object_storage_identity_cache_last_modified`, which reads one S3 object twice and requires the same non-NULL `_time` with a cache hit and no HEAD on the second read. Found by the audit of the identity cache PR: #2888 Co-authored-by: Cursor <[email protected]>
…reshness An identity-cache hit now returns the stored Last-Modified, so `_time` is no longer NULL on repeat reads. The same value was also consumed by the schema cache (`ReadBufferIterator`) and the count-from-files cache (`StorageObjectStorageSource`). After an external replace, the stored time is older than the registration time of the cached schema and row count, so both caches would treat the replaced object as unchanged and return the previous result. `ObjectMetadata` gets `is_last_modified_fresh`, which is cleared when the time came from the identity cache, and `lastModifiedConfirmsUnchanged()`. Both caches now require that check instead of only `is_last_modified_known`. A HEAD or listing that just observed the time still allows the caches to use it. A read pinned to the cached ETag still fails with `S3_OBJECT_CHANGED_DURING_READ` after a replace, and the retry loads the new object, so the count is correct after one failed query. Added the test `05493_object_storage_identity_cache_count_after_replace`: it reads `count()` once, replaces the object with a PUT that bypasses the server, expects `S3_OBJECT_CHANGED_DURING_READ`, and then expects the new count. Found by the audit of the identity cache PR: #2888 Co-authored-by: Cursor <[email protected]>
A filesystem cache (and the page cache) is keyed by the object's ETag. When the identity cache supplies that ETag, a fully cached read never issues a GET, so the `If-Match` check in `ReadBufferFromS3` never runs. After an external replace the cache keeps serving the previous bytes under the old ETag, and nothing in the query reports the change. `ObjectMetadata` gets `is_from_identity_cache`, set on an identity-cache hit. `createReadBuffer` checks it when a filesystem or page cache is about to use the ETag as the key, and re-reads the object through the new `getObjectMetadataIgnoringIdentityCache`. That skips the lookup but still stores the result, so the next read is cached again. An unchanged object keeps its ETag and is served from the cache. A replaced object gets a new key and is read from object storage. The added cost is one HEAD per filesystem-cache read whose identity came from the identity cache. A cold read is unchanged. Added the test `05494_object_storage_identity_cache_filesystem_cache_replace`: it reads an object into `cache_for_readbigat`, checks that the next read is a cache hit that still sends a HEAD, replaces the object with a PUT that bypasses the server, and expects the new rows. Found by the audit of the identity cache PR: #2888 Co-authored-by: Cursor <[email protected]>
`GetObjectAttributes` cannot request Last-Modified in this SDK, so a successful part-offset fetch left `last_modification_time` at 0. The identity cache then stored that as "the object has no modification time", and every later `_time` read from the cache was NULL, including reads with part offsets disabled. `S3::ObjectInfo` gets `last_modification_time_observed`, set only by a HEAD response. The identity gets `last_modified_observed`. A cache entry without an observed time is not returned as a complete identity. The read keeps the cached part offsets and issues a HEAD for the time. The stored entry then carries the HEAD's time. The part offsets are kept only while the ETag is unchanged. A HEAD that really returns a zero modification time is still cached as unknown. Added the failpoint `object_storage_identity_cache_skip_last_modified`, which simulates an attributes response without Last-Modified, and the test `05495_object_storage_identity_cache_part_offsets_time`. It reads one object with part offsets enabled and expects `_time` to be NULL. It then disables the failpoint and expects a non-NULL `_time` with a HEAD. Found by the audit of the identity cache PR: #2888 Co-authored-by: Cursor <[email protected]>
…bjectAttributes A filesystem or page cache hit re-reads the identity before using its ETag as the cache key. When the cached identity came with part offsets, that re-read used GetObjectAttributes. That call does not return Last-Modified, so the revalidating read reported `_time` as NULL and the store replaced the cached time with "not observed". The revalidation now uses a HEAD, which returns the ETag and Last-Modified. `ObjectStorageIdentityCache::setIfEpoch` keeps the part offsets already stored when the fetch saw the same ETag, because a HEAD does not return them. A different ETag still drops them. Adds test 05496 covering the primed, revalidated, and later reads. Co-authored-by: Cursor <[email protected]>
…ity-cache ETag A footer-only Parquet `count()` reads the row count from the parquet metadata cache and never issues a GET. `ParquetMetadataCache` keys by ETag, and the ETag came from the identity cache. After an external replace, the count returned the old row count, and `s3_validate_etag_on_read` never ran because no GET was sent. When the read is a Parquet count and `use_parquet_metadata_cache` is enabled, `createReadBuffer` now revalidates an identity-cache ETag with a HEAD, using the same path as the filesystem and page caches. Parquet reads that GET the data still check the ETag there and are unchanged. Adds test 05497 that counts a Parquet object, replaces it externally, and expects the next count to return the new row count after a HEAD. Co-authored-by: Cursor <[email protected]>
The identity cache had a second source of identity: `GetObjectAttributes`, which carried multipart part offsets, and a `last_modified_observed` flag because that request does not return Last-Modified. That path was not in any release, so it is removed rather than kept as dead complexity. Every identity-cache entry now comes from a HEAD, which always returns size, ETag and Last-Modified. `getObjectMetadata` no longer takes `fetch_part_offsets`, `setIfEpoch` only checks the epoch and `fetch_seq`, and the `object_storage_identity_cache_fetch_part_offsets` setting, the `object_storage_identity_cache_skip_last_modified` failpoint, and the `S3GetObjectAttributes` and `DiskS3GetObjectAttributes` events are removed. The S3 client's `getObjectIdentity` wrapper is removed. The fixes from earlier commits are kept: a cache hit reports Last-Modified with `is_last_modified_fresh` set to false, and filesystem, page and Parquet footer-only count revalidation issue a HEAD before using a cached ETag. Tests 05495 and 05496 covered only the part-offset path and are removed. Tests 05484, 05485, 05486 and 05490 no longer count `GetObjectAttributes`. Co-authored-by: Cursor <[email protected]>
An identity-cache hit returns the previous size and ETag. Two decisions used that metadata without a GET, so an external replace could be dropped unread: - `s3_skip_empty_files` (on by default) skipped a file whose cached size was 0, in `StorageObjectStorageSource::createReader` and `ReadBufferIterator`. - A query condition cache hit that dropped every row group, or every row group left after the bucket filter, skipped a file whose cached ETag was the key. A new helper `revalidateIdentityCachedObjectMetadata` replaces an identity-cache hit with a HEAD before those decisions. Data-lake keys do not contain the ETag, so they are not revalidated for the condition cache. Reads that do not skip still use the cache and do not pay the HEAD. Adds test 05498 that replaces an empty object and a Parquet object that the condition cache would have skipped, then expects the new rows after a HEAD. Co-authored-by: Cursor <[email protected]>
…acement The empty-file check in createReader runs once, before the query condition cache loop. A condition-cache hit that drops the whole file re-HEADs the object, which can reveal that the replacement is empty. That path then fell through and opened the object, and formats such as Parquet throw on an empty file. Apply the empty-file skip again after the re-HEAD, honoring `s3_skip_empty_files`. Extend the 05498 test with an empty Parquet replacement behind a condition-cache hit. Co-authored-by: Cursor <[email protected]>
…alya-26.8/object-storage-identity-cache Co-authored-by: Cursor <[email protected]>
…aded-virtual The private three-argument `S3ObjectStorage::getObjectMetadata` shared its name with the `IObjectStorage::getObjectMetadata` overloads, so clang's `-Woverloaded-virtual` (an error under `-Werror`) reported it as hiding the two-argument `RelativePathWithMetadata` overload. Rename it to `getObjectMetadataImpl`; the public overrides keep their signatures. Co-authored-by: Cursor <[email protected]>
… cache test The stateless runner can randomize `read_from_filesystem_cache_if_exists_otherwise_bypass_cache` to 1. In that mode a cache miss reads from S3 and does not store the segment. Test 05494 clears `cache_for_readbigat`, so the cold read leaves nothing behind, and the cached read misses and issues a `S3GetObject`. The test expects zero GETs there. Set the setting to 0 in the test's read settings, as other filesystem cache tests do, so a miss populates the cache and the warm read is a cache hit. Co-authored-by: Cursor <[email protected]>
`ReadBufferFromS3` drops the cached identity on a `412`, on an ETag drift in the response and on a `404`. A store that ignores `If-Match` answers a read that is bounded by the cached size of a replaced object with `416 Requested Range Not Satisfiable` when the new object is shorter. That case did not call `rejectCachedIdentity`, so the stale size stayed and every retry failed the same way. Drop the entry on `416` as well. No test: the mock S3 server honours `If-Match`, so it answers `412` and never reaches this branch. Related: #2888 Related: #2181 Co-authored-by: Cursor <[email protected]>
…omic `object_creation_request_sent` is set by the upload worker before `PutObject` or `CompleteMultipartUpload` and read by `preFinalize`, `finalizeImpl`, `cancelImpl` and the destructor. The readers normally run after the worker has finished. The catch of `preFinalize`, though, can also run for an exception from the code that queues the task, while a worker that was queued earlier still runs. A plain `bool` is a data race in that case. Make the flag `std::atomic<bool>`. No test: the window needs an exception between queueing and waiting for a task. Related: #2888 Related: #2181 Co-authored-by: Cursor <[email protected]>
…he HEAD in the identity cache `getObjectMetadataImpl` stored the credential hash of `client.get()` after the request. A credential refresh on another thread can replace `client` between the request and the store, so the entry then carried the credentials of a later client than the one that signed the HEAD. A principal with other credentials could then hit an entry that it did not fetch, or the owner could miss it. Keep the client of the request, and hash its credentials. No test: the window needs a refresh between the HEAD and the store. Related: #2888 Related: #2181 Co-authored-by: Cursor <[email protected]>
The legacy `DeltaLakeMetadata` reads `_last_checkpoint`, which every checkpoint rewrites in place. `createReadBuffer` took its identity from the identity cache and pinned the GET to that ETag. The cache does not see an external replace, so the first query after a checkpoint failed with `S3_OBJECT_CHANGED_DURING_READ`. Read the identity of the file with `getObjectMetadataIgnoringIdentityCache` before the read. No test: the legacy reader runs only with `allow_experimental_delta_kernel_rs` off and needs a Delta table that a second writer advances between two queries. Related: #2888 Related: #2181 Co-authored-by: Cursor <[email protected]>
…elImpl` `cancelImpl` is `noexcept` and called `notifyUploadComplete` after the upload task finished, without the `try` and `catch` that the destructor has. An exception from the `on_upload_complete` callback would reach `std::terminate`. Log the exception instead, as the destructor does. The identity was already dropped or is dropped by the callback itself, so nothing else is needed. Related: #2888 Related: #2181 Co-authored-by: Cursor <[email protected]>
…it of its delete `KeeperSnapshotManagerS3` invalidated the cached identity of the lock file after `DeleteObject` returned. `DeleteObject` can throw after the request was sent (a memory limit while the response is read, too many redirects, a cancelled query), and the delete may already have been applied. The invalidation was then skipped and the entry described a deleted object. Use a `SCOPE_EXIT_MEMORY` guard declared before the request, as the other delete paths do. No test: it needs a failure after the request was sent in a Keeper snapshot upload. Related: #2888 Related: #2181 Co-authored-by: Cursor <[email protected]>
…inds the object gone Two uncached metadata requests left the entry of a deleted object in the identity cache: - `tryGetObjectMetadataImpl`, which serves `s3_ignore_non_existent_file = 1` and the schema cache lookup, returned "not found" without touching the cache. - `getObjectMetadataImpl` dropped the entry only when the first HEAD failed. When a credentials refresh callback returned a new client, the retried HEAD threw outside that branch and the entry stayed. A later hit then described an object that does not exist, and a read sent a GET for it. Drop the entry in both places. Add `05823_object_storage_identity_cache_dropped_by_ignored_missing_file`. Related: #2888 Related: #2181 Co-authored-by: Cursor <[email protected]>
`getObjectMetadataImpl` stored every non-empty ETag in the identity cache and `etag_is_strong` stayed `true` for S3 objects. An S3-compatible gateway or proxy can return a weak ETag (`W/"..."`, RFC 9110) that does not change when the content, and so the size, changes. A hit would then bound a read by the previous size, and the ETag could key the filesystem, page or parquet metadata caches. Mark a weak ETag of a HEAD response as not strong, and treat it like a missing ETag in the identity cache: do not store it and drop an entry stored earlier. AWS S3 returns strong ETags, so nothing changes there. No test: the mock S3 server does not return weak ETags. Related: #2888 Related: #2181 Co-authored-by: Cursor <[email protected]>
…n object version The identity cache key is `(endpoint, bucket, path)` and has no version, and a HEAD without a version describes the latest one. `ReadBufferFromS3` sends no `If-Match` for a read with `?versionId=`, so nothing rejects a hit that carries the size of another version. A query that reads `key?versionId=V2` after `key` was cached with the size of an earlier version bounded the read by that size and returned a truncated object without an error. Do not take a hit when the URI has a version id. The HEAD result is still stored: it is the identity of the latest version, which is what the key describes. No test: the mock S3 server does not support object versioning. Related: #2888 Related: #2181 Co-authored-by: Cursor <[email protected]>
An identity cached for an empty object has `size_bytes == 0`. A read that is bounded by 0 sends no GET, so `If-Match` cannot notice that the object was replaced outside the server, and the query returned no rows for an object that has content. The caller revalidated an empty hit only when `s3_skip_empty_files` is on. `createReadBuffer` now also re-reads the identity with a HEAD when a hit has a known size of 0, regardless of `s3_skip_empty_files`. Related: #2888 Co-authored-by: Cursor <[email protected]>
…y-file check `One` returns a row per object without reading it, so no GET follows and `If-Match` cannot reject an identity cached for a replaced object. The HEAD that confirms the hit ran after the empty-file check, which used the cached size: an object replaced by an empty one was counted as a row instead of being skipped. The revalidation of a `One` hit now happens in the object selection loop, before the empty-file check. A hit of an archive entry is handled the same way. Related: #2888 Co-authored-by: Cursor <[email protected]>
… be cached The HEAD that confirms an identity cache hit before a Parquet read was sent for every Parquet read when `use_parquet_metadata_cache` is on (the default), which removed the saving of the cache for the most common format. The HEAD is needed only when the read may send no GET, that is when the parquet metadata cache holds the footer for the path and the cached ETag: a footer miss reads the footer with a GET that `If-Match` checks. The HEAD is now sent only if the footer is in the cache, and never for data lake configurations whose data files are not overwritten in place (`dataFilesAreImmutable`). Related: #2888 Co-authored-by: Cursor <[email protected]>
…tart The size is applied on `SYSTEM RELOAD CONFIG` by `updateObjectStorageIdentityCacheConfiguration`, like the size of the other caches, but it was not listed in `collectChangeableServerSettings`. `system.server_settings` then reported `changeable_without_restart = No` and the value from the startup configuration instead of the one in use. Related: #2888 Co-authored-by: Cursor <[email protected]>
…thout restart Related: #2888 Co-authored-by: Cursor <[email protected]>
Startup with `object_storage_identity_cache_size = 0` leaves the cache unset, but a reload to 0 kept the cache with a zero limit: every lookup counted a miss and took the locks of a cache that cannot hold anything, and `system.server_settings` kept reporting the cache. The reload now unsets the cache, as the startup does. A reader that holds the pointer finishes with the old cache, and a later reload that raises the size creates an empty one. Related: #2888 Co-authored-by: Cursor <[email protected]>
`05821` did not pin `use_query_condition_cache`, and the test runner randomizes it. With it on, the stale entry is revalidated by the query condition cache loop, so the test passed without the Parquet metadata cache revalidation that it covers. `05489` overwrote the object through the server. That invalidates the key, and the slot barrier alone rejects the paused store, so the drop of the whole cache (`cleared_at`) was not what the test checked. The overwrite now goes around the server. Related: #2888 Co-authored-by: Cursor <[email protected]>
`s3_ignore_non_existent_file` is not a setting, the S3 one is `s3_ignore_file_doesnt_exist`. Related: #2888 Co-authored-by: Cursor <[email protected]>
They are output of a local run, committed together with the test `05824`. Related: #2888 Co-authored-by: Cursor <[email protected]>
…n for Parquet Since the Parquet revalidation became conditional on a cached footer, the main pass of a lazy read can skip the HEAD (the footer is not cached yet), cache the footer by its pinned GET, and leave the identity-cache flag set on the shared `ObjectInfo`. The second pass then found the footer cached, re-read the identity with a HEAD, and pinned its GET to the ETag of a replaced object: the deferred columns came from the new version with the row numbers of the previous one. The second pass (`rows_to_read` is set) no longer revalidates, so its GET stays pinned to the generation that the main pass read and a replaced object fails the read. Also correct the comment that still described the flag as set for every Parquet read. Related: #2888 Co-authored-by: Cursor <[email protected]>
`removeObjectsIfExistImpl` kept the cached identity of a key whose `DeleteObjects` result held an error other than "not found". An error such as `InternalError` or `SlowDown` does not tell whether the object was deleted, and the single-key delete and `removeObjectsImpl` drop the entry on every outcome. The guard now drops every key on every exit, which also removes the quadratic scan of keys against errors. Related: #2888 Co-authored-by: Cursor <[email protected]>
…he hit The gate that re-reads the identity before a Parquet read looked at the parquet metadata cache once. Another read could put the footer for the same path and ETag there afterwards, and an object replaced in the meantime was then answered from that footer with no GET and no HEAD (a `count`, or a read where row group pruning drops every row group). A hit of the identity cache that no HEAD confirmed now neither reads nor fills the parquet metadata cache. Its GET is pinned to the ETag and reads the footer itself. Data lake data files, which are not overwritten in place, keep using the cache. Related: #2888 Co-authored-by: Cursor <[email protected]>
…the context mutex The reload to size 0 reset the pointer while holding the exclusive `ContextSharedPart::mutex`. A read that still held the cache kept all its entries and metrics alive, which `SYSTEM CLEAR OBJECT STORAGE IDENTITY CACHE` could no longer reach. With no read in flight, the whole cache was destroyed under the mutex and stalled every caller that waited for it. The reload now moves the cache out under the mutex and clears it after the mutex is released. Related: #2888 Co-authored-by: Cursor <[email protected]>
…the cache is disabled With size 0 the cache does not exist, so `collectChangeableServerSettings` did not list the setting and `system.server_settings` reported `changeable_without_restart = No`, although a reload with a non-zero size creates the cache. The entry is now always listed, with the value 0 for a missing cache. Related: #2888 Co-authored-by: Cursor <[email protected]>
…t gone `getObjectMetadataImpl` invalidated the entry on a 404 only through the cache pointer that it captured before the request. A request for tags (`_tags`) does not use the identity cache and has no pointer, and a config reload can replace the cache during the request, so the entry of a deleted object stayed and the next read took its size and ETag from the cache. The invalidation now goes through the global cache. Related: #2888 Co-authored-by: Cursor <[email protected]>
…rom `05491` `05493` covers the count-from-files cache, which is consulted only with `optimize_count_from_files`, and the runner randomizes that setting: without it the read of the replaced object failed on the changed ETag and the test passed without the fix. `05491` picked two free ports, closed them, and bound them later. The servers now bind port 0 and report their ports through a file. Related: #2888 Co-authored-by: Cursor <[email protected]>
The ETag of an object that comes from `ListObjectsV2` was always treated as strong, while the HEAD paths already recognize a weak validator (`W/"..."`). An S3-compatible gateway that returns weak ETags then had them key the filesystem, page, and parquet metadata caches when the metadata came from the listing. Both listing sites now set `etag_is_strong` the way the HEAD sites do. The pin of a GET to the ETag is not changed: a weak ETag in `If-Match` fails the read with 412, which stays fail-closed. Related: #2888 Co-authored-by: Cursor <[email protected]>
A format that checks the size before it reads anything (Parquet, ORC and Arrow reject a file shorter than their magic and footer) fails on the previous object's size with `INCORRECT_DATA` before any GET is sent. With the prefetch off no GET rejects the hit either, so a tiny object that was replaced outside the server kept failing every read. The zero-size revalidation is widened to every hit of 32 bytes or less, which costs one HEAD for an object that small. Related: #2888 Co-authored-by: Cursor <[email protected]>
…observes `tryGetObjectMetadataImpl` asks the store without the identity cache, and kept the cache as it was. A read that looks at the object there first (`s3_ignore_file_doesnt_exist`, the schema cache lookup) and then takes the stale hit from the cache fails on the changed ETag. The request now takes part in the clock protocol the way a miss of `getObjectMetadataImpl` does: `beginFetch` before it, and the store, or the invalidation for an identity without a strong ETag, after it. The store is shared in `storeObservedIdentity`. A missing `Last-Modified` is now reported as unknown there too, as in `getObjectMetadataImpl`. Related: #2888 Co-authored-by: Cursor <[email protected]>
`createReadBuffer` confirms a hit of the identity cache with a HEAD for several reasons that the empty-file check in `createReader` does not know about (a content cache, a tiny size). When that HEAD finds that an object with a non-zero cached size was replaced by an empty one, the reader was still created, and a format such as Parquet failed with `INCORRECT_DATA` even though `s3_skip_empty_files` is on. The reader now produces no rows for such an object, as it does when the empty-file check sees the empty size. Related: #2888 Co-authored-by: Cursor <[email protected]>
… reject short files The tiny-size revalidation sent a HEAD for every identity cache hit of at most 32 bytes. Only a format that checks the size before it reads anything (Parquet, ORC, Arrow) can fail on the previous size without a GET that `If-Match` would reject. For other formats a GET follows. A cached size of 0 stays revalidated for every format, because no GET follows it. Related: #2888 Co-authored-by: Cursor <[email protected]>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Object storage identity cache
Pull request: #2888
This is a part of #2181, split into a separate pull request.
Branch
feature/antalya-26.8/object-storage-identity-cacheagainstantalya-26.8.The change is an in-memory cache of S3 object identity so a repeated open does not send a
HEADfor size, ETag, and Last-Modified.What is stored
ObjectStorageIdentityCacheis a process-wideCacheBase(SLRU by default) owned by the globalContext. Each entry is one object on one store:The value does not include tags, user metadata, or part offsets. A miss is a plain
HEAD(S3::getObjectInfo). A request that asks for tags does not read or update the cache.tryGetObjectMetadatadoes not use the cache either.A hit sets
ObjectMetadata::is_from_identity_cache. When the stored Last-Modified is known, the hit also setsis_last_modified_freshto false._timemay still show that time, but the schema cache and the count cache do not treat it as proof that the object is unchanged (lastModifiedConfirmsUnchanged). As a result, a query on an S3 object whose identity came from the cache infers the schema and counts the rows again instead of using those caches.docs/reference/statements/system.mdxsays so, andtest_storage_s3::test_schema_inference_cacheexpects no number-of-rows cache hit fors3on the repeated count, and a hit when the count is repeated withs3_validate_etag_on_read = 0, which skips the identity cache.When the cache is used
S3ObjectStorage::getObjectMetadataconsults the cache only for an identity-only read (with_tagsfalse).getObjectMetadataIgnoringIdentityCachealways issues theHEADand still stores the result.Before the
HEAD, the fetch takesbeginFetch, which returns the next value of a logical clock.setIfNotInvalidatedstores the result only when the key was not invalidated after the fetch began and no later fetch of the same key has stored. The cache keeps one barrier per slot (65536 slots, chosen by the hash of the key) and one barrier for the whole cache, set byclear. An invalidation raises the barrier of the slot of that key only, so a write to one object does not stop the store of a fetch of another object. Without that, a server that writes to S3 all the time (aMergeTreetable or a system log on an S3 disk) would drop most identities before they are stored. Two keys that share a slot can only cause a skipped store, never a stale one: the next read of that key sendsHEADagain. A fetch that started earlier cannot overwrite a fetch of the same key that started later, even if the later entry was evicted. The ordering state is guarded by one mutex that is taken before the cache mutex.Iceberg data files are not filled from the manifest. The comment in
IcebergDataObjectInfoleaves identity empty so the first metadata read goes through this cache and the ETag used by the filesystem, page, and Parquet metadata caches is the one returned by S3.url()keepsread_source_indexon the object when metadata is fetched. The same relative path can come from different expanded URL shards (http://{host1,host2}/...). The schema and count cache key includes that index, andWebObjectStorage::readObjectuses it to pick the shard instead of treating every shard as a failover of the first one. Test05491_url_object_metadata_shard.Invalidation
S3ObjectStorage::invalidateCachedIdentitydrops the entry and raises the barrier of the slot of the key, so the stores of fetches of that key that began earlier are rejected. It runs when this server removes, conditionally deletes, or finishes writing the object, and after a successful copy, on the destination.WriteBufferFromS3takes anon_upload_completecallback and runs it after the upload has replaced the object, including when the post-upload size check fails.A
GETthat sees the object change also drops the entry, throughReadBufferFromS3::rejectCachedIdentity:S3_OBJECT_CHANGED_DURING_READ)GETreturns 404SYSTEM CLEAR OBJECT STORAGE IDENTITY CACHEandSYSTEM DROP OBJECT STORAGE IDENTITY CACHEdrop every entry and reject the store of every fetch that began before the clear. The privilege isSYSTEM DROP OBJECT STORAGE IDENTITY CACHE, grouped underSYSTEM DROP CACHE. A fetch paused across the clear cannot store afterwards (failpointobject_storage_identity_cache_pause_before_store).An overwrite made by another client is not visible to this invalidation. The next read that needs the bytes still compares ETags (
s3_validate_etag_on_read, default on) and the paths below re-HEADbefore they would skip the object or serve it from another cache.Re-HEAD before a decision that would not GET
A hit is enough for a read that still sends
GET: If-Match rejects a replaced object. It is not enough when the server would skip theGET.revalidateIdentityCachedObjectMetadatareturns immediately unlessis_from_identity_cacheis set. Otherwise it sendsHEADthroughgetObjectMetadataIgnoringIdentityCache, using the archive path when the object is an archive, and replaces the metadata. After that,is_from_identity_cacheis false, so a later step does notHEADagain.s3_skip_empty_filesis on (the default), the size is known, and the cached size is 0,createReaderre-HEADs before skipping. The same check is inReadBufferIteratorfor schema inference.HEADs once and looks up again. The condition-cache key is path plus ETag. If the refreshed size is known and 0 ands3_skip_empty_filesis on, the file is skipped. A partial hit still reads and relies on If-Match. Data-lake condition-cache keys do not include the ETag, and those scans are not re-HEADed for this cache.createReadBufferre-HEADs when the metadata came from the identity cache, the size is known, and the ETag can be a cache key. The filesystem cache key is a hash of path plus ETag. An unchanged object keeps the key. A replaced object gets a new key and is read again. Other Parquet reads still check the ETag onGET.Configuration and observability
Server settings, also applied by
SYSTEM RELOAD CONFIG:object_storage_identity_cache_size, default 64 MiB.0disables the cache. A reload with a non-zero size creates the cache when startup left it disabled.object_storage_identity_cache_policy, defaultSLRUobject_storage_identity_cache_size_ratio, default0.5Profile events:
ObjectStorageIdentityCacheHits,ObjectStorageIdentityCacheMisses.Current metrics:
ObjectStorageIdentityCacheBytes,ObjectStorageIdentityCacheCells.If there is no global context yet, the metadata request is issued uncached.
docs/reference/statements/system.mdxdocumentsSYSTEM CLEAR|DROP OBJECT STORAGE IDENTITY CACHE.The private three-argument metadata method is
getObjectMetadataImpl. The namegetObjectMetadatawould hide the two-argumentIObjectStorage::getObjectMetadataand fail the build with-Werror,-Woverloaded-virtual.Iceberg constant columns
This is not part of the cache. It fixes a failure of
04890_iceberg_metadata_spec_violation_no_abortseen in the CI of this pull request (report), and it is inStorageObjectStorageSource::createReader.A data file with one row has equal lower and upper bounds, and with
allow_experimental_iceberg_read_optimization(default on) the reader builds a constant column from the bound instead of reading the column. The bound is aFieldof the type of the file. After a schema change the column has another type, so the column was built from aFieldof another kind and the query failed withBAD_GET(a primitive that became a struct, and also int to string or date to timestamp), while the same query with the optimization off returned the value orICEBERG_SPECIFICATION_VIOLATION.tryGetConstantFromBounduses the bound only whentryConvertFieldToTypegives aFieldof the same kind (for example int to long). Otherwise the column is read from the file, where the schema evolution converts the values or rejects the change withICEBERG_SPECIFICATION_VIOLATION. An earlier version of this change raised that error from the constant path instead, and a conversion that changes the kind (days of a date to ticks of a timestamp) returned a wrong value, so the bound is skipped and not converted.Test
05819_iceberg_constant_column_type_mismatch: int to long keeps the value, date to timestamp gives the same value with the optimization on and off (it failed withBAD_GETbefore the change), and long to struct is rejected with and without the optimization and through parallel replicas.Tests
Stateless tests under
tests/queries/0_stateless/, allno-fasttest(mock S3 atlocalhost:11111),no-parallel(the cache is process-wide):05484_object_storage_identity_cacheHEAD.05485_object_storage_identity_cache_endpoint_key05486_object_storage_identity_cache_overwrite05488_object_storage_identity_cache_stale_storeHEADdoes not overwrite a newer one.05489_object_storage_identity_cache_clear_during_fetchSYSTEM CLEAR OBJECT STORAGE IDENTITY CACHEduring a fetch rejects the store.05490_object_storage_identity_cache_external_replace05491_url_object_metadata_shardurl()metadata fetch keeps the shard index.05492_object_storage_identity_cache_last_modified05493_object_storage_identity_cache_count_after_replace05494_object_storage_identity_cache_filesystem_cache_replaceHEAD. A replaced object is read again. The read settings pinread_from_filesystem_cache_if_exists_otherwise_bypass_cacheto 0, because the stateless runner can turn that setting on and then a miss is not stored.05497_object_storage_identity_cache_parquet_count_after_replaceHEADs before using a cached ETag.05498_object_storage_identity_cache_skip_replacedHEADbefore the skip. Replacing the object with an empty Parquet file is skipped instead of opened.05499_object_storage_identity_cache_unvalidated_replaces3_validate_etag_on_read = 0theGEThas no If-Match, so a cached size is re-checked with aHEADand an external replace returns the new rows. TheHEADrefreshes the entry.05500_object_storage_identity_cache_backup_replaceBackupWriterS3drops the entry, so the next read does not fail withS3_OBJECT_CHANGED_DURING_READ.05814_object_storage_identity_cache_partial_condition_cache_replaceHEADfirst.05815_object_storage_identity_cache_restore_to_cached_diskRESTOREto an S3 disk wrapped by the filesystem cache still copies natively.05816_object_storage_identity_cache_request_headers_principalheaders('Authorization' = ...)) do not share an entry. The same headers hit.05817_object_storage_identity_cache_weight_counts_keyObjectStorageIdentityCacheBytesis not under-reported for long paths.05818_object_storage_identity_cache_unrelated_writesIntegration test
tests/integration/test_storage_s3/test.py::test_schema_inference_cachecovers the schema cache and number-of-rows cache bypass described above.01271_show_privilegesand04836_system_cache_on_cluster_access_typeslist the new system-query privilege.Scope that stayed out
The cache does not store tags or user metadata. A metadata read that needs them always goes to S3.
tryGetObjectMetadatais unchanged and does not fill the cache. A read that ignores a missing file uses that path when metadata is absent. A later re-HEADof an entry that is already cached usesgetObjectMetadataand throws if the object has been deleted.Virtual columns
_size,_etag, and_timeon a hit show the stored identity. They update when a path above re-HEADs or when theGETrejects the ETag.