Repository navigation
Log the initial disk check period before scheduling the disk check task - #110783
Conversation
`DiskLocalCheckThread::startup` scheduled the periodic check task via
`task->activateAndSchedule()` and only afterwards read `check_period`
(a `DynamicDelay`, documented "Not thread safe") on the main thread to
format the "Disk check ... started with period ..." log message. Once
the task is scheduled, `run` may start executing on a `BackgroundSchedulePool`
thread and write `check_period` (`rotateToMin`/`up`) concurrently with that
read, so the two race.
ThreadSanitizer reports this as a data race between the main-thread read in
`DynamicDelay::getCurrentDelay` (from `startup`) and the pool-thread write in
`DynamicDelay::rotateToMin` (from `run`), which aborts server startup under
the `Stateless tests (amd_tsan, flaky check)` job:
WARNING: ThreadSanitizer: data race
Write ... DB::DynamicDelay::rotateToMin() src/Common/DynamicDelay.cpp:69
DB::DiskLocalCheckThread::run() src/Disks/DiskLocalCheckThread.cpp:55
Previous read ... DB::DynamicDelay::getCurrentDelay() src/Common/DynamicDelay.cpp:49
DB::DiskLocalCheckThread::startup() src/Disks/DiskLocalCheckThread.cpp:46
Read the delay for the log message before scheduling the task. That orders
the main-thread read before the task can run, and the task thereafter runs
only on the schedule pool (serialized with itself) until `deactivate` in
`shutdown`/the destructor waits for it, so `check_period` has a single
accessor at any time. The logged value is unchanged (the initially
configured period).
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Workflow [PR], commit [7911b2e] Summary: ✅
AI ReviewSummaryThis PR now just reorders Final Verdict
|
|
The sole CI failure — The startup data race this PR fixes is validated by this run: all |
…hread-startup-race
…hread-startup-race
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 2/2 (100.00%) · Uncovered code |
Description
Log the initially configured disk check period before scheduling the periodic task in
DiskLocalCheckThread::startup, instead of after it.History and current status of this change. This PR was originally opened as a fix for a ThreadSanitizer data race:
startupcalledtask->activateAndSchedule()first and only afterwards readcheck_period(aDynamicDelay, at that time documented as "Not thread safe") on the main thread to format theDisk check ... started with period ...message. Once scheduled,runcould writecheck_period(rotateToMin/up) on aBackgroundSchedulePoolthread concurrently with that read. Because the abort happened at server startup, it surfaced as aStart ClickHouse Server/Server diedfailure in theStateless tests (amd_tsan, flaky check)job:Observed in CI on PR #109369: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=109369&sha=7b341f536dbac2c97b55196c58066093ef980bd3&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20flaky%20check%29
Meanwhile #110817 made
DynamicDelayitself thread safe (all accessors take a mutex, the class comment flipped from "Not thread safe" to "Thread safe"), which removes that race at its source. So on the current merge result this diff no longer fixes a data race — it is a two-line ordering cleanup: the log message reports the initial period, so reading it before the task can start is the natural order and keeps the read out of the concurrency window regardless ofDynamicDelay's internal synchronization. The logged value is unchanged. Merge it as a small cleanup or close it — it is no longer load-bearing.Related: #110817
Related: #110773
Changelog category (leave one):
Version info
26.8.1.203(included in26.8and later)