Skip to content

Tolerate a missing file when cleaning up a corrupted in-memory backup - #109947

Merged
jkartseva merged 7 commits into
masterfrom
jkartseva/backup-memory-cleanup-tolerate-missing-files
Jul 22, 2026
Merged

jkartseva merged 7 commits into
masterfrom
jkartseva/backup-memory-cleanup-tolerate-missing-files

Conversation

@jkartseva

@jkartseva jkartseva commented Jul 9, 2026 •

Copy link
Copy Markdown
Member

A BACKUP ... TO Memory(...) that fails before finalization never writes the .backup metadata file. The cleanup path (tryRemoveAllFiles) still tried to remove it, and BackupInMemory::removeFile threw BACKUP_ENTRY_NOT_FOUND, aborting cleanup and leaving the backup registered — so the same Memory(...) name could not be reused (it failed with BACKUP_ALREADY_EXISTS).

This makes the in-memory writer's removal best-effort (logging a missing entry at DEBUG instead of throwing), matching the S3, Disk and File writers, and skips empty data_file_name entries so an empty name cannot resolve to the backup root. Both issues predate the refactoring and were found by the review bots on #109861.

A backup_fail_before_writing_metadata failpoint and a stateless regression test (04509_backup_to_memory_cleanup_after_failure) are added.

Depends on #109861 — this branch is based on it and includes its commits so CI runs against a complete tree. #109861 should merge first; afterwards this PR's diff reduces to the cleanup fix, the failpoint, and the regression test.

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 cleanup of a BACKUP ... TO Memory(...) that fails before finalization: the failed backup was left registered so its name could not be reused.

Version info

  • Merged into: 26.7.1.1311 (included in 26.7 and later)

jkartseva and others added 2 commits July 9, 2026 23:12
A BackupFileInfo can have an empty data_file_name (an empty file, or a
whole-file reference to a base backup). Pushing an empty name into the list
passed to removeFiles could resolve to the backup root on some writers, so
skip such entries.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
A BACKUP ... TO Memory(...) that fails before finalization never writes the
`.backup` metadata file. tryRemoveAllFiles still tried to remove it, and
BackupInMemory::removeFile threw BACKUP_ENTRY_NOT_FOUND, aborting cleanup and
leaving the backup registered so the name could not be reused. Make the
in-memory writer's removal best-effort, matching the S3, Disk and File writers,
and log a missing entry instead of ignoring it silently.

Adds a backup_fail_before_writing_metadata failpoint and a regression test.

Related: #109861

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

clickhouse-gh Bot commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [2d5e04f]

Summary: ✅


AI Review

Summary

This PR hardens failed-backup cleanup by making Memory(...) deletion best-effort when .backup was never written, by skipping empty data_file_name entries that would otherwise resolve to the backup root on non-archive writers, and by adding focused regressions for both paths. I did not find a remaining correctness issue in the current diff; the earlier bot concern about the empty-name cleanup path is now covered by 04510, and the plain-backup reference path still assigns non-empty data_file_name, so the cleanup contract looks consistent.

Missing context / blind spots
  • ⚠️ The long-running Praktika build and sanitizer jobs were still pending during review, so I could not use their results to validate the change under the full CI matrix. Passing amd_debug, amd_asan_ubsan, amd_tsan, amd_msan, and the arm counterparts would close that gap.
Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jul 9, 2026
The style check rejects test filenames containing 'fail'.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Comment thread src/Backups/BackupImpl.cpp Resolved
jkartseva and others added 2 commits July 10, 2026 01:18
Exercises tryRemoveAllFiles on a Disk (non-memory) writer: an unchanged
incremental backup has fully base-backed entries whose data_file_name is empty.
Without the guard, cleanup of a backup that failed before finalization calls
removeFile(""), which resolves to the backup root (root_path / ""), unlinks the
backup directory (EISDIR) and throws, aborting cleanup and leaving the failed
backup behind so its destination cannot be reused. The test asserts the
destination is reusable after the failure.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The failed backup prints FAULT_INJECTED more than once (server-forwarded log
line, client exception, and the error-code suffix), so grep -o emitted several
lines. Keep only the first so the output is deterministic.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Comment thread src/Backups/BackupImpl.cpp Resolved
@SmitaRKulkarni SmitaRKulkarni self-assigned this Jul 20, 2026
Comment thread src/Backups/BackupInMemory.cpp Resolved

@SmitaRKulkarni SmitaRKulkarni 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.

Rest all LGTM

jkartseva and others added 2 commits July 20, 2026 23:54
The previous comment said 'base-backup reference', which reads as a
`BackupEntryReference`. It actually means a file wholly covered by the
base backup. Reword to name the two empty-`data_file_name` cases
directly (empty file, or wholly base-covered) and why the skip matters.

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

Copy link
Copy Markdown
Member Author

CI failures are unrelated to this PR (which touches only src/Backups/*):

Both are pre-existing, tracked flakies. Retrying the failed jobs.

@clickhouse-gh

clickhouse-gh Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 36 queries analysed

This is a BACKUP-subsystem bugfix (failed-backup cleanup in BackupImpl/BackupInMemory, a new failpoint, and two regression tests) — it does not touch any SELECT query execution path. The three flagged ClickBench queries (Q4 -20.2%, Q15 -20.6%, Q17 +10.1%) all show unchanged CPU time while wall-clock moved, and every median sits within master's current-era variance band, so the deterministic within-envelope suppression is correct. These deltas are run-to-run cache variance, not effects of this PR. No actionable performance change.

clickbench

⚠️ 1 inconclusive

Flagged queries (1 of 43)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 17 not_sure 493 543 +10.1% <0.0001 cache: +10.1% with flat CPU (7056 vs 7077 ms) and both medians inside master's band. Backup cleanup fix does not touch this SELECT; correctly held at not_sure.

Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on.

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: 66e8a42d-21c1-4ebb-9de0-6debc5c1a4d2
  • MIRAI run: 54ac8857-cafd-4e74-ba52-84306cf602e2
  • PR check IDs:
    • clickbench_124338_1784694937
    • clickbench_124350_1784694937
    • clickbench_124356_1784694937
    • tpch_adapted_1_official_124363_1784694937
    • tpch_adapted_1_official_124374_1784694937
    • tpch_adapted_1_official_124387_1784694937

@clickhouse-gh

clickhouse-gh Bot commented Jul 22, 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.20% 78.30% +0.10%

Changed lines: Changed C/C++ lines covered: 23/23 (100.00%) · Uncovered code

Full report · Diff report

@jkartseva
jkartseva added this pull request to the merge queue Jul 22, 2026
Merged via the queue into master with commit bdd74d1 Jul 22, 2026
352 of 354 checks passed
@jkartseva
jkartseva deleted the jkartseva/backup-memory-cleanup-tolerate-missing-files branch July 22, 2026 04:52
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 22, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…-memory-cleanup-tolerate-missing-files

Tolerate a missing file when cleaning up a corrupted in-memory backup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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