Repository navigation
Do not overwrite files on S3Queue move destination collision - #115724
valerypetrov wants to merge 134 commits into
Conversation
|
Workflow [PR], commit [abefcb1] Summary: ✅
AI ReviewSummaryThe PR prevents flattened Missing context / blind spots
Findings❌ Blockers
Tests
Final VerdictStatus: ❌ Block Preserve explicit |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes191 object files changed (+648.31 KiB total), 0 added.
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units1842 translation units recompiled, 9283 s compile time in total, 1842 of them have a recent master baseline. Symbol sizes
|
5fefabb to
d4da636
Compare
|
Update: both blockers are addressed.
|
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ibes A queue whose URL selects a version requests the tags of that version, but the `One` format also consumes keys that have no such version. These keep the listed metadata of their latest version, and the version-specific tag lookup failed them with `FILE_DOESNT_EXIST`. Background ingestion requests every virtual column, so this aborted the batch in `test_failed_lookup_of_the_selected_version_keeps_the_ordered_position`. Now the selected version's tags are fetched only when the file's metadata is that version; otherwise the tags of the key are taken, consistent with the other metadata virtual columns. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=115724&sha=a69d192ef08de9666e20c4107ee8e0cbcd8f605b&name_0=PR&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20db%20disk%2C%20targeted%29 ClickHouse#115724 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Without a `versionId` in the URL, `_tags` were read from the latest version of the key. With `One` the consumed version is claimed before the tag lookup, so a version uploaded in between combined the claimed version's `_etag` with the new version's tags, while post-processing acted on the claimed version. Now the tags of a claimed version are requested by its `versionId`. Formats that read bytes learn their version only after the tags are fetched, so the generation of the tags (from `HeadObject`) is checked against the generation that was read, and a mismatch resets the file like any other rewrite during the read. `getObjectInfo` also checks that `GetObjectTagging` describes the version reported by `HeadObject`. A new failpoint `object_storage_queue_pause_before_tags_fetch` is used by the regression test `test_tags_of_the_version_the_one_format_consumed`. ClickHouse#115724 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rned A format that reads bytes learns the version it read only from the response, which arrives after the tags are fetched. The check that the tags describe the generation that was read ran only at the end of the file, after the rows had already been returned: a direct `SELECT ... LIMIT 1` could emit them, and a materialized view with `MergeTree` commits each chunk, so failing at the end of the file did not roll them back. Now each chunk is checked against the generation reported by the read buffer before it is returned. A mismatch on the first chunk resets the file to be read again; a mismatch after rows were returned fails the insert. The end-of-file check is kept for files without rows. `ReadBufferFromS3::getMetadata` now reads only the response fields that `sendRequest` records under the mutex, instead of `impl`, so it may be called while a prefetch or parallel parsing reads the buffer. Add the failpoint `object_storage_queue_pause_after_tags_fetch` and the regression test `test_tags_of_the_version_a_byte_reading_format_consumed`: the tags are fetched from a new version, which is removed before the read, so the rows are read from the old version. The test fails without the check. Address review: ClickHouse#115724 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…llision-114847 Master moved `parallel_inserts` from the table metadata to a storage member: `runsParallelInserts` now takes that member. The PR's `hasClaimedFiles` check is replaced by master's equivalent `acquired_files` check.
Master points `contrib/aws` at a fork where `Aws::String` uses `Aws::Allocator`, so it no longer converts implicitly to and from `String`. Convert explicitly where the PR passes values between them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… per row `One` reads no bytes, so its reader reports no generation and the per-chunk check was skipped. On an unversioned bucket a rewrite between the claim and the tag lookup emitted the claimed `_etag`/`_size` with the tags of the new object. Fall back to the generation recorded for the file (claimed or listed). Co-Authored-By: Claude Opus 5.5 <[email protected]>
…versioned objects `GetObjectTagging` returns the tags of the current object and reports no `ETag`. Without versions, a rewrite between the `HeadObject` of a tag lookup and `GetObjectTagging` returned the tags of the new object labelled with the generation described by `HeadObject`, so `One` on an unversioned bucket could still emit the claimed `_etag` / `_size` together with the tags of the rewritten object. `HeadObject` is now repeated after `GetObjectTagging` when the versions cannot be compared, and a different `ETag`, `Last-Modified` or version throws `S3_OBJECT_CHANGED_DURING_READ`, which resets the file so that the next poll ingests the rewritten object with its own tags. Regression test: `test_tags_of_the_generation_rewritten_between_head_and_tagging_unversioned`, which pauses at the new failpoint `s3_pause_between_head_object_and_get_object_tagging`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A prefixless `after_processing_move_uri` pointing at the source bucket, with other move keys, maps every object onto its own key. The other keys disable the native copy, so the buffered copy re-uploaded the same bytes (keeping the `ETag`) and the `If-Match` delete that followed removed the only copy, while the move was counted as successful. The external S3 move now compares the destination bucket and endpoint with the source (failing closed: endpoints are taken as different only when they are known to be) and the key, and leaves an object that would be moved onto itself in place with an error and `ObjectStorageQueueMoveCollisions`, like a collision. The same check is applied to moves within the bucket (a flattening prefix can map `a/x` to itself) and to Azure moves (compared by blob URL). Regression test: `test_external_move_onto_the_source_itself_is_refused`; without the check the object is copied onto itself and removed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…endpoint The self-move check compared the endpoints of the source and the move destination, and took two endpoints with different hosts or ports as two independent services. That is not proven: `http://minio1:9001` and the IP address of the same container (or a CNAME, a private endpoint) name the same bucket. With a prefixless move to such an alias, the buffered copy re-uploaded the object onto itself and then deleted the only copy. A move whose destination bucket has the source bucket's name and whose key is the source key is now always refused, and an Azure move is compared by the blob path only (container and blob name, and the account for path-style endpoints). The regression test `test_external_move_onto_the_source_itself_is_refused` now also runs with the move URI pointing at the MinIO IP address. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s point An S3 access point alias (`...-s3alias`), an Object Lambda alias (`...--ol-s3`), an access point or Object Lambda host and a Multi-Region Access Point host all address the objects of a bucket whose name they do not contain. A comparison of bucket names cannot prove that such a destination is distinct from the source, so a prefixless external move that keeps the key is refused as a self-move whenever either side is addressed through an access point. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…master` The merge of `master` brought a new call of `isSettingChangeable` in `StorageObjectStorageQueue::alter` (the `differs_from_queue` lambda), while this branch added the `storage_type` argument to that function, so the merged tree did not compile. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…llision-114847 Conflicts: - `S3ObjectStorage::tryGetObjectMetadata`: `master` made it describe the version selected by `?versionId=`. It now passes `uri.version_id` to `tryGetObjectVersionMetadata`, which keeps taking the version from its caller. - `createReadBuffer` in `StorageObjectStorageSource.cpp`: the bypass of the caches for a read pinned to an S3 version is kept next to the new page cache check for `Web` objects, and the read is pinned to the `ETag` also when the page cache requires it (`pin_read_to_etag_for_page_cache`), in addition to `require_read_pinned_to_generation`. Co-Authored-By: Claude Fable 5.2 <[email protected]>
… source URL `S3ObjectStorage::tryGetObjectMetadata` now describes the version selected by `?versionId=` of the storage URL (after the merge of `master`). The move within a bucket used it to look at the destination after a refused guarded copy, to recognise its own committed copy. A destination never has the version of the source, so with such a URL the lookup would find nothing and the copy would be reported as a collision. The destination is now looked up as the current version of its key. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Address review: an unguarded move (`after_processing_move_preserve_path = 1`, or a prefixless external move) to another endpoint, or with other valid keys, cannot use `CopyObject` and uploads the object again. It passed neither the user metadata nor the headers of the source, and it skipped the tags even with `after_processing_move_preserve_tags = 1`, so the moved object lost its `Content-Type`, user metadata and tags, and the source was removed. Every move that uploads the object again now restates the user metadata and the headers, and the tags when `after_processing_move_preserve_tags` is enabled. An unguarded native copy still passes nothing, so `CopyObject` keeps `MetadataDirective::COPY`. `test_buffered_move_with_other_keys_preserves_s3_properties` covers a preserved-path external move with distinct valid destination keys. ClickHouse#115724 (comment) Co-Authored-By: Claude Fable 5.2 <[email protected]>
…_format_consumed` Address review: the prefetch is submitted when the read buffer is created, before the tags are fetched. A delayed prefetch could read the temporary new version between its upload and its deletion. Its bytes and its tags belong together, so the row was accepted, the original version stayed, and the test timed out. The object is now consumed by `INSERT ... SELECT` with `commit_on_select = 1` and `remote_filesystem_read_prefetch = 0`, so the first byte is requested only after both failpoints. The test also checks that the first read returned no rows and left the version in place. It runs on the instance without the keeper fault injection, because a query does not retry a failed commit. ClickHouse#115724 (comment) Co-Authored-By: Claude Fable 5.2 <[email protected]>
…ge of `master` `test_failed_lookup_of_the_selected_version_keeps_the_ordered_position` relied on a second key, `b.csv`, being consumed by the `One` format although the version selected by the URL was not one of its versions. Since the merge of `master`, `S3ObjectStorage::getObjectMetadata` requests the selected version, so the reader of `b.csv` gets a 404, the insert fails, and `a.csv` is never committed. A version belongs to one key, so no other key can be consumed through such a URL, and no later key can move the ordered pointer. The test keeps only the selected object and checks that the released file is read by a later poll. It is renamed to `test_failed_lookup_of_the_selected_version_releases_the_file`. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=115724&sha=93de7aac44c4be7a9373ac3daa3feaa78f10ab29&name_0=PR&name_1=Integration%20tests%20(amd_asan_ubsan%2C%20db%20disk%2C%20targeted) ClickHouse#115724 Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
🕵 Pushed three commits on top of 93de7aa; the branch is current with
Both review threads are answered and resolved, so the full CI suite can run. The remaining failure on the previous head was the review-thread gate itself. One thing for the author or a maintainer to judge: a key that lacks the selected version still fails the whole batch in |
…t names The previous commit renamed `test_failed_lookup_of_the_selected_version_keeps_the_ordered_position` to `test_failed_lookup_of_the_selected_version_releases_the_file`, which is the name of the test right above it. The second definition shadowed the first one, so the first test was not collected, and the `ruff` check of the Style check failed with `F811 Redefinition of unused test_failed_lookup_of_the_selected_version_releases_the_file`, which dropped the rest of the CI. The test of the ordered queue is now `test_failed_lookup_of_the_selected_version_releases_the_file_of_an_ordered_queue`. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=115724&sha=6f888019baaa049ea9a74a5aba8beae45ca7a782&name_0=PR&name_1=Style%20check ClickHouse#115724 Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
🕵 Pushed d9027b9: the only CI failure on 6f88801 was the |
…es the object anew Only `CopyObject` carries the user metadata, the headers and the tags of the source for free. The post-processor guessed which moves take another route (a guarded one, or one with the native copy disabled for the external destination) and passed the properties only then. The guess missed the moves whose route is decided inside `copyS3File`: - a move within the storage with `after_processing_move_preserve_path = 1` and `allow_native_copy = 0` configured for the endpoint, which uploads the object again; - a file above `max_single_operation_copy_size`, which is copied by parts into a new `CreateMultipartUpload`; - a fallback from a refused `CopyObject`. Such a move replaced `Content-Type` with `binary/octet-stream`, dropped the user metadata and the tags, and removed the source. The decision now belongs to `copyS3File`. `S3CopyFileSettings` gets `source_metadata` and `source_tags_reader` next to `source_headers`; they are applied on `PutObject` and `CreateMultipartUpload` and never on `CopyObject`, which keeps `MetadataDirective::COPY`. The tags of an unguarded move are read lazily, so a plain `CopyObject` costs no `GetObjectTagging`. Every move hands the properties over: the external one directly, and the one within the storage through the new `WriteSettings::object_storage_copy_preserve_source_properties`, so other callers of `S3ObjectStorage::copyObject` are unchanged. `test_unguarded_move_without_copy_object_preserves_s3_properties` covers a preserved-path move within the storage with the native copy disabled and with a multipart copy, with source metadata, a nondefault `Content-Type` and tag preservation enabled. Co-Authored-By: Claude Fable 5.2 <[email protected]>
The `after_processing` action lives in the Keeper metadata, which is shared by every table of a Keeper path, while the move destination belongs to each table. `after_processing_publication_mutex` makes the pair coherent only for the table being altered. Another table of the same Keeper path can keep an incomplete destination (only `after_processing_move_uri`, without the keys), which is valid for `keep`. Once the first table is altered to `move`, the second one read and inserted its files, failed to move them with `BAD_ARGUMENTS` before the Keeper commit, and inserted the rows again on every poll. `createSource` now runs the same completeness check as `CREATE` and `ALTER` (extracted to `checkMoveDestinationIsComplete`), plus the check that the destination fits the storage type, whenever the batch captured `MOVE`. An incomplete destination fails the batch before it claims any file, with a message naming the table, until the table gets a destination of its own. `test_move_action_set_through_another_table_of_the_keeper_path` covers the action change through a second local table sharing the Keeper path. The test completes the destination with an `ALTER`, which printed the value of `after_processing_move_secret_access_key` in the `New setting` trace line of `alter`. The value of that setting and of `after_processing_move_connection_string` is no longer logged there. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Closes: #114847
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed silent data loss in S3Queue/AzureQueue
after_processing = 'move': with the defaultafter_processing_move_preserve_path = 0, objects sharing a basename under different prefixes mapped to the same destination key, so the second move overwrote the first object's data and then deleted its own source. Colliding objects are now left in place with an error logged; the destination guard is enforced by the object storage itself, so concurrent movers cannot both overwrite.Documentation entry for user-facing changes
The move is copy-then-delete per object, and an S3/Azure overwrite is not an error, so the collision destroyed one file's bytes with no exception, no log line, and
ObjectStorageQueueMovedObjectscounting both moves as successful.The fix detects collisions at two levels and, on collision, refuses the move: the object stays at the source (it is already recorded as processed, so it is simply retained in the bucket for the operator), an error is logged, and the new
ObjectStorageQueueMoveCollisionsprofile event is incremented.If-None-Match: *), so the storage refuses it rather than overwriting. This is applied on all three move paths (same-bucket, cross-bucket S3, cross-container Azure) wheneverafter_processing_move_preserve_path = 0; preserved paths cannot collide, so they are unconditional as before. GCS cannot refuse such an overwrite, soCREATEandALTERrefuse a flattening move to GCS. It costs no extra request: the precondition rides on the request that makes the object visible.Because the guard is enforced by the storage rather than by a preflight check, there is no check-then-copy window: of two movers racing for the same destination exactly one wins, and the loser keeps its source. A rejected copy is reported as a collision (logged, counted by
ObjectStorageQueueMoveCollisions) and never followed by the source deletion.To carry the precondition, the S3 copy helpers accept
S3CopyFileSettings, while the Azure copy helpers accept an optional destinationIf-None-Match. Each sets it on the request that commits the object (PutObject/CopyObject/CompleteMultipartUpload, andUpload/CommitBlockList/CopyFromUri/StartCopyFromUri). The parameter defaults to "no precondition", so every existing caller is unchanged.S3ObjectStorage::copyObjectnow forwards itsWriteSettings, which it previously discarded, soobject_storage_write_if_none_matchreaches the copy.The copy is no longer re-executed by the retry loop once it has succeeded, so a failure while removing the source cannot make the retry collide with the object this move just wrote. The source delete is pinned to the copied generation, by
versionIdon versioned buckets and byIf-Matchotherwise; a store that ignoresIf-MatchonDELETE(MinIO does) deletes by key there, as before this change. GCS rejectsETagconditions on deletes, so no condition is sent to it and it deletes by key as well. On a versioned bucket only the version that was read is removed, so an older version of the key, if there is one, becomes the current object again. The listing reports no version IDs, so the read is pinned to the listedETagonly: if the same bytes are uploaded again between the listing and the read, the new version is the one read and removed, and the listed version stays at the key.A move that would put an object onto its own key (e.g. a prefixless
after_processing_move_uripointing at the source bucket with other keys, or a flattening prefix that mapsa/xto itself) is refused the same way: the object stays in place, an error is logged, andObjectStorageQueueMoveCollisionsis incremented. A destination bucket with the source bucket's name is taken as the source bucket whatever its endpoint is, as is any bucket when either side is addressed through an S3 access point (an alias, an access point or Object Lambda host, or a Multi-Region Access Point), because its name does not identify the bucket; and an Azure destination is compared by the blob path only: distinct hosts or ports (a host name and its IP address, a CNAME, a private endpoint) do not prove that the services are distinct.A move that uploads the object again restates what
CopyObjectcarries for free: the user metadata, the headers (Content-Type,Content-Encoding,Cache-Controland the like) and, withafter_processing_move_preserve_tags = 1, the tags. This applies to guarded moves and to unguarded moves that cannot useCopyObject(another endpoint, other access keys, orallow_native_copy = 0)._tagsare taken from the generation that was consumed. On unversioned objects,HeadObjectis repeated afterGetObjectTagging, so tags of an object rewritten in between are never attributed to the earlier generation; such a file is reset and read again.Setting
after_processing_move_preserve_path = 1remains the recommended configuration when same-basename objects are possible, and theafter_processing_move_preserve_pathsetting description now documents the collision behavior.Integration tests cover in-batch and pre-existing collisions, same-storage and external moves for S3Queue/AzureQueue, interrupted-copy recovery, S3 headers and tags and Azure metadata on flattening moves, versioned-source provenance, and a same-byte re-upload between the listing and the read.
🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/115724]