Repository navigation
Do not apply DROP fault injection to a refreshable view's cleanup DROP - #114622
alexey-milovidov merged 1 commit into
Conversation
`ignore_drop_queries_probability` exists to make a *user* `DROP TABLE` silently do
nothing (or become a `TRUNCATE`) so the stress suite exercises the case where the
table you asked to drop is still there. It must only ever hit statements the user
issued.
`StorageMaterializedView::dropTempTable` is engine-internal cleanup: after a
refreshable materialized view swaps in a freshly built target, it drops the
rotated-out old one. It ran `InterpreterDropQuery` on `refresh_context`, and
`createRefreshContext` never marks that context internal, so `secondary_query` was
false at the injection gate and the cleanup DROP was treated as a user DROP. The
gate's existing refreshable-view exemption does not cover this: that test inspects
the table *being dropped*, which here is the inner target rather than the view, so
the cast yields null. Both exits of `RefreshTask::executeRefreshUnlocked` are
affected, the successful one and the failure one.
When the injection fired, the rotated-out target survived under its internal
`.tmp.inner_id.<uuid>` name, still holding a full copy of the view's data, absent
from the view's metadata, unreferenced by anything that would reap it, and present
again after a restart. For a target that stores no data on disk the DROP was
rewritten to a TRUNCATE instead, leaving the same orphan minus its rows.
Carry the internal intent on the interpreter, mirroring the `internal` member
`InterpreterCreateQuery` already has, and set it only on this one DROP; the shared
`refresh_context` is left untouched. Marking that context instead is the smaller
diff and it is wrong: the publishing RENAME of the same refresh runs on it, and
`DatabaseReplicated::tryEnqueueReplicatedDDL` rejects a non-initial query unless the
interpreter also passes `flags.internal`, which neither the Rename nor the Drop
interpreter did. That asymmetry is why the equivalent one-liner was safe for the
CREATE OR REPLACE sites and is not safe here. Copying the context is worse still,
since a copy loses the parent table UUID, the DDL cancellation token and the
enqueue checks that a lagged replica needs to skip stale temp-table entries.
Passing `QueryFlags{ .internal = internal }` at the replicated enqueue is neutral
for every other DROP: `internal` defaults to false and all three `QueryFlags`
members default, so it equals the `{}` it replaces.
Requested by tiandiwonder as a follow-up to ClickHouse#114420, which established the same
invariant for the DROPs that CREATE OR REPLACE issues internally.
Internal second-model review (0 blockers, 0 majors)An independent cold review plus a second-model gate ran against this diff before it Cold review, independent of the implementation notes. The carrier list was
💡 Two nits withdrawn on measurement, recorded because the checking is the point. Test-liveness, checked rather than assumed. Reverting the fix reddens all three Also verified: no gitlink or submodule drift, no |
|
Workflow [PR], commit [59b8f0b] Summary: ✅
AI ReviewSummaryThis PR makes the cleanup Final VerdictNo findings. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 13/13 (100.00%) · Uncovered code |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-6:20260813-080400 |
|
cc @tuanpach @evillique, could you review this? A refreshable view's cleanup DROP of its rotated-out target was still subject to |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units12 translation units recompiled, 88 s compile time in total, 12 of them have a recent master baseline. |
CI finish ledger - 59b8f0bNo failures on this head. 177 jobs, 0 incomplete, 0 dropped, 159 OK, 18 skipped (each with a
The six Session id: cron:our-pr-ci-monitor:20260813-180000 |
aec8b1d
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a refreshable materialized view leaking its rotated-out target table when
ignore_drop_queries_probabilityis enabled. TheDROPa refresh issues to clean up the previous target is a step of the refresh, not aDROPthe user asked for, so the fault injection no longer applies to it.Description
Follow-up to #114420, requested by @ tiandiwonder in #114420 (comment).
ignore_drop_queries_probabilitymakes aDROP TABLEsilently do nothing (or become aTRUNCATE) so the stress suite exercises "the table you dropped is still there". It must only affectDROPs the user issued.Root cause. After a refresh swaps in a new target,
StorageMaterializedView::dropTempTabledrops the rotated-out one viaInterpreterDropQuery(drop_query, refresh_context).createRefreshContextnever marks that context internal, so the gate treated the cleanupDROPas a userDROP. Its existing refreshable-view exemption does not cover this: that test inspects the table being dropped, which here is the inner target, not the view. Both refresh exits are affected. When it fires, the old target survives as.tmp.inner_id.<uuid>still holding a full copy of the view's data, outside the view's metadata and surviving restart.The change.
InterpreterDropQuerygains aninternalmember mirroring the oneInterpreterCreateQueryalready has,dropTempTablesets it, and the sharedrefresh_contextis untouched. Marking that context instead would break the refresh outright in aReplicateddatabase: the publishingRENAMEruns on it, andDatabaseReplicatedrejects a non-initial query unless the interpreter also passesflags.internal, which neither the Rename nor the Drop interpreter did. That is why #114420's one-liner was safe there and is not here.QueryFlags{ .internal = internal }at the replicated enqueue is behaviour-neutral for every otherDROP, since all its members default to false. The interpreter's other policy branches (ON CLUSTERdispatch, access and dependency checks) deliberately keep applying.Validation. New test
04887_refreshable_mv_cleanup_drop_not_ignored: three positive arms (success path, failure path,Replicateddatabase) leak on master and are clean with the fix; a fourth asserts a genuine userDROPis still skipped. 50 randomized runs plus 50 withignore_drop_queries_probability=0.2were green, as were04247,04796,04218and04327.Version info
26.8.1.1485(included in26.8and later)