Skip to content

Do not fail server startup when a Backup database refers to unavailable storage - #83188

Merged
alexey-milovidov merged 5 commits into
ClickHouse:masterfrom
orloffv:patch-7
Jul 18, 2026
Merged

alexey-milovidov merged 5 commits into
ClickHouse:masterfrom
orloffv:patch-7

Conversation

@orloffv

@orloffv orloffv commented Jul 3, 2025 •

Copy link
Copy Markdown
Contributor

When a database (or table) was created with ENGINE = Backup(...) and the backup later became unavailable (its files were deleted, or the underlying storage such as S3 became inaccessible), the server failed to start entirely. Opening the backup in DatabaseBackup::beforeLoadingMetadata threw, and the exception aborted the whole startup, making recovery hard even if only one database depended on the missing backup.

Now, on server startup (FORCE_ATTACH/FORCE_RESTORE mode), a failure to open the backup is logged and the Backup database is loaded without any tables, following the same pattern that DatabaseReplicated already uses to tolerate an unavailable ZooKeeper on startup. The server starts normally; once the backup becomes available again, restart the server to access its tables. Interactive CREATE/ATTACH DATABASE still surfaces the error as before.

The test added by this PR (a reproducer originally contributed by @orloffv) now passes for all backup destinations (File, local Disk, s3_plain, and object_storage with local_blob_storage).

Closes: #83187

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):

Fixed the server failing to start when a Backup database engine refers to a backup that has become unavailable (for example, when its files were deleted or the underlying storage is inaccessible). The database is now loaded without tables instead of preventing the whole server from starting.

@alesapin alesapin added the can be tested Allows running workflows for external contributors label Jul 3, 2025
@clickhouse-gh

clickhouse-gh Bot commented Jul 3, 2025 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [b91e6cf]

Summary: ✅


AI Review

Summary

This PR makes DatabaseBackup tolerate a failed backup open during existing-metadata loading (FORCE_ATTACH/FORCE_RESTORE) by logging the exception and attaching the Backup database with no tables instead of aborting server startup. Normal interactive CREATE/ATTACH DATABASE paths still propagate the error, and the added integration test covers the promised recovery behavior across File, local Disk, s3_plain, and object_storage backup destinations. I did not find a correctness blocker.

Missing context / blind spots
  • ⚠️ I did not rerun the integration suite in this review environment. The current PR report URL for commit b91e6cf378fbd5aa1788072a7ee2e7ff05e197a6 returned zero recorded test results; a completed Praktika run for test_database_backup would close runtime validation.
Final Verdict

Status: ✅ Approve

No minimum required actions.

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Jul 3, 2025
@orloffv orloffv mentioned this pull request Jul 4, 2025
@alexey-milovidov

Copy link
Copy Markdown
Member

The code was added by @kitaisreal, let's invite him to fix.

@rienath rienath left a comment

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.

Let's keep this a draft until a fix lands

@rienath
rienath marked this pull request as draft June 15, 2026 17:02
alexey-milovidov and others added 3 commits June 29, 2026 10:20
…le storage

When a database was created with `ENGINE = Backup(...)` and the backup later
became unavailable (its files were deleted, or the underlying storage such as
S3 became inaccessible), the server failed to start entirely: opening the
backup in `DatabaseBackup::beforeLoadingMetadata` threw, and the exception
aborted the whole startup.

Now, on server startup (`FORCE_ATTACH`/`FORCE_RESTORE` mode), a failure to open
the backup is logged and the `Backup` database is loaded without any tables,
following the same pattern as `DatabaseReplicated` tolerating an unavailable
ZooKeeper on startup. Interactive `CREATE`/`ATTACH DATABASE` still surfaces the
error as before.

Closes: ClickHouse#83187

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Cover all backup destinations (File, local disk, s3_plain, object storage), and
after restarting with the backup deleted, assert that the `Backup` database is
still attached but loaded without tables, and that the original database is
unaffected.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@alexey-milovidov alexey-milovidov changed the title Tests for #83187 issue Do not fail server startup when a Backup database refers to unavailable storage Jun 29, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

The fix has landed. In addition to @orloffv's reproducer, this PR now fixes the underlying bug from #83187:

  • DatabaseBackup::beforeLoadingMetadata now tolerates a failure to open the backup when loading on server startup (FORCE_ATTACH/FORCE_RESTORE mode): it logs the error and loads the Backup database without any tables, instead of aborting the whole server startup. This mirrors how DatabaseReplicated already tolerates an unavailable ZooKeeper on startup. Interactive CREATE/ATTACH DATABASE still surfaces the error as before.
  • The regression test was extended to cover all backup destinations (File, local Disk, s3_plain, object_storage) and to assert that after restarting with the backup deleted, the Backup database is still attached but loaded without tables, and the original database is unaffected.

Verified locally: the whole test_database_backup integration suite passes (35 passed, 0 failed), including all four parametrizations of the new test. The branch was also brought up to date with master.

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default and removed pr-not-for-changelog This PR should not be mentioned in the changelog labels Jun 29, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.50% 85.40% -0.10%
Functions 92.60% 92.60% +0.00%
Branches 77.70% 77.60% -0.10%

Changed lines: Changed C/C++ lines covered by tests: 19/19 (100.00%) | Lost baseline coverage: none · Uncovered code

Full report · Diff report

@alexey-milovidov
alexey-milovidov marked this pull request as ready for review July 6, 2026 15:43
@alexey-milovidov

Copy link
Copy Markdown
Member

Marked ready for review — the draft condition (@rienath: "keep as draft until a fix lands") is now satisfied. The fix has landed, all CI is green (integration test_database_backup passes across all four backup destinations), the AI review verdict is Approve with no required actions, and changed lines have 100% test coverage. @rienath @kitaisreal, please take a look when you have a chance.

@alexey-milovidov alexey-milovidov self-assigned this Jul 18, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 18, 2026
Merged via the queue into ClickHouse:master with commit 789084e Jul 18, 2026
175 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 18, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
Do not fail server startup when a Backup database refers to unavailable storage
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-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.

Server fails to start if backup table refers to unavailable S3 storage

5 participants