Skip to content

Fsync restored part files on RESTORE to survive power loss - #111378

Merged
alexey-milovidov merged 6 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-111321-restore-fsync
Aug 17, 2026
Merged

alexey-milovidov merged 6 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-111321-restore-fsync

Conversation

@groeneai

@groeneai groeneai commented Jul 22, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • Critical Bug Fix (crash, data loss, RBAC)

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

RESTORE now fsyncs the restored part files when the destination table has fsync_after_insert enabled, so a restored part is as durable against power loss as an inserted one. Previously restored files were only written and closed (never fsynced), so a power loss right after RESTORE returned RESTORED could leave the parts torn and the table empty.

Description

Closes: #111321

RESTORE materializes a MergeTree part outside the INSERT write path: MergeTreeData::restorePartFromBackup copies each part file via IBackup::copyFileToDisk, which only does copyData + finalize() (no fdatasync). The part is then attached through the rename machinery, so the part directory is fsynced when fsync_part_directory is set, but the file contents are never fsynced, even when the table sets fsync_after_insert. On a filesystem with delayed allocation the file data blocks are therefore not durable when RESTORED is returned; a power loss shortly after can leave every restored file at 0 bytes and the part is dropped as broken on the next start.

The two other part-materialization paths already fsync file contents: INSERT (via fsync_after_insert -> MergedBlockOutputStream) and the replicated fetch path (DataPartsExchange, if (sync) file->sync()). This makes RESTORE consistent with them.

Change: IBackup::copyFileToDisk takes a bool sync. When set, BackupImpl copies through a live destination buffer and fdatasyncs its contents before returning. MergeTreeData::restorePartFromBackup passes sync = fsync_after_insert && !disk->isRemote(), so a restored part on a local disk gets exactly the durability the table's fsync settings already promise an inserted part. On object storage the object is durable once finalized, so the flag is a no-op there.

Three restore copy paths carry sync:

  • the generic buffered path (this backup / concat / archive), and encrypted incremental restore where a full-base entry is delegated to the base backup;
  • object-key (lightweight snapshot) entries, which the object-key copy could not fsync, now go through a live buffer + finalize + sync when sync is requested, mirroring the generic path's encryption handling (reject encrypted -> non-encrypted disk, writeEncryptedFile for encrypted-by-disk entries);
  • required zero-byte entries (e.g. the .bin of an all-empty Array column), which INSERT also fsyncs, are created through a live buffer + finalize + sync instead of createFile.

Regression test 04550_restore_fsync_after_insert asserts, via the per-query FileSync ProfileEvents, that the on/off FileSync delta covers the number of files RESTORE actually copies (including a zero-byte file) with fsync_after_insert = 1, and stays below it with = 0. It also covers encrypted incremental restore.

Version info

  • Merged into: 26.8.1.1548 (included in 26.8 and later)
  • Backported to: 26.7.4.49, 26.6.3.48, 26.5.7.59, 26.3.19.3, 25.8.31.7

RESTORE materializes a MergeTree part outside the INSERT write path:
MergeTreeData::restorePartFromBackup copies each part file via
IBackup::copyFileToDisk, which only writes and finalizes the file (no
fdatasync). The part directory is fsynced by the later rename when
fsync_part_directory is set, but the file contents never are, even when
the table enables fsync_after_insert. On a filesystem with delayed
allocation the data blocks are therefore not durable when RESTORED is
returned, so a power loss shortly after can leave the restored files at
0 bytes and the part is dropped as broken on the next start.

Thread an optional sync flag through IBackup::copyFileToDisk (defaulted
to false, so other callers are unchanged). When set, BackupImpl copies
through a live destination buffer and fdatasyncs its contents before
returning, mirroring the INSERT and replicated-fetch paths.
restorePartFromBackup passes fsync_after_insert && !disk->isRemote(), so
a restored part on a local disk gets the same durability as an inserted
one; on object storage the object is durable once finalized.

Closes: ClickHouse#111321

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. On a wide (30-column, 73-file) part, the global FileSync delta around RESTORE is 2 on master (fsync_after_insert=1) vs 75 with the fix (idle noise = 0). The regression test flips 0->1 across binaries.
b Root cause explained? RESTORE copies part files via IBackup::copyFileToDisk = copyData + finalize(), never fdatasync. The later rename fsyncs the part directory (when fsync_part_directory), so dirents are durable but data blocks are not. Under delayed allocation a power loss right after RESTORED leaves files at 0 bytes -> broken-on-start -> empty table.
c Fix matches root cause? Yes. It fdatasyncs the exact file contents that were unsynced, gated on the table's own fsync_after_insert, mirroring the INSERT and replicated-fetch paths.
d Test intent preserved / new test added? New stateless test 04550_restore_fsync_after_insert.sh asserting per-query FileSync >= files-in-part for fsync_after_insert=1 and < files-in-part for =0. No existing test weakened.
e Both directions demonstrated? Yes. Test FAILS on master (CASE A = 0) and PASSES with the fix (CASE A = 1, CASE B = 0), on Build-ID-distinct binaries.
f Fix is general across code paths? Yes. Fixed at the single shared restore copy site; the base-backup and projection sub-paths route through the same synced buffered branch (verified). Not a symptom guard: it adds the missing durability step.
g Fix generalizes across inputs? Yes. Verified wide/narrow parts, Nullable/Array columns, incremental (base-backup) and projection restores (data byte-identical + CHECK TABLE in each). !isRemote() covers the local-vs-object-storage axis; encrypted disks use writeEncryptedFile (same WriteBufferFromFileBase::sync()).
h Backward compatible? Yes. New parameter defaulted false; no setting default / on-disk / wire-format change. fsync_after_insert=0 and remote-disk restore are unchanged.
i Invariants and contracts preserved? Yes. Restored data is byte-identical (cityHash64 sum + CHECK TABLE); copyFileToDisk still returns bytes-written and updates num_read_files/num_read_bytes on all paths; the buffered branch was already the correct fallback for every source (this-backup / base-backup / archive / encrypted / concat); finalize()-before-sync() matches the WriteBufferFromFileDescriptor contract.

Session id: cron:clickhouse-author-slot-6:20260722-105400

@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review — adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 1 finding;
bounded: 1 full pass + 1 fix round + 1 delta recheck).

# Sev Finding Verdict Evidence / action
1 ⚠️ The #if CLICKHOUSE_CLOUD lightweight-snapshot path (copyFileToDiskByObjectKey) does not forward the new sync flag. DISAGREE Dead code in OSS (CLICKHOUSE_CLOUD 0) — RESTORE falls through to the synced copyFileToDisk(SizeAndChecksum, ..., sync). The helper has no definition in src/ (private overlay), so adding a parameter to its declaration would break the cloud build. The branch serves only lightweight snapshots restoring object-storage-resident data, where the caller's sync = fsync_after_insert && !disk->isRemote() is always false. No behavioural gap; forwarding is a no-op that risks an untestable build.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per finding.

Session id: cron:clickhouse-author-slot-6:20260722-105400

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @pamarcos @SmitaRKulkarni — could you review this? It makes RESTORE fdatasync the restored part file contents (not just the part directory) when the destination table has fsync_after_insert enabled, closing a power-loss data-loss gap (#111321). The durability step is threaded as an optional sync flag through IBackup::copyFileToDisk and gated on fsync_after_insert && !disk->isRemote().

@clickhouse-gh

clickhouse-gh Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [9e5af08]

Summary: ✅


AI Review

Summary

This PR makes RESTORE honor fsync_after_insert for restored MergeTree part files, threads the sync request through the backup copy paths that can materialize those files, and strengthens coverage for the plain and encrypted incremental restore cases. After checking the current diff, the live code, the CI report, and the full prior discussion, I did not find a remaining correctness or durability issue in the implementation.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jul 22, 2026
groeneai added 2 commits July 22, 2026 13:26
The sync parameter was added as a defaulted argument on the virtual
IBackup::copyFileToDisk (and the BackupImpl overrides). clang-tidy's
google-default-arguments check prohibits default arguments on virtual
methods and is enforced as -warnings-as-errors in the arm_tidy build,
so the build failed there. Drop the default and pass sync explicitly at
the three call sites that relied on it (base-backup delegate, StorageLog,
StorageStripeLog). No behavior change: those callers already used false.
The previous commit gated the base-backup delegation branch in
BackupImpl::copyFileToDisk on !sync, forcing entries that come entirely
from the base backup (size == base_size) down the generic copy path when
sync was requested. For an encrypted-by-disk entry that path reads the
base via the public readFile(), which always requests unencrypted data,
so restoring an encrypted table from an incremental backup with
fsync_after_insert=1 failed with CANNOT_RESTORE_TO_NONENCRYPTED_DISK and
left the table empty.

Delegate full-base entries to the base backup and forward sync to it: the
base is itself a BackupImpl that honours sync and can read its own
encrypted entries, so durability is preserved without going through the
unencrypted public read path.
@groeneai

Copy link
Copy Markdown
Collaborator Author

Pushed two follow-up commits.

1. Fix Build (arm_tidy) failure. The sync parameter was added as a defaulted argument on the virtual IBackup::copyFileToDisk (and the BackupImpl overrides). clang-tidy google-default-arguments prohibits default arguments on virtual methods and is enforced as -warnings-as-errors only in the arm_tidy build, so local debug/asan builds and the pre-merge gates passed while arm_tidy failed. Dropped the default and pass sync explicitly at the three call sites that relied on it (base-backup delegate, StorageLog, StorageStripeLog). No behavior change: those callers already used false. Reproduced the exact 4 errors locally with clang-tidy-21 on the baseline and confirmed clean with the fix.

2. Fix an encrypted incremental-backup restore regression (found by internal review, then reproduced locally). The first commit gated the base-backup delegation branch on !sync, so a part that comes entirely from the base backup (size == base_size) was forced down the generic copy path when sync was requested. For an encrypted-by-disk entry that path reads the base via the public readFile(), which always requests unencrypted data, so RESTORE of an encrypted table from an incremental backup with fsync_after_insert=1 failed with CANNOT_RESTORE_TO_NONENCRYPTED_DISK and left the table empty. Fix: delegate full-base entries to the base backup and forward sync to it (the base is itself a BackupImpl that honours sync and reads its own encrypted entries), preserving durability without the unencrypted read path.

Local verification on the rebuilt binary:

  • encrypted incremental restore: RESTORED, 1000 rows / sum 499500, CHECK TABLE=1 (was CANNOT_RESTORE_TO_NONENCRYPTED_DISK before);
  • plain fsync_after_insert=1: FileSync=15 >= 9 files in part (durability preserved);
  • plain fsync_after_insert=0: FileSync=2 < 9 (correctly gated, no regression).

Comment thread src/Backups/BackupImpl.cpp Resolved
groeneai and others added 2 commits July 22, 2026 15:27
The getBaseBackup()->copyFileToDisk(..., sync) branch was previously untested.
It restores files that come entirely from the base backup, and it already
regressed once during this PR (encrypted entries threw
CANNOT_RESTORE_TO_NONENCRYPTED_DISK). Add an encrypted MergeTree case that
takes a full backup, an unchanged incremental backup, and restores the
incremental with fsync_after_insert = 1, asserting the base-backup files are
fsynced.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
The encrypted incremental restore case creates a table on an inline
disk(type = encrypted, ...). The encrypted disk type is registered only
under USE_SSL (registerDisks.cpp), and the Fast test build is compiled
without SSL, so the CREATE TABLE fails there with
UNKNOWN_ELEMENT_IN_CONFIG ("unknown disk type: encrypted"). Exclude the
test from the Fast test job, matching the other encrypted-disk stateless
tests (03801, 03820). No effect on the full Linux stateless runs where
the fix and both directions are already exercised.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@pamarcos pamarcos self-assigned this Jul 22, 2026
@pamarcos

Copy link
Copy Markdown
Member

Feedback from GPT-5.6 Sol:

I found two remaining implementation gaps and one test-evidence gap at 3e2d2c63:

  1. Blocker: the Cloud object-key path drops the new sync request. In BackupImpl::copyFileToDisk, lines 993-996 dispatch entries with an object key to copyFileToDiskByObjectKey without forwarding sync. This is reachable when a lightweight snapshot containing object-key entries is restored into an existing empty local MergeTree, for example with RESTORE TABLE source AS local_target ... SETTINGS allow_different_table_def=1. MergeTreeData computes fsync_files = true for the local target, but the object-key dispatch discards it, and the Cloud helper's current paths finalize without syncing. The original acknowledged-restore durability hole therefore remains in this supported path.

    Suggested fix: pass sync into copyFileToDiskByObjectKey; when it is true, bypass optimized copies that expose no destination buffer, copy through WriteBufferFromFileBase, then call finalize and sync. Please add a Cloud regression restoring a lightweight remote snapshot into a local target.

  2. Major: zero-byte entries bypass sync. Lines 1007-1017 return after createFile, before the new sync logic. Required zero-byte part files are valid, for example arr.bin in a wide part whose Array(UInt32) values are all empty. INSERT does call MergeTreeWriterStream::sync for these empty streams, so RESTORE still does not provide the promised INSERT parity. The practical risk is reduced when fsync_part_directory=1, but the new IBackup contract is still violated.

    Suggested fix: create zero-sized destinations through a live write buffer and call finalize followed by sync; add an empty-array case to the regression test.

  3. The test does not prove that all restored files were synced. system.parts.files is part->checksums.files.size(), not the number of physical files copied by restore; it excludes files such as checksums.txt and columns.txt. For this fixture it reports 9 while restore copies 13 files. Since the query also records roughly two unrelated FileSync events, syncing only seven copied files can satisfy FileSync >= 9. Please compare the on/off FileSync delta with the actual number of files traversed by restore, including a zero-byte file.

The existing local_blob_storage thread is not a PR regression: the author's rebuttal is correct because the INSERT sync currently stops at ForkWriteBuffer too.

Finally, because the reported impact is data loss after an acknowledged operation, the changelog category should be Critical Bug Fix (crash, data loss, RBAC), not Bug Fix.

…ied file count

Address review on ClickHouse#111378 (RESTORE fsync durability):

- Object-key (lightweight snapshot) entries dropped the sync request: the
  copyFileToDisk(String) dispatch forwarded to the object-key copy without
  sync, so restoring object-key entries into a local target with
  fsync_after_insert reintroduced the durability hole. Route the sync case
  through a live write buffer + finalize + sync via a new
  copyObjectKeyEntryToDiskSynced helper (defined unconditionally so it is
  type-checked in every build; only reachable in the cloud build). The helper
  mirrors the generic copy path's encryption handling: it rejects an encrypted
  entry restored to a non-encrypted disk and uses writeEncryptedFile for
  encrypted-by-disk entries so their bytes are not re-encrypted.
- Zero-byte entries returned after createFile, before the sync logic. A
  required empty part file (e.g. the .bin of an all-empty Array column) is
  fsynced by INSERT, so create it through a live buffer + finalize + sync
  when sync is requested, restoring INSERT parity.
- Strengthen 04550: add an empty Array(UInt32) column (zero-byte .bin), and
  assert the on/off FileSync delta covers the number of files RESTORE
  actually copies (physical files minus the version-metadata files RESTORE
  skips), instead of comparing against system.parts.files.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

Thanks, all three addressed in 9e5af08.

  1. Object-key path: copyFileToDisk(String) now routes the sync case to a new copyObjectKeyEntryToDiskSynced, which copies the entry through a live WriteBufferFromFileBase, then finalize + sync. It mirrors the generic path's encryption handling (rejects an encrypted-by-disk entry restored to a non-encrypted disk with CANNOT_RESTORE_TO_NONENCRYPTED_DISK, and uses writeEncryptedFile for encrypted-by-disk entries so their bytes are not re-encrypted). The helper is defined unconditionally so it type-checks in every build; it only touches OSS-visible primitives (readFileByObjectKey, lightweight_snapshot_file_infos) and does not change the private copyFileToDiskByObjectKey signature. The runtime path is cloud-only (object keys are never present in OSS builds), so the Cloud regression restoring a lightweight remote snapshot into a local target belongs in the private suite; I can add it there if you point me at the right test dir.

  2. Zero-byte entries: the size == 0 / Rewrite branch now, when sync is requested, creates the destination through a live buffer + finalize + sync instead of createFile. Added an empty Array(UInt32) column to the test so arr.bin is a required zero-byte file (verified it is exercised, and that INSERT fsyncs it too).

  3. Test: it now asserts the on/off FileSync delta >= the number of files RESTORE actually copies, computed as the physical files in the part minus the version-metadata files RESTORE skips (txn_version.txt[.tmp], metadata_version.txt), rather than system.parts.files. For the fixture that is 17 copied files; the fix gives delta 17 (FileSync 19 on, 2 off), and dropping either the object-key/zero-byte sync makes the delta fall short. Confirmed both directions on Build-ID-distinct binaries: fails on the pre-fix binary (delta 0 for the zero-byte gap), passes on the fix.

Agree the impact is data loss after an acknowledged operation; switched the changelog category to Critical Bug Fix.

@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review - adjudication log (click to expand)

Pre-publication review of the resulting code by an independent model (engine: codex; 1 finding; bounded: 1 full pass + 1 fix round).

# Sev Finding Verdict Evidence / action
1 ❌ The synced object-key path (copyObjectKeyEntryToDiskSynced) used writeFile unconditionally, ignoring encrypted_by_disk - on an encrypted destination it would re-encrypt ciphertext; on a plain destination it would write ciphertext instead of rejecting the restore. AGREE Confirmed BackupFileInfo retains encrypted_by_disk for object-key entries (set in makeBackupFileInfo, serialized/parsed in BackupImpl). Fixed the helper to reject encrypted -> non-encrypted disk (CANNOT_RESTORE_TO_NONENCRYPTED_DISK) and select writeEncryptedFile for encrypted-by-disk entries, mirroring the generic copy path. Re-verified: rebuilt, 20/20 test pass incl. the encrypted incremental case.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per finding.

@clickhouse-gh clickhouse-gh Bot added pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! and removed pr-bugfix Pull request with bugfix, not backported by default labels Jul 22, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 23, 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: 43/88 (48.86%) · Uncovered code

Full report · Diff report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 9e5af08

Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
— no failed checks on this commit —

CI is fully finished on this commit with zero failing checks.

Session id: cron:our-pr-ci-monitor:20260729-043000

@clickhouse-gh

clickhouse-gh Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

🔴 AI verdict: degradation — 1 query(s) regressed out of 36 analysed

This PR only changes BACKUP/RESTORE fsync durability (BackupImpl copyFileToDisk gains a sync path, restorePartFromBackup fsyncs restored part files); it does not touch the SELECT query-execution hot path any ClickBench query exercises. Q4 (-10.5%) and Q15 (-11.6%) are consistent improvements that correctly land inside master's current variance band, and Q30's flagged +17.4% is off-path with a median still inside its band, so it is downgraded to not_sure. Q23's x2.1 slower is a large, consistent delta that the deterministic trust override locks in place, but because nothing here touches that query's path it is almost certainly environmental - re-run before treating it as a real regression.

clickbench

🔴 1 regressed · ⚠️ 1 inconclusive

Flagged queries (2 of 43)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
🔴 23 regression 78 167 ×2.1 slower <0.0001 Large, consistent x2.1 slower delta, so the deterministic override locks the verdict. This PR only touches backup/restore, not this SELECT path, so re-run to rule out an environmental cause.
⚠️ 30 not_sure 268 314 +17.4% <0.0001 The PR only changes backup/restore fsync durability, which this SELECT never executes, and median 314.5 sits inside master's band [250,334]. The +17.4% reads as run-to-run variance.

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: 70d6b9c2-db32-400e-9f67-8ed94ed2ebcf
  • MIRAI run: e0e810b0-f268-42f8-9601-36c576b29c28
  • PR check IDs:
    • clickbench_1279710_1785611732
    • clickbench_1279723_1785611733
    • clickbench_1279729_1785611733
    • tpch_adapted_1_official_1279747_1785611733
    • tpch_adapted_1_official_1279766_1785611732
    • tpch_adapted_1_official_1279780_1785611733

@alexey-milovidov

Copy link
Copy Markdown
Member

@pamarcos

Feedback from GPT-5.6 Sol:

What does it mean? Did you review this PR? Is it approved?

@alexey-milovidov alexey-milovidov self-assigned this Aug 17, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 17, 2026
Merged via the queue into ClickHouse:master with commit 9813c63 Aug 17, 2026
179 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Aug 17, 2026
@robot-ch-test-poll robot-ch-test-poll added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Aug 17, 2026
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 17, 2026
clickhouse-gh Bot added a commit that referenced this pull request Aug 17, 2026
Backport #111378 to 26.7: Fsync restored part files on RESTORE to survive power loss
clickhouse-gh Bot pushed a commit that referenced this pull request Aug 17, 2026
clickhouse-gh Bot added a commit that referenced this pull request Aug 17, 2026
Backport #111378 to 26.6: Fsync restored part files on RESTORE to survive power loss
alexey-milovidov pushed a commit that referenced this pull request Aug 18, 2026
…e_fsync_after_insert

The test read the `files` column of `system.parts` to size the
encrypted-incremental-restore fsync assertion. That column was added by
476e9fc in January, after 25.8 forked, so the automated 25.8
backport of #111378 (#115088) fails at runtime with UNKNOWN_IDENTIFIER
even though the cherry-pick applied cleanly and the script is
byte-identical to master. The empty shell variable then also fails the
`{files:UInt64}` parameter binding.

The count the assertion wants is how many files RESTORE copies and must
therefore fsync. The test already measures exactly that for its first
table via `SELECT path FROM system.parts` plus `find`, so feed the
encrypted arm the same count and drop the column read. The two tables
have identical schema, data and part-layout settings, so their parts hold
the same file set; the physical count is also larger than the checksums
map (18 vs 14 on master), since it covers checksums.txt, columns.txt and
the zero-byte arr.bin, so the assertion gets stronger rather than weaker.

Validated on the official 25.8 binary: the old test reproduces both
errors, the new one runs to completion. On master the encrypted restore
performs 20 FileSync events against a required 18, the two arms' part
file lists are identical on both branches (18 files on master, 15 on
25.8), disabling fsync_after_insert still fails the test, and 50/50 runs
pass with randomized settings.

Related: #111378
Related: #115088

Co-Authored-By: Claude Fable 5 <[email protected]>
(cherry picked from commit fd8fc0c)
alexey-milovidov added a commit that referenced this pull request Aug 18, 2026
Backport #111378 to 26.5: Fsync restored part files on RESTORE to survive power loss
alexey-milovidov added a commit that referenced this pull request Aug 18, 2026
Backport #111378 to 26.3: Fsync restored part files on RESTORE to survive power loss
pull Bot pushed a commit to SINHASantos/ClickHouse that referenced this pull request Aug 18, 2026
…e_fsync_after_insert

The test read the `files` column of `system.parts` to size the
encrypted-incremental-restore fsync assertion. That column was added by
476e9fc in January, after 25.8 forked, so the automated 25.8
backport of ClickHouse#111378 (ClickHouse#115088) fails at runtime with UNKNOWN_IDENTIFIER
even though the cherry-pick applied cleanly and the script is
byte-identical to master. The empty shell variable then also fails the
`{files:UInt64}` parameter binding.

The count the assertion wants is how many files RESTORE copies and must
therefore fsync. The test already measures exactly that for its first
table via `SELECT path FROM system.parts` plus `find`, so feed the
encrypted arm the same count and drop the column read. The two tables
have identical schema, data and part-layout settings, so their parts hold
the same file set; the physical count is also larger than the checksums
map (18 vs 14 on master), since it covers checksums.txt, columns.txt and
the zero-byte arr.bin, so the assertion gets stronger rather than weaker.

Validated on the official 25.8 binary: the old test reproduces both
errors, the new one runs to completion. On master the encrypted restore
performs 20 FileSync events against a required 18, the two arms' part
file lists are identical on both branches (18 files on master, 15 on
25.8), disabling fsync_after_insert still fails the test, and 50/50 runs
pass with randomized settings.

Related: ClickHouse#111378
Related: ClickHouse#115088

Co-Authored-By: Claude Fable 5 <[email protected]>
PedroTadim added a commit that referenced this pull request Aug 18, 2026
Backport #111378 to 25.8: Fsync restored part files on RESTORE to survive power loss
PedroTadim pushed a commit that referenced this pull request Aug 18, 2026
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Aug 24, 2026
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Aug 24, 2026
@blau-ai blau-ai mentioned this pull request Sep 9, 2026
15 of 30 tasks
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-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR 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.

RESTORE never fsyncs the restored part files: an acknowledged restore loses all data on power loss

7 participants