8000 embedded URL restore: update .backup manifest after .sql rewrite by Slach · Pull Request #1669 · Altinity/clickhouse-backup · GitHub
[go: up one dir, main page]

Skip to content

embedded URL restore: update .backup manifest after .sql rewrite - #1669

Open
Slach wants to merge 2 commits into
masterfrom
embedded_url_manifest_1668
Open

Slach wants to merge 2 commits into
masterfrom
embedded_url_manifest_1668

Conversation

@Slach
@Slach Slach commented Nov 6, 2026
Copy link
Copy Markdown
Collaborator

Fixes #1668

Problem

fixEmbeddedMetadataRemote rewrites metadata/**/*.sql objects in place for embedded backups without embedded_backup_disk (BACKUP TO S3/GCS/Azure(url)). It doesn't update the .backup manifest. ClickHouse 26.9.x and 26.10.1 compare the object size with the manifest before reading and fail with code: 1009 S3_OBJECT_CHANGED_DURING_READ. ClickHouse reverted that check in 26.10.2+ (ClickHouse/ClickHouse@62eb34814e2), but the manifest still gets out of sync.

Changes

  • pkg/backup/embedded_manifest.go: after the rewrite, the node that executes RESTORE recalculates size and checksum of every .sql listed in .backup and uploads the manifest back. The checksum is CityHash128 v1.0.2 chained over 2048-byte blocks, the same way HashingReadBuffer computes it. ON CLUSTER workers don't touch the shared manifest, so concurrent writes can't overwrite each other.
  • fixEmbeddedMetadataSQLQuery: {database}/{table} were taken from the wrong path components (metadata/<db> instead of <db>/<table>). Every ReplicatedMergeTree() table of a database got the same replica path, and restore failed with code: 253 Replica ... already exists.
  • Test infra: 26.10 refuses to start with unknown disk elements (code 137). dynamic_settings.sh drops cache_enabled/send_metadata for 26.10+.

Tests

  • Unit tests: checksums match a .backup written by ClickHouse 26.10, including a file larger than 2048 bytes. Manifest rewrite covers data_file, use_base and empty files.
  • New integration test TestEmbeddedS3URLRewrittenMetadata: ENGINE=Replicated database, ReplicatedMergeTree() without arguments, MV, create_remote / restore_remote --rm over S3 URL.
    • 26.9 without the fix: fails with code 1009, same as the reported log.
    • 26.9 with the fix: passes.
    • 26.8 with the fix: passes, and TestEmbeddedS3Cleanup passes too.
  • Not run locally: the full TestEmbedded* suite on 26.8/26.10. 26.9/26.10 are not in the CI matrix yet.

🤖 Generated with Claude Code

Slach added 2 commits November 6, 2026 17:09
fixEmbeddedMetadataRemote rewrites metadata/**/*.sql objects in the bucket
in place but left the .backup manifest untouched. ClickHouse 26.9.x and
26.10.1 check the object size against the manifest before reading and fail
with code 1009 S3_OBJECT_CHANGED_DURING_READ.

After the rewrite the node which executes RESTORE recalculates size and
checksum (CityHash128 over 2048 bytes blocks, as HashingReadBuffer does)
of every .sql listed in .backup and uploads the manifest back. ON CLUSTER
workers don't touch the shared manifest to avoid lost updates.

Also fix {database}/{table} substitution in fixEmbeddedMetadataSQLQuery:
they were taken from the wrong path components (metadata/<db> instead of
<db>/<table>), so every ReplicatedMergeTree() table of a database got the
same replica path and restore failed with code 253.

Test infra: 26.10 refuses unknown disk elements (code 137), drop
cache_enabled/send_metadata for 26.10+.

Fixes #1668
ClickHouse 24.3 BACKUP to AzureBlobStorage stores files at the container
root instead of under the backup path, so fixEmbeddedMetadataRemote
rewrites nothing and reading them from the backup path fails with
BlobNotFound. Check only .sql files listed under the metadata dirs.

CH 24.3 doesn't support {database} macro in Replicated database path,
use the literal database name in TestEmbeddedS3URLRewrittenMetadata.
@coveralls
Copy link
Copy Markdown

Coverage Report for CI Build 42260192973

Coverage increased (+0.08%) to 70.706%

Details

  • Coverage increased (+0.08%) from the base build.
  • Patch coverage: 29 uncovered changes across 1 file (140 of 169 lines covered, 82.84%).
  • 23 coverage regressions across 6 files.

Uncovered Changes

File Changed Covered %
pkg/backup/embedded_manifest.go 162 133 82.1%
Total (2 files) 169 140 82.84%

Coverage Regressions

23 previously-covered lines in 6 files lost coverage.

File Lines Losing Coverage Coverage
pkg/backup/watch_schedule.go 8 77.22%
pkg/clickhouse/clickhouse.go 5 81.29%
pkg/backup/delete.go 3 74.2%
pkg/backup/freezes.go 3 72.95%
pkg/backup/create.go 2 74.65%
pkg/backup/create_remote.go 2 66.02%

Coverage Stats

Coverage Status
Relevant Lines: 30030
Covered Lines: 21233
Line Coverage: 70.71%
Coverage Strength: 35886.06 hits per line

💛 - Coveralls

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

embedded URL restore fails on ClickHouse 26.9+: code 1009 S3_OBJECT_CHANGED_DURING_READ after .sql metadata rewrite

2 participants

0