Repository navigation
Do not record the async-metrics readonly checks in system.errors - #119448
alexey-milovidov merged 3 commits into
Conversation
ServerAsynchronousMetrics::updateImpl reads `status.is_readonly` and then calls `getReplicaDelays`, whose first statement is `assertNotReadonly()`. A concurrent DROP/RESTART flips `is_readonly` in between (ReplicatedMergeTreeRestartingThread:: setReadonly), so the call throws TABLE_IS_READ_ONLY before doing any work. The Exception constructor increments the error counter, so the code lands in system.errors and system.error_log even though no user action caused it and the background thread simply skips the table. PR ClickHouse#104981 identified the same race but only demoted the log level from error to debug, leaving the system.errors accounting in place. This completes that change by wrapping the speculative call in Exception::SuppressErrorCodesScope, which exists for exactly this shape. The scope suppresses every code constructed on the thread, and getReplicaDelays also does Keeper I/O after the readonly check (getZooKeeper, getChildren, tryGet), whose Coordination::Exception is a DB::Exception. Those failures are real and must stay visible, so the handler re-records every code except TABLE_IS_READ_ONLY via recordToSystemErrors(). Log-level selection from ClickHouse#104981 is unchanged. The other getReplicaDelays caller, ReplicasStatusHandler, has the same window and is deliberately left alone: it serves an explicit /replicas_status request, so its errors belong in system.errors. Verified with a temporary probe widening the window, over 12 forced flips per binary: the TABLE_IS_READ_ONLY counter moves by 12 on the pre-fix binary and stays 0 on the fixed one, while the debug line naming this call site appears 12 times on both, so the race still happens and is still reported. With Keeper blocked, KEEPER_EXCEPTION rises by 8 on both binaries.
Internal second-model review (click to expand)Two independent reviews of this change (a cold read plus a separate model pass) agreed on one ❌ A unit test that could not fail without the fix was removed. An earlier revision added
💡 Session id: cron:clickhouse-review-slot-8:20260911-121300 |
|
cc @antonio2368 @pamarcos, could you review this? The async-metrics thread reads |
|
Workflow [PR], commit [3319b06] Summary: ✅
AI ReviewSummaryThe change suppresses expected readonly exceptions from asynchronous replication-delay collection, skips static-storage replicas, and preserves accounting and error logging for other exceptions, including Keeper failures. No remaining findings at Missing context / blind spots
Final Verdict✅ Approve. No additional changes requested. |
`status.is_readonly` mirrors only the transient atomic flag, but the callee's `assertNotReadonly()` checks static storage first and throws TABLE_IS_PERMANENTLY_READ_ONLY for a replica attached on a read-only or write-once disk. So the previous guard let that replica into the branch on every tick. Unlike the DROP/RESTART flip this is not a race and it never stops: the restarting thread clears `is_readonly` after a successful startup, while `isStaticStorage()` stays true for the table's lifetime. The result on any server at the default 1 s metrics period is a TABLE_IS_PERMANENTLY_READ_ONLY row in system.errors plus an error-level "Cannot get replica delay" line every second, with nothing having failed. Only TABLE_IS_READ_ONLY was demoted and excluded, so the permanent code was both counted and logged at error level. Ask for both states up front instead: `isTableReadOnly()` is `is_readonly || isStaticStorage()`, which is exactly what `assertNotReadonly()` enforces, and is what the only other `getReplicaDelays` caller, ReplicasStatusHandler, already guards with. The handler now also treats the permanent code as benign, so the narrow window between the check and the call is covered for both codes; Keeper failures from the same call are still recorded and still logged at error level. Reported by clickhouse-gh[bot] in ClickHouse#119448 (comment) Verified on a debug build, both directions. Fixture: a ReplicatedMergeTree on a local_blob_storage disk, restarted with read_only=true so the disk reports isReadOnly() and the policy becomes static; sampled over 20 s with system.replicas.is_readonly = 0, i.e. with the branch reachable. before "Cannot get replica delay" for that table: 21 lines, level Error system.errors[TABLE_IS_PERMANENTLY_READ_ONLY]: +61 after "Cannot get replica delay" for that table: 0 lines system.errors[TABLE_IS_PERMANENTLY_READ_ONLY]: +40 The 21-line difference is this call site, and 61 - 40 = 21 accounts for it exactly. The remaining 40 come from the replica's own queueUpdatingTask, mutationsFinalizingTask and mergeSelectingTask, which are a separate producer and are not touched here. Non-target check on the fixed binary, so the new predicate is not over-broad: a healthy replica with min_relative_delay_to_measure = 0 and Keeper's port blocked still logs this call site and still adds 11 to KEEPER_EXCEPTION/NO_ZOOKEEPER. Tables that should be measured are still measured, and real failures stay counted.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 21 s compile time in total, 7 of them have a recent master baseline. |
CI finish ledger - e555dbcEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose
Session id: cron:our-pr-ci-monitor:20260911-210037 |
Related: #118928, #111845
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Do not count a
ReplicatedMergeTreereplica's read-only state as an error insystem.errorsandsystem.error_logwhen the asynchronous metrics thread reads its replication delay. Previously a dropped or restarted replica recordedTABLE_IS_READ_ONLY, and a replica on static storage recordedTABLE_IS_PERMANENTLY_READ_ONLYand logged an error once perasynchronous_metrics_update_period_s, with no query having failed.Description
Requested by @ alexey-milovidov in #93111. Seen as
test_cancel_backup.py::test_cancel_restoreat:547(report);test_different_versions.py:105has the same producer. No open issue exists.ServerAsynchronousMetrics::updateImplguardsgetReplicaDelayswithstatus.is_readonly, but the callee starts withassertNotReadonly(), which rejects more than that flag, so it throws before doing any work in two ways:DROP TABLEorSYSTEM RESTART REPLICAflipsis_readonlyafter the check:TABLE_IS_READ_ONLY;assertNotReadonly()also checks static storage, which that flag does not reflect, so a replica on a read-only or write-once disk getsTABLE_IS_PERMANENTLY_READ_ONLY. That one is not a race and never stops: the restarting thread clearsis_readonlyafter startup while the disk stays static, so it fired on every tick, at error level, only the transient code having been demoted.The counter is incremented in the exception constructor, before any
catchruns, and is cumulative.#104981 named case 1 but only demoted its log level. This completes it: the call is wrapped in
Exception::SuppressErrorCodesScope, the guard now usesisTableReadOnly()(is_readonly || isStaticStorage(), whatassertNotReadonly()enforces and whatReplicasStatusHandleralready uses), and the handler re-records every code except the two readonly ones, so Keeper failures stay visible.No test ships. Case 1 has no failpoint; case 2 is deterministic, but its fixture needs a static-storage
ReplicatedMergeTree, which in a stateless test means a deprecatedOrdinarydatabase plus s3_plain, as in02980_s3_plain_DROP_TABLE_ReplicatedMergeTree.sh. I could not validate that locally and would rather not add an unvalidated test here; happy to add one if wanted.Validation, both directions on a debug build
Case 1, a probe widening the window identically on both binaries, 12 forced flips:
system.errors[TABLE_IS_READ_ONLY]moves by +12 before the fix and by 0 after, while theCannot get replica delayline for this call site appears 12 times on both, so the race stillhappens and is still reported. With Keeper's port blocked,
KEEPER_EXCEPTIONrises by +8 on both.Case 2, a
ReplicatedMergeTreerestarted onto aread_onlydisk so the policy is static,sampled over 20 s with
system.replicas.is_readonly = 0, i.e. with the branch reachable:the
Cannot get replica delayline for that table appears 21 times at error level before the fixand 0 times after.
system.errors[TABLE_IS_PERMANENTLY_READ_ONLY]moves by +61 and +40, the21 difference being this call site; the rest is the replica's own
queueUpdatingTask,mutationsFinalizingTaskandmergeSelectingTask, a separate producer not touched here.Not over-suppressed: after the fix, a healthy replica with
min_relative_delay_to_measure = 0and Keeper unreachable still logs this call site and still adds +11 to
KEEPER_EXCEPTION/NO_ZOOKEEPER, so tables that should be measured still are.test_different_versionspasses 50/50.Workflow [PR]
Sync PR [sync-upstream/pr/119448]
Version info
26.11.1.1428-master(included in26.11and later)