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 <dtitmoav@gmail.com>
(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 <cursoragent@cursor.com>
… 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) <noreply@anthropic.com> Signed-off-by: UnamedRus <dtitmoav@gmail.com>
…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) <noreply@anthropic.com> Signed-off-by: UnamedRus <dtitmoav@gmail.com>
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 <cursoragent@cursor.com>
…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 <cursoragent@cursor.com>
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 <cursoragent@cursor.com>
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 <cursoragent@cursor.com>
`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 <cursoragent@cursor.com>
`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 <cursoragent@cursor.com>
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 <cursoragent@cursor.com>
…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 <cursoragent@cursor.com>
… 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 <cursoragent@cursor.com>
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 <cursoragent@cursor.com>
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 <cursoragent@cursor.com>
…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 <cursoragent@cursor.com>
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 <cursoragent@cursor.com>
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 <cursoragent@cursor.com>
…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 <cursoragent@cursor.com>
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 <cursoragent@cursor.com>
`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 <cursoragent@cursor.com>
…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 <cursoragent@cursor.com>
…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 <cursoragent@cursor.com>
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 <cursoragent@cursor.com>
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 <cursoragent@cursor.com>
…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 <cursoragent@cursor.com>
…alya-26.8/object-storage-identity-cache Co-authored-by: Cursor <cursoragent@cursor.com>
…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 <cursoragent@cursor.com>
… 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 <cursoragent@cursor.com>
…s after the write With `max_inflight_parts_for_one_file` of 1, `TaskTracker::add` waits for the single-part upload and rethrows its failure from `WriteBufferFromS3::preFinalize`. That is before `finalizeImpl` reaches the `try` that runs `on_upload_complete`, and a caller that calls `preFinalize` itself never reaches `finalizeImpl` at all. A `PutObject` that committed the object but lost its response therefore left the previous size and ETag in `ObjectStorageIdentityCache`. The next read failed its `If-Match` check with `S3_OBJECT_CHANGED_DURING_READ` and only then dropped the entry. `preFinalize` now runs `on_upload_complete` when the single-part upload throws after `object_creation_request_sent` was set, the same condition `finalizeImpl` uses. A part-upload failure never sets it, so the entry is kept. Tests: `ExceptionOnPutWithOneInflightPartRunsUploadCallback` covers the failure from `finalize` and from an explicit `preFinalize`, `ExceptionOnUploadPartWithOneInflightPartSkipsUploadCallback` checks that a part-upload failure runs no callback. The first fails without the change (0 callbacks instead of 1). Related: #2888 Co-authored-by: Cursor <cursoragent@cursor.com>
…cancelled after the upload started `WriteBufferFromS3::preFinalize` can already have sent `PutObject`, or scheduled `CompleteMultipartUpload`, when the buffer is cancelled. `cancelImpl` waits for those tasks and drops their errors, so the object may have been replaced while the identity cache kept the previous size and ETag. `cancelImpl` now runs the upload callback when an object-creating request was sent. The callback runs at most once, because a failed `finalize` runs it and then cancels the buffer. Related: #2181 Related: #2888 Co-authored-by: Cursor <cursoragent@cursor.com>
The delete paths invalidated the identity cache only after the request returned. A `DeleteObject` or `DeleteObjects` whose response was lost can still have removed the objects, and a batch that fails in a later chunk has already removed the earlier ones, so the cache kept the previous size and ETag. Invalidate on every exit of `removeObjectImpl`, `removeObjectsImpl`, the single-key branch of `removeObjectsIfExistImpl`, `BackupWriterS3::removeFile` and `BackupWriterS3::removeFiles`. Also invalidate before throwing on a whole-batch failure in `removeObjectsIfExistImpl` and on an unclassified error in `removeObjectIfTokenMatchesImpl`, where the outcome is unknown. Related: #2181 Related: #2888 Co-authored-by: Cursor <cursoragent@cursor.com>
…tion guards The delete paths invalidate the identity cache from `SCOPE_EXIT` guards. A scope guard's destructor is implicitly `noexcept`, and invalidating allocates the cache key. On the normal exit of a successful delete, the memory tracker may throw `MEMORY_LIMIT_EXCEEDED` for that allocation, and the exception then escapes the destructor and terminates the server. Use `SCOPE_EXIT_MEMORY` for the guards in `removeObjectImpl`, `removeObjectsImpl`, the single-key branch of `removeObjectsIfExistImpl`, `BackupWriterS3::removeFile` and `BackupWriterS3::removeFiles`. It blocks memory exceptions for the duration of the guard, as `WriteBuffer::cancel` does. Related: #2181 Related: #2888 Co-authored-by: Cursor <cursoragent@cursor.com>
…n object to an S3 disk `BackupReaderS3::copyToDiskImpl` copies a backup object straight into a destination S3 disk with `copyS3File` or `copyS3FileRange`. It did not invalidate the destination key, so a fixed key that was read earlier kept its previous size and ETag. The next read then sent `If-Match` for the old generation. Every other copy into an S3 object (backup writes, the queue post-processor, `S3ObjectStorage`) already drops the entry. Pass an invalidation callback to the copy, so it also runs when the copy throws after an object-creating request was sent. Invalidate again after the copy returns. The entry is keyed by the destination endpoint, the blob bucket and the blob key. A destination that is not an S3 storage now fails before the copy. Related: #2181 Related: #2888 Co-authored-by: Cursor <cursoragent@cursor.com>
…S3ObjectStorage `BackupReaderS3::copyToDiskImpl` read the destination endpoint with a `dynamic_cast` to `S3ObjectStorage`, added by e65b47a. A disk with a `cache` layer is `DiskObjectStorage(CachedObjectStorage(S3ObjectStorage))`, so the cast returned null and the restore failed with `LOGICAL_ERROR` before any copy started. Read the endpoint through the virtual `getDescription` instead. `S3ObjectStorage` returns the same `uri.endpoint` that its own invalidation uses, and `CachedObjectStorage` forwards the call. The native copy is still taken only when the destination has the S3 data source kind. Add the test `05815_object_storage_identity_cache_restore_to_cached_disk`: it restores a table on the `s3_cache` disk with `allow_s3_native_copy` and checks the rows and the `S3CopyObject` event. Related: #2181 Related: #2888 Co-authored-by: Cursor <cursoragent@cursor.com>
… test `05497_object_storage_identity_cache_parquet_count_after_replace` expects a Parquet `count` after an external replace to succeed. That holds only for the footer-only count: it needs `need_only_count`, which depends on `optimize_count_from_files`. With that setting off the count reads the file with the GET pinned to the cached ETag, so a replaced object fails with `S3_OBJECT_CHANGED_DURING_READ`, as designed. The stateless runner randomizes the setting, so the test failed intermittently. Pin `optimize_count_from_files` and `optimize_trivial_count_query` in the read settings. With `optimize_count_from_files 0` forced at the client, the previous settings fail with `S3_OBJECT_CHANGED_DURING_READ` and the pinned settings pass. Related: #2181 Related: #2888 Co-authored-by: Cursor <cursoragent@cursor.com>
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c19329f129
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| update_field(credentials.GetAWSAccessKeyId()); | ||
| update_field(credentials.GetAWSSecretKey()); | ||
| update_field(credentials.GetSessionToken()); |
There was a problem hiding this comment.
Partition identity entries by header-based credentials
Include authentication-bearing request headers in the principal hash. StorageS3Configuration::createObjectStorage supports per-query headers, and getClient also uses Authorization bearer headers for GCS, but this hash only covers AWS credentials. Consequently, two users accessing the same endpoint/bucket/path with different bearer or gateway credentials—especially anonymous clients whose AWS credential fields are all empty—share an identity-cache entry, allowing one principal to receive the other principal's existence, size, ETag, and modification-time metadata or to have its GET pinned to the other principal's ETag.
Useful? React with 👍 / 👎.
| if (auto existing = Base::get(key); existing && existing->fetch_seq > read.seq) | ||
| return; | ||
| identity.fetch_seq = read.seq; | ||
| Base::set(key, std::make_shared<ObjectStorageIdentity>(std::move(identity))); |
There was a problem hiding this comment.
Preserve fetch ordering after cache eviction
Retain the latest completed sequence independently of entry residency. If fetch A starts before an external overwrite, fetch B starts afterward and stores the new identity, B's entry can be evicted by ordinary cache pressure before A finishes; because this check only examines the resident entry, A then stores the older identity despite its lower sequence. The next read can therefore reuse the stale size/ETag and fail against the current object, contradicting the stated guarantee that an earlier observation cannot overwrite a later fetch.
Useful? React with 👍 / 👎.
`s3CredentialHash` hashed only the AWS access key, secret and session token. A principal that authenticates with
request headers, such as `headers('Authorization' = 'Bearer ...')` of the `s3` table function or the SSE-C key
headers, has no AWS credentials or the same ones as another principal. All of them hashed to the same value, so
a metadata-only read (`_size`, `_etag`, `_time`, existence, no-GET paths) by one principal could be answered from
the identity cached by another one without any request to S3. The file contents were not exposed, because
`createReadBuffer` revalidates with the caller's own headers before a content cache can answer without a GET.
Hash the extra request headers of the client (name and value, in order) together with the credentials.
Headers configured on the server are identical for every user and do not split the cache. Clients without
headers still share one hash, as before.
Add the test `05816_object_storage_identity_cache_request_headers_principal`: the same object read with
`headers(...)` A, then B, then none. Each principal misses and sends its own HEAD, and then hits with the same
headers. Without the change principal B reuses the entry of A and sends no HEAD.
Related: #2181
Related: #2888
Co-authored-by: Cursor <cursoragent@cursor.com>
`ObjectStorageIdentityCache::setIfEpoch` compared the sequence of a fetch only with the resident entry. If fetch A started before an external overwrite, fetch B started after it and stored the new identity, and the entry of B was evicted by cache pressure before A finished, A found no entry and stored the older identity. The next read then reused a stale size and ETag. Remember the highest sequence that stored an entry in a fixed array of slots indexed by the hash of the key. It is not tied to the residency of the entry, so eviction does not forget it. Two keys can share a slot, which only skips a store that would have been safe: the next read of that key requests the metadata again. The per-entry `fetch_seq` is no longer needed and is removed. Related: #2181 Related: #2888 Co-authored-by: Cursor <cursoragent@cursor.com>
…nal replaces The section on `SYSTEM CLEAR OBJECT STORAGE IDENTITY CACHE` only said that a write, copy or delete by this server drops an entry. The cache is enabled by default, so a metadata-only read of an object that was replaced outside this server, such as `_size`, `_etag` or `_time`, can return the previous generation. A read that downloads the object detects the replacement through `If-Match` and drops the entry. Describe that contract and the ways to see current metadata: `s3_validate_etag_on_read = 0` for the query, `object_storage_identity_cache_size = 0`, or `SYSTEM CLEAR OBJECT STORAGE IDENTITY CACHE`. Related: #2181 Related: #2888 Co-authored-by: Cursor <cursoragent@cursor.com>
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 21c2642f71
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (!cache) | ||
| return; | ||
|
|
||
| cache->invalidate(makeObjectStorageIdentityCacheKey(endpoint, bucket, path)); |
There was a problem hiding this comment.
Block memory errors while invalidating identities
When an S3 copy or conditional deletion succeeds while its query is at the memory limit, constructing the composite key here can throw MEMORY_LIMIT_EXCEEDED after the object has already changed. Several new callers, including copyObject and removeObjectIfTokenMatchesImpl, invoke this helper directly rather than through SCOPE_EXIT_MEMORY, so the operation is reported as failed while the old identity remains cached; subsequent metadata-only reads can continue returning the previous size and ETag. Block memory-limit exceptions inside this helper or construct the key before sending the mutating request.
Useful? React with 👍 / 👎.
| size_t operator()(const ObjectStorageIdentity & identity) const | ||
| { | ||
| return identity.memoryUsage() + OVERHEAD; |
There was a problem hiding this comment.
Account for variable-sized cache keys
Include the endpoint/bucket/path key allocation in the entry weight. The current weight counts only the identity and a fixed 128-byte estimate, although each cache-policy entry owns the full composite key; with long object paths, the configured 64 MiB limit and ObjectStorageIdentityCacheBytes metric can understate actual cache memory by several times, allowing this process-wide cache to consume hundreds of MiB before eviction.
Useful? React with 👍 / 👎.
… errors `invalidateObjectStorageIdentityCache` builds the cache key, which allocates. Several callers run it after an object-changing request has already succeeded: `copyObject`, the conditional delete in `removeObjectIfTokenMatchesImpl`, and the failed-delete branch of `removeObjectsIfExistImpl`. Those callers do not all sit in a `SCOPE_EXIT_MEMORY`. Under a query memory limit the allocation can throw `MEMORY_LIMIT_EXCEEDED` after the object has changed. The query then reports a failure, and the previous size and ETag stay cached, so metadata-only reads return the old object. Lock memory exceptions inside the helper, so every caller is covered, the same way `SCOPE_EXIT_MEMORY` does. Related: #2181 Related: #2888 Co-authored-by: Cursor <cursoragent@cursor.com>
`ObjectStorageIdentityWeight` counted the identity, its ETag and a fixed 128 bytes. The cache stores each entry under the full composite key `endpoint`, `bucket` and `path`, and that key was not counted. With long object paths an entry can take several times its weight, so `object_storage_identity_cache_size` and the `ObjectStorageIdentityCacheBytes` metric understate the memory the cache holds, and the process can use hundreds of megabytes beyond a 64 MiB limit. The weight function sees only the value, so `setIfEpoch` stores the capacity of the key in the entry, and `memoryUsage` counts it. The fixed overhead now covers the hashmap node, list links and `shared_ptr` only. Add the test `05817_object_storage_identity_cache_weight_counts_key`: after a cold read of an object with a 700-byte path, `ObjectStorageIdentityCacheBytes` must be at least 700. Related: #2181 Related: #2888 Co-authored-by: Cursor <cursoragent@cursor.com>
The S3 mock rejects keys above its limit (`KeyTooLongError`), so the 700-byte path of `05817_object_storage_identity_cache_weight_counts_key` failed on the INSERT. Use a 400-byte path. Without the key in the weight an entry weighs about 260 bytes, so the test still tells the two cases apart. Related: #2181 Related: #2888 Co-authored-by: Cursor <cursoragent@cursor.com>
The S3 mock still rejected the 400-byte path (`KeyTooLongError`), because the object key also contains the test name. Use a 100-byte path and require a weight of at least 400 bytes. The entry weighs about 450 bytes with the key counted and about 250 without it, so the threshold separates the two cases. Related: #2181 Related: #2888 Co-authored-by: Cursor <cursoragent@cursor.com>
The cache policies keep every key twice: as the key of the hashmap and in the eviction queue list. The entry weight counted the key once, so a long object path still made the cache hold up to about 40% more memory than `object_storage_identity_cache_size` and `ObjectStorageIdentityCacheBytes` reported. Count the key capacity twice. `05817_object_storage_identity_cache_weight_counts_key` now requires at least 600 bytes for one entry: about 240 without the key, 450 with one copy, 661 with both. Related: #2181 Related: #2888 Co-authored-by: Cursor <cursoragent@cursor.com>
|
@codex review |
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
CI triage for
|
| Check | Verdict |
|---|---|
Integration amd_asan_ubsan, targeted and db disk, old analyzer, 1/8: test_storage_s3::test_schema_inference_cache |
🔴 Caused by this PR |
Stateless amd_binary, cas storage, parallel: 04890_iceberg_metadata_spec_violation_no_abort |
🟡 Flaky, not related to this PR |
Integration db disk, old analyzer, 2/8 and 5/8 |
⚪ Infra: Docker image pull failed |
Regression iceberg_2 (export partition casting) |
⚪ Regression suite out of sync with #2878, not related to this PR |
| Grype Keeper and Server alpine | ⚪ Pre-existing: they fail the same way on the latest antalya-26.8 MasterCI (run 45917020538) |
| DCO | ef65f443cc, 3119a1540a, 56df2a64e4, …) have no Signed-off-by |
🔴 test_storage_s3/test.py::test_schema_inference_cache (caused by this PR)
It fails in 2 of the 2 jobs that ran it, with the same assertion each time:
File: test_storage_s3/test.py:2216 - in test
check_cahce_num_rows_hits(
File: test_storage_s3/test.py:1883 - in check_profile_event_for_query
assert res == amount
E assert 0 == 1
The test writes test_cache.parquet, clears the schema cache, runs select count() and expects SchemaInferenceCacheNumRowsHits = 1. It now gets 0.
Root cause. On an identity-cache hit, S3ObjectStorage::getObjectMetadata sets is_last_modified_fresh = false (src/Disks/DiskObjectStorage/ObjectStorages/S3/S3ObjectStorage.cpp:1151). The PR changed the get_last_mod_time lambda for the count cache in StorageObjectStorageSource::createReader to check lastModifiedConfirmsUnchanged(), and it made the same change in ReadBufferIterator::tryGetColumnsFromCache. That lambda now returns nullopt whenever the metadata came from the identity cache. The object was just written or HEADed in the same session, so the identity cache is warm, and the num-rows cache is never consulted. In practice the num-rows count cache no longer hits for S3 while the identity cache is enabled. That is a real regression, not just a test-expectation change. The last base MasterCI with this job green (run 45868450975) is consistent with that. The latest base run's integration shards all ended with ERROR, so they give no comparison.
Suggested fix. Don't give up on the cache. Confirm the time with a HEAD, the same way the PR already does for the empty-file and query-condition-cache paths:
auto get_last_mod_time = [&]() -> std::optional<time_t>
{
auto metadata = object_info->getObjectMetadata();
if (metadata && metadata->is_from_identity_cache)
{
revalidateIdentityCachedObjectMetadata(*object_info, object_storage);
metadata = object_info->getObjectMetadata();
}
if (!metadata || !metadata->lastModifiedConfirmsUnchanged())
return std::nullopt;
return std::optional<time_t>(metadata->last_modified.epochTime());
};The same pattern applies to ReadBufferIterator::tryGetColumnsFromCache, where the iterator's object_storage is available.
- This costs one HEAD per file on a count-cache or schema-cache lookup. The behaviour before the identity cache paid that HEAD anyway, and the replace-safety guarantee your
0548x/0549xtests check is kept. - If you would rather skip the HEAD, the test's expectation has to change to
0, and the release notes should say that the num-rows and schema caches are bypassed for identity-cached S3 objects. I'd recommend the HEAD.
🟡 04890_iceberg_metadata_spec_violation_no_abort (flaky, not related to this PR)
-primitive to complex rejected
+NOT REJECTED
The CI's own rerun diagnosis says: Runs: 13, Failed: 4, Passed: 9 → Failure is flaky. The test uses IcebergLocal (local files), so the S3 identity cache is not involved. The PR's only change under DataLakes/Iceberg/ is comments and a named-argument annotation. The test and the validator came from 807e721fc52, which is already in base. It passed on the latest base run. Next step: re-run. It's worth a separate issue for the arm-4 race, but it does not block this PR.
⚪ Integration db disk, old analyzer, 2/8 and 5/8 (infra)
FAILED to pull tabulario/iceberg-rest:1.6.0 after 3 attempt(s)
ERROR: Failed to pull the following image(s) after 3 attempt(s): altinityinfra/s3-proxy:57c3f2d0385fc09b9f6c chrislusf/seaweedfs:4.41
Failed to pre-pull Docker images needed by the test batch
No tests ran. Re-run.
⚪ Regression iceberg_2 (regression suite out of sync, not related to this PR)
All 8 failures are in /iceberg/export partition/*/casting/{lossy,out of bounds}. For example, UInt64 narrows to Int32 without allow_lossy_cast expected exit code 122 and got 0. The export part/accepted errors are hidden behind a suite bug: NameError: name 'error' is not defined at export_operations.py:393.
- Antalya 26.8 - Backport of #118596 and drop
export_merge_tree_part_allow_lossy_cast, allowing it by default #2878 ("dropexport_merge_tree_part_allow_lossy_cast, allowing it by default") was merged intoantalya-26.8at 16:21 UTC on 2026-11-26. - The regression suite on the
releasebranch was updated for it at 23:27 UTC (01247c2600"Update iceberg export partition tests for Antalya 26.8 - Backport of #118596 and dropexport_merge_tree_part_allow_lossy_cast, allowing it by default #2878"). - This PR's regression job checked out the suite at 21:23 UTC, so it ran the old expectations against the new behaviour.
- The latest base MasterCI ran after the suite update, and its
iceberg_2passed.
Re-run and it should pass. This PR does not touch the export path.
Next steps: fix the num-rows/schema-cache freshness check above, then re-run the two infra shards and iceberg_2. Sign off the commits if DCO is enforced for merge.
Evidence: result_pr.json for this SHA, the Actions logs of run 45883216321, the iceberg2 report.html, and the base MasterCI run 45917020538. I did not do a local build or run; this analysis is based on the CI artifacts only.
The identity cache keeps the modification time of an object, but that time is not proof the object is unchanged, so the schema inference and number-of-rows caches do not use it. `test_schema_inference_cache` runs a HEAD for the schema, then a count of the same object in the same query, which now gets the time from the identity cache. For `s3` the count expects no number-of-rows cache hit. `url` storage does not use the identity cache and keeps the hit. Document the bypass in `SYSTEM CLEAR OBJECT STORAGE IDENTITY CACHE`. CI report: https://altinity-build-artifacts.s3.amazonaws.com/json.html?PR=2888&sha=32fbd93f3b464e9b584c624481c42ffc36b985a4&name_0=PR&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20db%20disk%2C%20old%20analyzer%2C%201%2F8%29 Related: #2181 Related: #2888 Co-authored-by: Cursor <cursoragent@cursor.com>
… objects `invalidate` advanced one epoch for the whole cache, so a write to any S3 object on the server made every metadata fetch in flight skip its store. A server that writes to S3 all the time, for example a MergeTree table or a system log on an S3 disk, then rarely filled the cache, and the next read of an object sent a HEAD again. In the CI job with an S3 storage policy this made `05485_object_storage_identity_cache_endpoint_key` and `05500_object_storage_identity_cache_backup_replace` flaky: a warm read had `S3HeadObject=1` instead of 0. Replace the epoch with a logical clock. `invalidate` stamps the hash slot of its key, `clear` stamps the whole cache, and a fetch stores only if nothing stamped its slot after it began. The stamp of the last store in the slot keeps the ordering of fetches of one key, as before. Two keys can share a slot, which only skips a store that was safe to do. `05818_object_storage_identity_cache_unrelated_writes` pauses a read before its store, overwrites another object, and requires the next read to hit. Before the change it fails with `S3HeadObject=1, expected 0`. CI report: https://altinity-build-artifacts.s3.amazonaws.com/json.html?PR=2888&sha=050bc00e5dab4d79a79aa35e074037b601a3f5ac&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20distributed%20plan%2C%20s3%20storage%2C%20sequential%29 Related: #2181 Related: #2888 Co-authored-by: Cursor <cursoragent@cursor.com>
…lookups off `test_schema_inference_cache` expected no number-of-rows cache hit for S3, so it no longer checked the hit path for S3 at all. A query with `s3_validate_etag_on_read = 0` skips the identity cache, so its HEAD gives a fresh modification time, and it must hit the number-of-rows cache. Also fix the comment in `05489_object_storage_identity_cache_clear_during_fetch`: the clear stops the stores in flight, it does not advance an epoch. CI report: https://altinity-build-artifacts.s3.amazonaws.com/json.html?PR=2888&sha=050bc00e5dab4d79a79aa35e074037b601a3f5ac&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20distributed%20plan%2C%20s3%20storage%2C%20sequential%29 Related: #2181 Related: #2888 Co-authored-by: Cursor <cursoragent@cursor.com>
… commit reverted `126f57cbb8fc` committed `05489_object_storage_identity_cache_clear_during_fetch` from a stale working-tree copy and so undid `85c874d738b7`. The test ran every read with `s3_validate_etag_on_read = 0`, which skips the identity-cache lookup, so the final read counted no miss and failed with `Misses=0, expected >= 1`. Run the final read with validation on and only the paused reader with validation off, as before. Also fix the header comment, which still described the removed epoch. CI report: https://altinity-build-artifacts.s3.amazonaws.com/json.html?PR=2888&sha=126f57cbb8fcdd01c4ff743d5434d7aadf4fb19a&name_0=PR&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20db%20disk%2C%20distributed%20plan%2C%20sequential%2C%20selected%20tests%29 Related: #2181 Related: #2888 Co-authored-by: Cursor <cursoragent@cursor.com>
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.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.