Skip to content

Disallow zip backup format for S3 and Azure Blob Storage - #101770

Merged
alexey-milovidov merged 11 commits into
ClickHouse:masterfrom
Onyx2406:fix/disallow-zip-s3-backup
Jul 21, 2026
Merged

alexey-milovidov merged 11 commits into
ClickHouse:masterfrom
Onyx2406:fix/disallow-zip-s3-backup

Conversation

@Onyx2406

@Onyx2406 Onyx2406 commented Apr 4, 2026 •

Copy link
Copy Markdown
Contributor

What this PR does

Zip archives require seeking to read their central directory, which is very slow over object storage where each seek turns into a separate HTTP request (see #53483 — a slow RESTORE of a many-column table from S3). This PR rejects the zip/zipx backup archive format early, with a clear error message suggesting tar-based formats, whenever the backup is stored on object storage:

  • direct S3(...) and AzureBlobStorage(...) backup destinations, and
  • Disk(...) destinations whose disk is backed by object storage (object_storage_type is S3 or Azure, e.g. an s3/s3_plain_rewritable disk).

The check applies to both BACKUP and RESTORE, because the seek-heavy path is hit when reading an existing zip archive too (the case reported in #53483). Local File(...) and local-disk Disk(...) zip backups remain allowed.

Closes: #53483

Changelog category (leave one):

  • Backward Incompatible Change

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):

Reject the zip/zipx backup archive format for backups stored on object storage — direct S3(...)/AzureBlobStorage(...) destinations and Disk(...) destinations backed by S3 or Azure — for both BACKUP and RESTORE. Zip requires seeking to read its central directory, which is very slow over object storage. Use a tar-based format such as tar.gz instead.

  • Documentation is written (no docs needed)

Zip format requires seeking to read the central directory at the end
of the archive, which causes severe performance problems with object
storage (each seek results in a new HTTP request). Reject zip/zipx
extensions early with a clear error message suggesting tar-based formats.

Fixes ClickHouse#53483
@alexey-milovidov alexey-milovidov self-assigned this Jun 17, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Jun 17, 2026
alexey-milovidov and others added 2 commits June 18, 2026 10:42
Cover the new early rejection of `BACKUP ... TO S3(...)` and
`BACKUP ... TO AzureBlobStorage(...)` when the destination uses a `.zip`
extension. Zip requires seeking, which turns every read into a separate
HTTP request on object storage, so it is rejected with a clear error
suggesting tar-based formats.

Related: ClickHouse#53483

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [aabc354]

Summary: ✅


AI Review

Summary

This PR rejects zip/zipx backup archives on object-storage-backed backup destinations (S3, AzureBlobStorage, and Disk backed by S3/Azure) to avoid the seek-heavy zip path. The direct guard is implemented consistently in the touched engines, but I do not think it is ready to merge yet: it still hard-breaks RESTORE of pre-existing object-storage zip backups without any compatibility switch, and the broadened Azure/Disk restore contract is not fully locked by tests or docs.

Findings

❌ Blockers

  • [src/Backups/registerBackupEngineS3.cpp:175, src/Backups/registerBackupEngineAzureBlobStorage.cpp:126, src/Backups/registerBackupEnginesFileAndDisk.cpp:165] [dismissed by author -- https://github.com/Disallow zip backup format for S3 and Azure Blob Storage #101770#discussion_r3445541567] The new guard rejects RESTORE of existing object-storage .zip backups as well as new BACKUPs, so an upgrade can make the only copy of a disaster-recovery backup unusable in place. Calling this a backward-incompatible change in the PR description is not enough for ClickHouse’s compatibility rule on new validation over existing data; users still need a supported compatibility path. Copying the archive to local storage first is a manual workaround, not a setting or compatibility mode, and can be infeasible for the large backups this change targets.
    Suggested fix: gate the READ/UNLOCK rejection behind an explicit compatibility setting, or restrict the hard rejection to new writes and continue allowing explicit restores of pre-existing object-storage zip archives.

⚠️ Majors

  • [tests/integration/test_backup_restore_azure_blob_storage/test.py:745] The PR body says the early rejection applies to RESTORE on AzureBlobStorage(...) too, but the new Azure coverage only exercises BACKUP. Right now the code happens to check before the open_mode branch, but there is no regression test locking that contract the way test_restore_from_s3_zip_not_supported does for S3.
    Suggested fix: add a negative RESTORE ... FROM AzureBlobStorage('...zip') test using a non-existent blob to prove the guard fires before any archive open.

  • [tests/integration/test_backup_restore_s3/test.py:1387] The object-storage Disk(...) path is in the same state: the PR description promises both BACKUP and RESTORE, but the new regression only proves writer-side rejection. A future refactor that accidentally moves the Disk zip check below the READ path will still pass CI today.
    Suggested fix: add a negative RESTORE ... FROM Disk('disk_s3', '...zip') case analogous to the S3 restore test.

  • [src/Backups/registerBackupEngineS3.cpp:175, src/Backups/registerBackupEnginesFileAndDisk.cpp:168] The repo still has English docs that recommend object-storage zip backups which this PR now rejects with BAD_ARGUMENTS: docs/products/cloud/guides/migration/oss-to-cloud-backup-restore.mdx:419 uses S3('...backup.zip'), and docs/integrations/connectors/data-ingestion/AWS/integrating-s3-with-clickhouse.mdx:1291-1301 uses Disk('s3_express', 't.zip') for both BACKUP and RESTORE.
    Suggested fix: update those examples to tar-based archives and document the migration path for existing object-storage zip backups.

Final Verdict

Do not merge as is. The direct guard itself is straightforward, but the restore compatibility break needs an explicit product decision in code, and the broadened contract still needs Azure/Disk restore regression coverage plus doc updates.

@clickhouse-gh clickhouse-gh Bot added the pr-backward-incompatible Pull request with backwards incompatible changes label Jun 18, 2026
Comment thread src/Backups/registerBackupEngineS3.cpp Resolved
alexey-milovidov and others added 4 commits June 20, 2026 05:37
The earlier change only rejected zip archives for the direct `S3(...)` and
`AzureBlobStorage(...)` backup engines. A `Disk(...)` destination can also be
backed by object storage (for example an `s3`-typed disk), and in that case a
zip archive hits the exact same seek-heavy read path through `BackupReaderDisk`:
zip requires seeking to read its central directory, and every seek over object
storage turns into a separate HTTP request (issue ClickHouse#53483).

Reject `.zip`/`.zipx` in `registerBackupEnginesFileAndDisk` as well when the
disk's `getDataSourceDescription().object_storage_type` is `S3` or `Azure`, so
the slow path is not reachable through the `Disk` backup engine. Local-disk
`Disk(...)` and `File(...)` zip backups remain allowed.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Remove the old `test_backup_to_zip`, which backed up to `S3('....zip', ...)` and
expected success; that expectation now contradicts the rejection introduced by
this PR and made the suite assert both old and new behavior (the test failed in
CI). The new behavior is already covered by `test_backup_to_s3_zip_not_supported`.

Add `test_backup_to_object_storage_disk_zip_not_supported`, which backs up to
`Disk('disk_s3', '....zip')` (an `s3`-typed disk) and asserts the new
`BAD_ARGUMENTS` rejection, covering the object-storage-backed `Disk` path.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…-backup

# Conflicts:
#	tests/integration/test_backup_restore_s3/test.py
`disk_s3_plain_rewritable_03517` is an `object_storage`/`s3` disk, so backing up
a `.zip` archive to it is now rejected (zip requires seeking, which is slow over
object storage). Switch the test to a `.tar` archive: it triggers the same empty
`root_path` (the archive's `parent_path`) that the test guards against during
plain_rewritable cleanup, so the stack-overflow regression coverage is preserved.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

Pushed d983d0787bb..ad363f677fa to address the two blocking AI-review findings and the resulting CI failures.

Blocker 1 — contradictory S3 zip test (the red CI): removed the old test_backup_to_zip, which backed up to S3('....zip', ...) and expected success; that expectation contradicts this PR. The rejection is now covered by test_backup_to_s3_zip_not_supported.

Blocker 2 — object-storage Disk bypass: registerBackupEnginesFileAndDisk now also rejects .zip/.zipx for a Disk(...) destination whose disk is backed by object storage (object_storage_type is S3 or Azure). Added test_backup_to_object_storage_disk_zip_not_supported. Local File(...) and local-disk Disk(...) zip backups stay allowed.

Master tests adapted to the new behavior (they backed up/restored zip on object storage and would otherwise fail):

  • test_restore_from_s3_archive_ignores_prefixed_archive (S3 integration) → switched to a .tar archive; still exercises the exact-object-key matching it guards.
  • 03831_backup_archive_to_plain_rewritable_disk (functional, backs up to the s3_plain_rewritable disk_s3_plain_rewritable_03517) → switched to .tar; same empty-root_path cleanup it regression-tests.

Also merged master (the branch was ~700 commits behind), and updated the PR description/changelog to state the expanded scope (object-storage Disk destinations, both BACKUP and RESTORE).

Note: the existing approval predates this scope expansion (the Disk rejection is new behavior), so a re-review of the broadened behavior would be worthwhile before merge. Waiting on a fresh CI run.

BackupImpl::ArchiveParams archive_params;
if (hasRegisteredArchiveFileExtension(s3_uri))
{
if (hasSupportedZipExtension(s3_uri))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also rejects RESTORE ... FROM S3('...zip') for archives that already exist, because the check runs before the open_mode branch. That makes old object-storage .zip backups unrestorable immediately after upgrade unless the operator manually copies them to local storage, and there is no compatibility/override setting for a disaster-recovery restore. Please either keep the rejection to writes/new backups, or add an explicit opt-in compatibility setting for READ/UNLOCK paths and document that migration path.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rejecting RESTORE ... FROM S3('...zip') for pre-existing archives is intentional, not an oversight — it is the slow path reported in #53483 (reading the zip central directory seeks, and every seek is a separate HTTP request, which makes such a RESTORE effectively unusable, not merely slow). That is why this is categorized as a Backward Incompatible Change.

The data is not stranded: a supported migration path remains for the rare operator whose only copy is a .zip on object storage — copy the archive to local storage and restore from there, since local File('...zip') and local-disk Disk('...zip') zip backups stay allowed. The hard rejection only removes the direct object-storage seek path.

I've added a focused RESTORE test (test_restore_from_s3_zip_not_supported in 52ec036aac0) that locks this contract: a non-existent .zip object is enough to prove the rejection fires up front, by file extension, before the archive is ever opened.

Whether to additionally offer an explicit opt-in compatibility setting that re-enables the seek-heavy READ/UNLOCK path is a product decision for the maintainers — it would reopen exactly the path this PR closes, so I've left it out rather than add it speculatively.

alexey-milovidov and others added 2 commits June 29, 2026 12:00
Address AI review: the existing tests covered only BACKUP rejection. The
seek-heavy path reported in issue ClickHouse#53483 is also hit on RESTORE, and the
zip check in `registerBackupEngineS3` fires by file extension before the
`open_mode` branch, so `RESTORE ... FROM S3('...zip')` is rejected up front
too. This test locks that contract: a non-existent `.zip` object is enough
to prove the archive is never opened.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

Pushed ad363f677fa..52ec036aac0.

What changed since the last CI run:

  • Merged master (branch was behind; merge-base is now 2026-06-29).
  • Added a focused RESTORE-rejection integration test (test_restore_from_s3_zip_not_supported in test_backup_restore_s3/test.py), addressing the AI review's request for RESTORE coverage. The C++ in all three backup engines (registerBackupEngineS3, registerBackupEngineAzureBlobStorage, registerBackupEnginesFileAndDisk) is unchanged from the previously-green run — only the test and the master merge are new.

On the AI ❌ Block (RESTORE of pre-existing object-storage .zip): replied in-thread — the rejection is intentional (it is the seek-heavy path from #53483) and a supported migration path remains (copy the archive to local storage and RESTORE ... FROM File('...zip'), which stays allowed). Adding an explicit opt-in compatibility setting that re-enables the object-storage seek path is a product decision left to you, since it would reopen exactly what this PR closes.

CI: the only red on the previous run was Stress test (arm_asan_ubsan, s3), failing with Logical error: 'Unexpected exception in refresh scheduling' (STID 2508-…) — a known refreshable-materialized-view fuzz flake (see #106737, #81850, #77472), unrelated to backups. Fresh CI is now running on 52ec036aac0.

Note: the existing approval predates the scope expansion (object-storage Disk rejection + RESTORE), so a re-review of the broadened behavior is still worthwhile before merge.

@alexey-milovidov

Copy link
Copy Markdown
Member

Re-checked 52ec036aac0 — nothing to change. The C++ in all three backup engines (registerBackupEngineS3, registerBackupEngineAzureBlobStorage, registerBackupEnginesFileAndDisk) is correct, and the test coverage is comprehensive (S3/Azure BACKUP rejection, S3 RESTORE rejection, object-storage-backed Disk rejection, plus the two adapted master tests).

CI completed since the last comment:

  • The full integration suite is green, including test_backup_restore_s3 (the new test_backup_to_s3_zip_not_supported, test_restore_from_s3_zip_not_supported, test_backup_to_object_storage_disk_zip_not_supported) and test_backup_restore_azure_blob_storage (test_backup_zip_not_supported) — these were still running at the time of the previous comment.
  • All completed stateless shards are green, including the modified 03831_backup_archive_to_plain_rewritable_disk (now .tar).
  • All builds and Fast test are green.

Only reds: Stress test (amd_tsan) and Stress test (arm_tsan), both failing with Hung check failed, possible deadlock found — the master-wide flake #107941 (CIDB: 168 failures across 77 PRs today, 183 across 75 PRs yesterday), unrelated to backups. Two amd_llvm_coverage stateless shards are still in progress.

MERGEABLE, AI Review verdict is ✅ Approve, no unresolved review threads.

@alexey-milovidov

Copy link
Copy Markdown
Member

CI on 52ec036aac0 is now fully complete (the two amd_llvm_coverage stateless shards that were still running at the time of my previous comment have finished green, and the LLVM coverage report has arrived with no coverage regression).

Final tally: 148 passed / 20 skipped / 2 failed. The only two reds are Stress test (amd_tsan) and Stress test (arm_tsan), both Hung check failed, possible deadlock found — the master-wide flake #107941 (CIDB: 207 failures across 94 PRs today, 183 across 76 PRs yesterday — it fires on master itself, with no backup-engine frames in the thread dumps). The CI summary above links the issue directly, so it is already tracked; re-merging would not fix it.

Nothing to change on my side: the C++ in all three backup engines is correct, test coverage is comprehensive (S3/Azure BACKUP rejection, S3 RESTORE rejection, object-storage-backed Disk rejection, plus the two adapted master tests), MERGEABLE, AI Review ✅ Approve, no unresolved review threads. The 53.57% changed-line figure in the coverage report is expected — the rejection branches are exercised by the integration tests, which run on a separate build from the single coverage build.

The PR is effectively ready to merge, pending your re-review of the broadened scope (object-storage Disk + RESTORE) and a rerun/override of the #107941 flake.

@alexey-milovidov

Copy link
Copy Markdown
Member

Re-ran the two red Stress test (amd_tsan) / Stress test (arm_tsan) jobs on the current head 52ec036aac0 — both are back in progress now.

These were the only reds, and both failed with Hung check failed, possible deadlock found — the master-wide flake #107941, whose thread dumps contain no backup-engine frames. The flake has largely subsided since this run (CIDB: 528 Hung check failures across 180 PRs on 2026-06-30, when the run executed, dropping to 77 across 47 PRs on 07-01 and ~1 on 07-02), so the re-run should come back green.

Everything else is green (148 passed / 20 skipped), including all builds, Fast test, the full integration suite (test_backup_restore_s3, test_backup_restore_azure_blob_storage), the modified 03831_backup_archive_to_plain_rewritable_disk, and all other stress variants. MERGEABLE, AI Review verdict ✅ Approve, no unresolved review threads.

The only remaining step before merge is a re-review of the broadened scope (object-storage Disk rejection + RESTORE), since the existing approval predates that expansion.

@alexey-milovidov

Copy link
Copy Markdown
Member

The re-run of the two stress jobs on 52ec036aac0 has completed, and — contrary to my previous note — both Stress test (amd_tsan) and Stress test (arm_tsan) failed again with Hung check failed, possible deadlock found, i.e. the master-wide flake #107941 (still OPEN; thread dumps contain no backup-engine frames). A rerun does not deterministically clear it, and there is no fix on master to merge in — the branch is only ~3 days behind (merge-base 2026-06-29), MERGEABLE, no conflicts — so a re-merge would just retrigger the same flake rather than resolve it. Leaving the head as-is.

Mergeable Check and CH Inc sync are both green, and the two stress reds are non-required (the aggregate PR failure is driven solely by them), so the PR is mergeable as it stands. AI Review is ✅ Approve, no unresolved review threads, and Stress test (arm_asan_ubsan, s3) — the refreshable-MV flake from the earlier run — is now green as well.

I re-verified the diff end-to-end: the zip rejection in all three engines (registerBackupEngineS3, registerBackupEngineAzureBlobStorage, and registerBackupEnginesFileAndDisk — the last gated on object_storage_type ∈ {S3, Azure}) fires before the is_internal_backup check and only for .zip/.zipx, and the tests cover S3/Azure BACKUP rejection, S3 RESTORE rejection, object-storage-backed Disk rejection, plus the two adapted master tests. Correct and complete.

The only remaining step before merge is your re-review of the broadened scope (object-storage Disk rejection + RESTORE), since the existing approval predates that expansion.

@alexey-milovidov

Copy link
Copy Markdown
Member

Refreshed the branch by merging the latest master (commit 3545dd58a86). The branch had fallen ~2 weeks behind, and in the meantime registerBackupEngineS3.cpp drifted on master with the S3 credential-provenance rework (named_collection_auth). The merge is clean — the zip-rejection block and its ArchiveUtils.h include sit in the hasRegisteredArchiveFileExtension branch, entirely separate from master's credential parsing, so both changesets coexist — and I verified the three touched backup-engine translation units still compile. This only refreshes the base for a current CI run; the broadened scope (Disk object-storage rejection + RESTORE rejection) still awaits your re-review before merge.

@alexey-milovidov

Copy link
Copy Markdown
Member

Merged master into the branch again (the previous merge-base had grown over a week old). The merge was clean — no conflicts, and master did not touch any of the files changed here; the three affected backup-engine translation units still compile. CI will re-run on the fresh base.

azure_query(node, "DROP TABLE test_restored")


def test_backup_zip_not_supported(cluster):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR description now promises the same early rejection for RESTORE ... FROM AzureBlobStorage('...zip'), not just BACKUP, but this suite only exercises the write path. The S3 path already has a dedicated RESTORE regression because the important invariant is that the zip guard fires before the open_mode branch and before any blob is opened. Please add the analogous Azure negative test (a non-existent .zip blob is enough) so that moving this check below the READ/UNLOCK branch will fail CI.

assert "Zip archive format is not supported for S3 backups" in error, error


def test_backup_to_object_storage_disk_zip_not_supported(cluster):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This covers the object-storage Disk(...) write path, but the PR body also claims RESTORE is rejected for Disk(...) destinations backed by object storage. That contract is still untested: unlike test_restore_from_s3_zip_not_supported, nothing fails if a future refactor leaves the guard only on the writer side. Please add a negative RESTORE TABLE ... FROM Disk('disk_s3', '...zip') case (using a non-existent archive is enough) to lock the READ path too.

BackupImpl::ArchiveParams archive_params;
if (hasRegisteredArchiveFileExtension(s3_uri))
{
if (hasSupportedZipExtension(s3_uri))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a user-visible behavior change, and the repo still has English docs that instruct people to do exactly what now throws BAD_ARGUMENTS: docs/products/cloud/guides/migration/oss-to-cloud-backup-restore.mdx:419 uses S3('...backup.zip'), and docs/integrations/connectors/data-ingestion/AWS/integrating-s3-with-clickhouse.mdx:1291-1301 uses Disk('s3_express', 't.zip') for both BACKUP and RESTORE. Please update those examples to a tar-based format and document the migration path for existing object-storage .zip backups.

@clickhouse-gh

clickhouse-gh Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.20% 86.20% +0.00%
Functions 92.00% 92.00% +0.00%
Branches 78.30% 78.30% +0.00%

Changed lines: Changed C/C++ lines covered: 15/28 (53.57%) · Uncovered code

Full report · Diff report

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 21, 2026
Merged via the queue into ClickHouse:master with commit 322df1e Jul 21, 2026
178 checks passed
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 21, 2026
@PedroTadim

Copy link
Copy Markdown
Member

@Onyx2406 what about other compression formats? Should they be disallowed as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-backward-incompatible Pull request with backwards incompatible changes pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Disallow zip backup format when the backup uses S3

4 participants