Repository navigation
Conversation
BackupImpl::checkLockFile verifies that the '.lock' file at the backup destination still holds this backup's UUID. It reads back a file the same process wrote milliseconds earlier, through the ordinary read path, so a path-keyed read cache is free to answer it. Both local read caches are keyed in a way that cannot see the rewrite. MMappedFileCache::hash keys on path + offset + length only, and a UUID text is always 36 bytes, so a lock file recreated at the same path after a failed attempt's cleanup removed it hits the previous mapping. The userspace page cache keys on path plus a file_version that is never populated for a local disk, which violates the assumption stated in PageCache.h. The verification then compares against the previous attempt's bytes and a legitimate retry aborts with BACKUP_ALREADY_EXISTS although no concurrent backup exists. ReadSettings::disableCaches is documented as disabling every read-side cache but did not clear the mmap fields, so extend it, and call it on a copy of the read settings in the two local-filesystem writer readFile overrides. BackupIO_Default states in source that readFile exists only to implement fileContentsEqual, so this cannot affect data copying or restore. The S3, Azure, Memory and Null writers have no local mmap or page-cache stage. The other disableCaches caller, checkDataPart, is unaffected: it starts from a default-constructed ReadSettings whose mmap fields are already cleared and additionally forces pread. Both carriers were reproduced against pristine master and are fixed: use_reader_executor = 1 with local_filesystem_read_method = 'mmap' and min_bytes_to_use_mmap_io = 1, and use_page_cache_for_local_disks = 1 on a server with a non-zero page_cache_max_size.
…ile read The fix in the previous commit closes two independent carriers of the same defect: a backup lock-file verification read served from a stale cache entry. Only the mmap carrier was pinned by a test, so the userspace page-cache carrier named in the changelog had no coverage, and reverting the two readFile call sites alone left every test green. The new test drives the page-cache carrier directly. It runs one clickhouse-local process with a page cache configured and local_filesystem_read_method = pread, so mmap cannot be involved: a fault-injected first attempt removes its lock file, and the retry must observe the lock file it just wrote rather than the contents cached for the previous attempt. clickhouse-local is required because page_cache_max_size is a server setting that defaults to 0 and no file under tests/config/ sets it. A Disk(...) destination is also required: BackupWriterFile reads through createReadBufferFromFileBase directly, bypassing the pipeline that owns the page-cache stage, so a File(...) destination cannot reach this carrier at all. The test asserts PageCacheBytes > 0 as well as the backup outcome, so a run in which the page cache was never populated fails loudly instead of passing for want of a cache. Disabling use_page_cache_for_local_disks makes the fixture pass on an unfixed binary, which confirms the setting rather than the fixture is what discriminates. Each half of the fix is now covered by its own arm: reverting only the ReadSettings change leaves this test passing and the mmap test failing, and reverting only the two call sites fails both.
… probe The regression test's arming assertion measured CreatedReadBufferMMap on a plain MergeTree read. Under --s3-storage and --azure-blob-storage the default MergeTree policy is object storage, where no read can create an mmap buffer, so that assertion printed 0 against a reference of 1 in 12 of the 22 stateless configs, including the amd_tsan s3-storage config the reported failure came from. It also measured a different query from the one under test. Assert ProfileEvents['ReaderExecutorSourceRequests'] on the retry's own query_log row instead. Only LocalSourceReader::open passes a file size down to createReadBufferFromFileBase, so that count is what makes a 36-byte lock file mmap-eligible at all, and it observes the backups destination disk, which is type=local in every stateless config. Measured non-zero on both binaries (base 1, fix 10), so it arms the test rather than restating its outcome; setting use_reader_executor=0 makes it read 0 and the test fails. Verified with an object-storage default MergeTree policy, where the deleted probe printed 0 and the new assertion passes. Both mutants still redden the outcome line. 04763 and 04764 each pass 50 of 50 randomized runs, 80 of 80 together.
04763's arming assertion read ProfileEvents['ReaderExecutorSourceRequests'] on the retry's query_log row. That counter is a per-query aggregate, and the retry performs source-table and metadata reads besides the lock read, so on the fixed arm the assertion is satisfied by a superset of the read it names. A binary in which only the lock read fell back to the legacy path, while the retry's other reads stayed executor-served, would leave the line green and silently stop arming the mmap carrier. Scope it to the lock read instead: LocalSourceReader::open logs the path and size of every executor-served local read, and it is the sole local read path that passes a file size down to createReadBufferFromFileBase, which is what makes a 36-byte lock file mmap-eligible. Asserting that trace line for the '.lock' path, scoped to the retry's own query_id, pins exactly the property the comment claims. Measured with a mutant that disables the executor for the writer's readFile and nothing else: the retry still reports BACKUP_CREATED and the old assertion still reads 1 from seven unrelated executor-served reads, while the new one reads 0 and the test fails. With use_reader_executor = 0 the new assertion reads 0 and with the shipped settings it reads 1, on both values of the randomized async logger. SYSTEM FLUSH LOGS text_log drains the async log channel before flushing, so the assertion is independent of which logger CI randomizes. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Internal second-model review (4 rounds, all findings adjudicated)I review my own PRs with an independent model before publishing, then adjudicate ❌ Blockers and majors, fixed
|
Pre-PR validation gate (click to expand)
Each half of the change is covered by its own arm, re-measured on the shipped files with one server |
|
cc @pamarcos @kssenii, could you review this? |
|
Workflow [PR], commit [58c60da] Summary: ✅
AI ReviewSummaryReviewed #113617 at Missing context / blind spots
Final VerdictStatus: ✅ Approve. |
CI finish ledger — 74a87a3Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
Not caused by this PR: the diff touches The remaining 174 check-runs are 157 success and 17 skipped, with Session id: cron:our-pr-ci-monitor:20260806-143000 |
The test arms the server-global fail point backup_fail_before_writing_metadata. The failpoint_tests_are_isolated style rule on master now requires every stateless test that arms a server fail point to carry both no-parallel and no-fasttest, so the PR would fail the Style check on its next run. 04764 arms the same fail point only inside its own clickhouse-local process, which the rule exempts, so it is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@CheSema I hit an issue from randomizing |
With it on, two bugs fail tests: - `use_reader_executor` with `local_filesystem_read_method = 'mmap'` reads stale bytes of a rewritten same-size local file (`05055_backup_lock_file_non_atomic_backend`); fix in #113617. - `reader_executor_use_long_connections` sizes the held GET from the read position but opens it at the fetch start, so a fetch from a cache segment's committed front ends before the position: `ReaderExecutor: source ended` (`04513`, `05182`); fixed by #125606. `reader_executor_use_long_connections` and its dependency on `use_reader_executor` go with it. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=106734&sha=09174651b0bd517f1371eb39e39355bb7d243811&name_0=PR PR: #106734 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The Style check now requires an `event_time` comparison in every test that reads `system.text_log` (234b980): the table is large on CI servers and a scan bounded only by `query_id` can exceed `max_rows_to_read` of the test profile. Add the usual `event_date >= yesterday() AND event_time >= now() - 600` bound, which prunes by the table's sorting key and keeps the lock-read trace the assertion looks for (it is logged seconds earlier). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Slowest function optimization changes (ThinLTO)Median per-function time ratio to the master baseline:
Compile time of recompiled translation units9 translation units recompiled, 13 s compile time in total, 9 of them have a recent master baseline. |
Related: #112945
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
BACKUPfailing withA concurrent backup writing to the same destination ... (BACKUP_ALREADY_EXISTS)when no concurrent backup exists. Retrying a backup to a destination whose previous failed attempt had just been cleaned up could read the removed attempt's.lockcontents from a read cache instead of the freshly written file. Affects local-disk destinations only with a non-default local read cache: the page cache (page_cache_max_size,use_page_cache_for_local_disks,local_filesystem_read_method = 'pread') or the mmap cache (use_reader_executor,local_filesystem_read_method = 'mmap', non-zeromin_bytes_to_use_mmap_io).Description
BackupImpl::checkLockFileverifies that the.lockfile at the destination still holds this backup's UUID. It reads back a file this process just wrote, through the ordinary read path, so a path-keyed read cache can answer it.Neither local read cache can see the rewrite.
MMappedFileCache::hashkeys on path + offset + length only, and a UUID text is always 36 bytes, so a lock file recreated at the same path after cleanup removed it hits the previous mapping. The page cache keys on path plus afile_versionnever populated for a local disk, violating the assumptionPageCache.hdocuments. The verification then compares against the previous attempt's bytes, and a legitimate retry throws before writing anything.ReadSettings::disableCachesis documented as disabling every read-side cache but did not clear the mmap fields, so this extends it and calls it on a settings copy in the two local-filesystem writerreadFileoverrides.BackupIO_Defaultstates in source that thisreadFileexists only to implementfileContentsEqual, so data copying and restore are unaffected; the S3, Azure, Memory and Null writers have no local mmap or page-cache stage. The only otherdisableCachescaller,checkDataPart, already forcespreadon default-constructed settings.Both carriers were reproduced against pristine master and fixed, deterministically over three runs each; for the mmap carrier the failing read's own
ProfileEventsshowMMappedFileCacheHits = 1,MMappedFileCacheMisses = 0. There is one test per carrier,04763and04764. Reverting only the two call sites breaks both carriers; reverting only theReadSettingschange breaks the mmap one, so each hunk is load-bearing and covered. Thebackupfamily's failure set is byte-identical before and after. No setting default or format change, so noSettingsChangesHistory.cppentry.#112824 conflicts textually on the two
readFilelines it wraps for Windows paths; resolving it is mechanical.Workflow [PR]
Sync PR [sync-upstream/pr/113617]
Version info
26.11.1.2525-master(included in26.11and later)