Repository navigation
Do not log TABLE_IS_READ_ONLY at error level in ServerAsynchronousMetrics - #104981
hanfei1991 merged 4 commits into
Conversation
…rics The async metrics thread reads `is_readonly` from `getStatus(...)` and then calls `getReplicaDelays(...)`, which calls `assertNotReadonly` internally. Between those two operations the table can transition into readonly state (e.g. due to Keeper churn, replica restart, or shutdown). When that race hits, `getReplicaDelays` throws `TABLE_IS_READ_ONLY` and the previously unconditional `tryLogCurrentException` writes an `<Error>` line. With the client default `--send_logs_level=warning`, that line gets sent to the client's stderr and `clickhouse-test` marks any parallel test as `having stderror`. The race is benign for a background metrics collector. Inspect the current exception code and log only `TABLE_IS_READ_ONLY` at debug level, keeping all other exceptions at error. Source of the parallel stderr-leak observed in CI is a churning RMT test such as `01671_ddl_hang_timeout_long`, which rapidly creates and drops ReplicatedMergeTree replicas and routinely flips `is_readonly` while the async metrics thread is mid-update. The leaked stderr previously caused unrelated parallel tests to fail with `having stderror` (e.g. `04204_mergetree_arena_routes_writes`, reported in ClickHouse#104912). Closes ClickHouse#104912
|
cc @Algunenano @azat — could you review this? It demotes the |
Pre-PR validation gateSelf-review per TASK.md Phase 4 Step 9 / fix-ci-failure SKILL.md.
|
|
Workflow [PR], commit [c7a3a43] Summary: ✅ AI ReviewSummaryThis PR narrows logging severity in Final Verdict
|
LLVM Coverage Report
Changed lines: 14.29% (1/7) | lost baseline coverage: 1 line(s) · Uncovered code |
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.
Description
ServerAsynchronousMetrics::updateImplcollects replica delay metrics from everyReplicatedMergeTreetable on a background thread. It first readsis_readonlyviagetStatus(...)and, only if the table is not readonly, callsgetReplicaDelays(...)to compute the actual delay.getReplicaDelayscallsassertNotReadonlyinternally, which throwsTABLE_IS_READ_ONLYwhen the table is in readonly mode (replica path or static storage).Between the
if (!status.is_readonly)check and thegetReplicaDelays(...)call, the table can transition into readonly state — for example because of Keeper churn, replica restart, shutdown, or rapidCREATE/DROPcycles in stress tests like01671_ddl_hang_timeout_long. When that race hits,tryLogCurrentExceptionwrites a<Error>line. With the test default--send_logs_level=warning, the line is forwarded to the client's stderr, whichclickhouse-testinterprets ashaving stderrorand fails any test that happened to be running in parallel — even when the parallel test has nothing to do with the readonly table.This is the reported failure mode of #104912, where
04204_mergetree_arena_routes_writeswas flagged as flaky because01671_ddl_hang_timeout_longrunning in parallel created/droppedReplicatedMergeTreereplicas while the async metrics thread was mid-update.The race is benign for a background metrics collector. The fix inspects the current exception code and demotes only
TABLE_IS_READ_ONLYtoLogsLevel::debug. Every other exception keeps itsLogsLevel::errorlevel, so genuine problems are still surfaced.Why not a regression test: the race window is microseconds wide and the failure rate in CI is ~1 occurrence per 30 days even with the stress test 01671 running constantly. A deterministic local reproducer would require explicit failpoints between
getStatusandgetReplicaDelays, which would be more invasive than the fix itself. The change is purely log-level: no functional behavior is altered.Reported failure example (from #104912):
Closes #104912
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Stop logging
TABLE_IS_READ_ONLYat error level from the background async metrics thread when a replicated table races into readonly state duringgetReplicaDelays. The condition is expected during shutdown / replica restart / Keeper churn and previously leaked into client stderr, causing unrelated parallel tests to fail withhaving stderror.Documentation entry for user-facing changes
Version info
26.5.1.830