Skip to content

Use the backup S3 retry settings for the destination of a restore fallback - #127638

Merged
jkartseva merged 6 commits into
masterfrom
jkartseva/restore-fallback-backup-retries
Nov 7, 2026
Merged

jkartseva merged 6 commits into
masterfrom
jkartseva/restore-fallback-backup-retries

Conversation

@jkartseva

@jkartseva jkartseva commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Related: #87660

copyS3File issues every request of a native copy with the client it is given as the source, and uses the
destination client only in fallback_method, which reads the source and reuploads it. On the backup side both are
covered since #87660; on the restore side only the source is, so the upload of a fallback retried on the
s3_retry_attempts of the disk instead of backup_restore_s3_retry_attempts.

The destination is now cloned through the same S3BackupDiskClientFactory the backup side uses, which keeps the
configuration of the disk - cloning it rather than reusing the backup client is what preserves SSE-KMS - and
overrides only the retry strategy.

A fallback is also traced now, on the restore side and for a ranged copy declining the native path, neither of
which said anything before.

Not covered: BackupReaderDefault::copyFileToDisk writes through IDisk::writeFile, the write path of the disk
itself, with no client to override.

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Fix RESTORE from S3 ignoring the backup_restore_s3_retry_* settings for the upload into the destination disk when a server-side copy is not used, which made it retry on the s3_retry_attempts of that disk instead and give up earlier than the restore was configured to. Also log when a copy of a byte range does not use the server-side copy and reads and reuploads the range instead.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/127638]

Version info

  • Merged into: 26.11.1.1590-master (included in 26.11 and later)

jkartseva and others added 3 commits October 23, 2026 19:26
A ranged copy needs `UploadPartCopy`, so `CopyFileHelper::performCopy` declines the native path when multipart
copy is unavailable or the source is not above the size S3 requires of a ranged copy source, and reads and
reuploads the range instead. It did so silently, while the other three ways into `fallback_method` each say
something - at `LOG_INFO`, in an exception, or at `LOG_TRACE`. This one is the most common of the four, because
every ranged copy of an object of at most `MIN_SOURCE_SIZE_FOR_RANGE_COPY` takes it, so the path that moves the
most objects was the one that could not be measured.

Co-Authored-By: Claude Opus 5 <[email protected]>
`copyS3File` issues every request of a native copy with the client it is given as the source, and uses the
destination client only in `fallback_method`, which reads the source and reuploads it. On the backup side both
are already covered: the source is the disk client cloned with the backup retry settings, and the destination is
the backup client. On the restore side only the source is - it is the backup client - while the destination was
the client of the disk as the disk configures it, so the upload of a fallback retried on `s3_retry_attempts`
instead of `backup_restore_s3_retry_attempts`, and the same object written by a native copy and by a fallback
got two different retry budgets.

The destination is now cloned through the same `S3BackupDiskClientFactory` the backup side uses, which keeps the
configuration of the disk, including its encryption settings, and overrides only the retry strategy and
`backup_slow_all_threads_after_retryable_s3_error`.

A restore taking the fallback is also traced now, as the backup side already traces it.

The fallback of `RestorerFromBackup` that writes through `IDisk::writeFile` is not covered: it is the write path
of the disk itself, with no client to override.

Co-Authored-By: Claude Opus 5 <[email protected]>
…own settings

`test_backup_restore_s3` already runs the `broken_s3` mock on port 8084 and drives it through the `init_broken_s3`
and `broken_s3` fixtures, so the tests go there. All the module was missing is a disk whose endpoint goes through
that mock: the existing tests use it as a backup destination, never as the storage a table lives on. So
`disk_s3.xml` gains `disk_s3_broken` and `policy_s3_broken`, with `s3_retry_attempts` set to 0.

With the mock answering `SlowDown` to the uploads of the destination, and the disk allowing no retries of its
own, the restore gets its data in only if its upload is retried with the `backup_restore_s3_retry_attempts` of the
restore instead. The mirror case sets those retries to none and asserts that a single injected answer fails the
restore, so the first test cannot pass on a client that merely retries a lot.

`allow_s3_native_copy=0` is what reaches the path at all: it is the one way into the fallback of `copyS3File`
that needs no error. The metadata of an `s3` disk is local and merges are stopped, so the data blobs of the
restore are the only uploads into the destination and nothing else can consume the injected answers.

Co-Authored-By: Claude Opus 5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [8ce468b]

Summary: ✅


AI Review

Summary

The change applies backup retry settings to buffered restore uploads by cloning the destination disk client and rebuilding its SDK retry strategy. The five prior findings are addressed in the current code. One new test-isolation issue remains: the added tests leave shared tables behind and break existing tests when execution order changes.

Missing context / blind spots
  • ⚠️ No local build or integration tests were run. Current-head targeted integration and bugfix-validation jobs are pending; completed results and an ordered run covering the interaction below would close the runtime validation gap.
Findings

⚠️ Majors

  • tests/integration/test_backup_restore_s3/test.py:1743, also line 1760: both new tests leave data and data_restored in the module-scoped cluster. If either precedes test_incremental_backup_append_table_def, its CREATE TABLE data fails with TABLE_ALREADY_EXISTS. Existing check_backup_and_restore callers instead encounter the incompatible leftover data_restored and fail with CANNOT_RESTORE_TABLE. Explicit selection order and the integration runner's randomized --count mode expose this. Reset the mock and drop both tables with SYNC in teardown that also runs on failure.
Final Verdict

Status: ⚠️ Request changes. Add reliable teardown to both new tests and verify that either can precede existing module tests without affecting them.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Oct 23, 2026
Comment thread src/Backups/BackupIO_S3.cpp Resolved
@clickhouse-gh clickhouse-gh Bot added the comp-backup Backup/restore infrastructure and backup formats. label Oct 23, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 8ce468b0a with master 8908f932f (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 360ab5255; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

11 translation units recompiled, 38 s compile time in total, 11 of them have a recent master baseline.

Job report

…ans to

`cloneWithConfigurationOverride` passed the configuration of the client being cloned straight on, keeping its
`retryStrategy`, the object the SDK retries with: `ClientFactory::create` is the only place that builds one, from
`retry_strategy`, so overriding that field alone changed nothing. The clone now builds it, with the same cap on
`backup_slow_all_threads_after_retryable_s3_error` as the factory. This is what makes the retries of a backup or
a restore reach the client of a disk at all, so it also completes the override of #87660.

`DataSourceDescription::sameKind` compares the endpoint, so a backup on another one sent the restore through the
buffers of `BackupReaderDefault` instead of the native branch the fallback lives in. The tests put the backup on
the endpoint of the disk, where the client of the destination is the one that uploads.

The injected answer carries `SlowDown` as its code and `Slow Down.` as its message, and the message is what
surfaces, as `test_checking_s3_blobs_paranoid` already records. The assertion matches that.

The new disk is added to the expectation of `check_system_tables`, which asserts the exact number of disks.

Co-Authored-By: Claude Opus 5 <[email protected]>
The positive test failed on the injected `SlowDown`: the first object the restore uploaded into the destination
was not a data blob but `format_version.txt`, the one-byte file `MergeTree` writes when a table is created,
which goes through the client of the disk and so allows no retries. The restore failed while creating the table,
before reaching the upload the retries of the restore are supposed to cover.

    Code: 499. Message: Slow Down., bucket root, key data/disks/disk_s3_broken/..., object size 1:
    While creating table default.data_restored
      DB::WriteBufferFromS3::makeSinglepartUpload

The table is created before the mock is armed, so the only uploads left in the window are the data blobs.
`allow_different_table_def` accepts it: its definition differs from the one in the backup only by its name.

Co-Authored-By: Claude Opus 5 <[email protected]>
opensource-fork-sync Bot pushed a commit to cla7aye15I4nd/opensource-ClickHouse__ClickHouse that referenced this pull request Oct 26, 2026
The `cache read` and `cache entries with ties kept` checks rerun queries
whose entries earlier queries of the test wrote to the server-wide query
condition cache. Dropping or renaming a MergeTree table without a UUID
(in an Ordinary or Memory database) calls `Context::clearCaches()`, which
also empties that cache. In both CI failures a parallel test did that
between the fill and the rerun (04498_database_max_tables on master,
01069_database_memory on ClickHouse#127638), so the rerun missed all 3 parts and
printed `cache read 0`.

Run the test only in the sequential job flavors, as done for 05258 in
ClickHouse#125702. Queries and the reference are unchanged; the Random settings
limits line is kept byte-identical.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@jkartseva
jkartseva requested a review from kolsha November 2, 2026 21:18

node.query(restore_from_broken_disk_backup(backup_destination, retry_attempts=100))

assert node.query("SELECT count() FROM data_restored") == "100\n"

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.

[P2] Clean up both tables after the new restore tests

Both new tests leave data and data_restored in the module-scoped cluster. Running either before test_incremental_backup_append_table_def makes that existing test fail at CREATE TABLE data with TABLE_ALREADY_EXISTS. Running either before a check_backup_and_restore caller also makes its restore encounter the leftover single-column data_restored, whose definition differs from the three-column backup, and fail with CANNOT_RESTORE_TABLE. This can happen with explicitly ordered test selections or the integration runner's --count mode, which enables --random-order.

Please add cleanup in finally or a shared fixture for both new tests: reset broken_s3, then drop data and data_restored with SYNC, including when an assertion or restore fails.

@jkartseva
jkartseva enabled auto-merge November 7, 2026 03:02
@jkartseva
jkartseva added this pull request to the merge queue Nov 7, 2026
Merged via the queue into master with commit 7a516a1 Nov 7, 2026
187 checks passed
@jkartseva
jkartseva deleted the jkartseva/restore-fallback-backup-retries branch November 7, 2026 07:57
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 7, 2026
opensource-fork-sync Bot pushed a commit to cla7aye15I4nd/opensource-ClickHouse__ClickHouse that referenced this pull request Nov 12, 2026
`BACKUP` to and `RESTORE` from `S3(...)` for a table on an S3 disk with the
same endpoint copy natively through `S3BackupClientCreator`, which takes the
disk client's configuration and assigns the backup's raw retry settings to it.
Since ClickHouse#127638, `Client::cloneWithConfigurationOverride` builds the SDK retry
object from that override, but the only validation of `retry_strategy` was in
the `PocoHTTPClientConfiguration` constructor, which a copied configuration
never runs. So `backup_restore_s3_retry_jitter_factor = 2` (or `-1`) reached the
`chassert`s in `Client::RetryStrategy::RetryStrategy` and aborted debug and
sanitizer servers; release builds kept the unclamped value.

Move the constructor's checks (throw if the initial delay exceeds the maximum,
clamp the jitter factor into [0, 1] with the same `LOG_INFO`) into
`PocoHTTPClientConfiguration::validateRetryStrategy` and call it on the
override's configuration in `cloneWithConfigurationOverride` before the retry
object is built. The validated struct is the one stored in the clone, so the
`ExpiredToken` retry, which rebuilds a `RetryStrategy` from the stored field,
gets the clamped value too. For a valid configuration the call is a no-op.

The new test runs `BACKUP` with jitter 2 and `RESTORE` with jitter -1 on
`s3_disk`, and asserts `S3CopyObject > 0` for both so that it fails if they stop
taking the native copy path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-backup Backup/restore infrastructure and backup formats. pr-bugfix Pull request with bugfix, not backported by default 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.

3 participants