Repository navigation
Fix Files metadata is empty logical error on the object storage queue read path - #113695
Conversation
…ue read path
`StorageObjectStorageQueue::getTableMetadata` asserted that `files_metadata` is
never null, but three reachable states leave a still-addressable table with a
null handle:
* a concurrent `DROP`/`DETACH`: `InterpreterDropQuery` shuts the storage down
before it takes any exclusive lock, and for an Atomic database it takes none
at all, while a `SELECT` holds only `lockForShare`. `shutdown` then resets
the handle underneath a query that is still building its plan.
* a failed `startup`: the catalog entry is created first and never rolled back,
so the table stays in `system.tables` with the handle already reset.
* a failed `DROP`: `DatabaseAtomic::dropTableImpl` does fallible disk work
before detaching, so a failure there leaves the table attached and shut down.
Reaching the assertion aborts the server in debug and sanitizer builds, which is
how it surfaces as a stress-test failure. The handle was also a plain
`shared_ptr` with no synchronisation, unlike the twelve other members of that
class, and it was dereferenced unguarded on user-facing paths -- in
`waitForPathToBeProcessed` with no null check at all, which segfaulted.
Guard the handle with the class mutex and give every operation one snapshot that
it owns for its whole duration, so a handle observed non-null cannot become null
halfway through. `getTableMetadata` is removed rather than reimplemented on top
of the accessor: it returned a reference into the object the snapshot owns, so a
snapshot local to the accessor would leave that reference dangling. Each of its
seven callers now takes its own snapshot instead.
Where the state is legitimate, report `TABLE_IS_DROPPED` -- what `IStorage`
itself throws for this condition -- instead of a logical error. On the background
streaming path a null handle means the table is shutting down, so that path
returns rather than logging an error on every poll.
This makes such a table report a clear error. It does not make it usable again;
recovering it is a `DatabaseAtomic`/`InterpreterDropQuery` concern for every
engine and is out of scope here.
Closes ClickHouse#93009
Internal second-model review — 1 finding, adjudicated (click to expand)An independent cold review plus a second model reviewed this change before it was
|
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-42:20260806-102300 |
|
cc @kssenii @antonio2368, could you review this? |
|
Workflow [PR], commit [75906ad] Summary: ✅
AI ReviewSummaryThis PR fixes the Findings
Tests
Final VerdictLLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 160/182 (87.91%) · Uncovered code |
…test The concurrent-drop arm accepted a clean result as well as the error, so a run in which the SELECT completed before the DROP satisfied it. That outcome never reads the metadata after shutdown, so the arm passed against the unfixed server too, and a future planner change that stopped opening the window would have gone unnoticed while the test stayed green. Measured on this branch, three tests per cell, native pytest with per-arm binaries: test shape old assertion new assertion shipped race pass pass (30 races) SELECT finishes before DROP pass fail The second row is the mutant: with the window never entered, the old assertion passes and the new one fails with `assert 'TABLE_IS_DROPPED' in ''`. Requiring the error does not make the arm racy. The subquery sleeps 3 seconds and the DROP lands at 1.2 seconds, so the window is open by construction: 26 of 26 consecutive races returned TABLE_IS_DROPPED, including 6 with the DROP delayed to 2.5 seconds, which leaves 0.5 seconds of margin. The absence of the logical error in the server log is kept as a separate assertion, since a query-level error alone does not prove the server survived.
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 units13 translation units recompiled, 82 s compile time in total, 13 of them have a recent master baseline. |
| const auto & table_metadata = getTableMetadata(); | ||
| auto metadata = tryGetFilesMetadata(); | ||
| if (!metadata) | ||
| return settings; |
There was a problem hiding this comment.
Returning a default-constructed ObjectStorageQueueSettings here makes system.s3_queue_settings / system.azure_queue_settings lie about a queue table that is still attached after a failed DROP.
StorageSystemObjectStorageQueueSettings always calls storage.getSettings(), and dumpToSystemEngineSettingsColumns() derives changed / alterable from settings_changes in the in-memory metadata rather than from this fallback. That means explicit values like keeper_path, mode = 'unordered', or processing_threads_num = 16 now get reported as their defaults, sometimes with changed = 1, which breaks the system-table contract and hides the real configuration while debugging the leaked table.
Can we either reconstruct the values from the in-memory metadata plus the local members that still exist here, or skip this broken table from system.*_queue_settings instead of fabricating defaults?
There was a problem hiding this comment.
I checked this against the source and against CI history, and I am not making the change.
Reachability is right: StorageSystemObjectStorageQueueSettings.cpp:66 iterates every attached table and :56 calls getSettings() with no state filter. The changed/alterable inconsistency is real too, and slightly worse than described: alterable goes through isSettingChangeable(name, mode), and mode is one of the fields that falls back. The default is ORDERED, so an unordered table is reported against the ordered changeability set, and 5 settings flip (processing_threads_num, tracked_files_limit, tracked_file_ttl_sec, enable_hash_ring_filtering, buckets).
Two things argue against acting on it here.
The fallback is not introduced by this PR. At the merge base f889715f8, getSettings() already reads:
ObjectStorageQueueSettings settings;
/// If startup() for a table was not called, just use the default queue settings
if (!startup_finished)
return settings;A table whose startup() failed already reports default rows on master today. This PR widens the same behaviour to a second state (shut down, handle dropped); it does not create it.
Skipping the table is a measured regression. The only lever available inside getSettings() is a throw, and fillData has no try/catch, so one leaked queue table takes down the whole scan and every healthy table's rows with it. That is the failure this PR exists to remove, and it is the family's largest carrier in practice: over the last 40 days, of 25 Files metadata is empty aborts across 22 PRs, 11 carry the frames StorageObjectStorageQueue::getSettings -> StorageSystemObjectStorageQueueSettings::fillData.
On reconstructing the values: 26 of the 45 settings already come from members that survive shutdown and are correct. The other 19 come from keeper via the handle that is gone. settings_changes does track ALTER, but it only records names that were explicitly specified, so anything left unset at CREATE still reads back as its default. That closes part of the gap and leaves the rest unchanged, which seems worth doing on its own, but not as part of a PR scoped to reporting a clear error rather than making a leaked table readable.
Net effect today is a cosmetically wrong row for a table that is already broken, versus an abort that loses every row. I am leaving the fallback as is and not opening a follow-up for the row accuracy.
f7901a4
… on the object storage queue read path
Backport #113695 to 26.8: Fix `Files metadata is empty` logical error on the object storage queue read path
Cherry pick #113695 to 26.6: Fix `Files metadata is empty` logical error on the object storage queue read path
… on the object storage queue read path
Backport #113695 to 26.6: Fix `Files metadata is empty` logical error on the object storage queue read path
Backport #113695 to 26.7: Fix `Files metadata is empty` logical error on the object storage queue read path
…ical error on the object storage queue read path
|
26.3 does not have this fix, and the same LOGICAL_ERROR now aborts the server in The backport labels here start at The cherry-pick onto the current 26.3 will conflict in |
The new test `05493_s3queue_settings_system_table_hide_secrets` reads `system.s3_queue_settings`, which calls `StorageObjectStorageQueue::getSettings` for every queue table on the server. When a concurrent `DROP` shuts a queue table down, `shutdown` resets `files_metadata` while `startup_finished` stays set, and `getTableMetadata` throws the logical error `Files metadata is empty`. The same failure happened on the backport of this PR to the private release/26.4 branch. This is the part of #113695 that `getSettings` needs (26.3 does not have that PR): `files_metadata` is set and reset under `mutex`, `tryGetFilesMetadata` takes one snapshot of it, and `getSettings` returns the default settings when the table is shut down. PR: #129469 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The new test `05493_s3queue_settings_system_table_hide_secrets` reads `system.s3_queue_settings`, which calls `StorageObjectStorageQueue::getSettings` for every queue table on the server. When a concurrent `DROP` shuts a queue table down, `shutdown` resets `files_metadata` while `startup_finished` stays set, and `getTableMetadata` throws the logical error `Files metadata is empty`. The same failure happened on the backport of this PR to the private release/26.4 branch. This is the part of #113695 that `getSettings` needs (26.3 does not have that PR): `files_metadata` is set and reset under `mutex`, `tryGetFilesMetadata` takes one snapshot of it, and `getSettings` returns the default settings when the table is shut down. PR: #129469 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The test raced `DROP TABLE ... SYNC` against a direct `SELECT` by wall clock: the `SELECT` kept its plan open for ~3 s in a scalar subquery and pytest sent the `DROP` 1.2 s later, so the `DROP` had to reach the server within ~1.8 s. In `Integration tests (amd_msan, targeted)` on ClickHouse#112928 the `DROP`'s client needed 2.23 s to connect, the `SELECT` read the live metadata first and returned 0 without an error, and the assertion `'TABLE_IS_DROPPED' in ''` failed. Add a one-shot pause failpoint `object_storage_queue_pause_in_direct_select` in `StorageObjectStorageQueue::read()`, after the table is opened and before the read path takes the metadata handle. It parks the query thread during planning, never a pipeline worker inside `IProcessor::work()`. The test now enables it, starts the `SELECT`, waits for the pause, runs `DROP TABLE` (not `SYNC`: that waits for the paused `SELECT` to release the table), disables the failpoint and asserts `TABLE_IS_DROPPED`. One deterministic pass replaces the 10 sleep-based iterations. Same pattern as `nats_pause_before_checking_direct_select_connection` (ClickHouse#125494). Related: ClickHouse#112928 Related: ClickHouse#113695 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
Logical error: 'Files metadata is empty'when reading from, altering, or flushing anS3Queue/AzureQueuetable whose metadata handle is gone: concurrently with aDROP/DETACH, after a failedstartup, or after a failedDROP. Such a table now reportsTABLE_IS_DROPPEDinstead.SYSTEM FLUSH OBJECT STORAGE QUEUEon such a table no longer crashes the server.Description
StorageObjectStorageQueue::getTableMetadatathrewLOGICAL_ERRORwheneverfiles_metadatawas null, andcreateFileIteratorcalls it first. Plan optimization reaches it viaReadFromObjectStorageQueue::applyFilters, so an ordinarySELECTaborted the server in debug and sanitizer builds (7 occurrences in 90 days, 4 unrelated PRs, 0 on master).Three reachable states leave an addressable table with a null handle:
DROP/DETACH: the storage is shut down before any exclusive lock is taken, and for an Atomic database none is taken at all, while aSELECTholds onlylockForShare;startup: the catalog entry is created first, and never rolled back;DROP: the database does fallible disk work before detaching (the Logical error: 'Files metadata is empty' with fault injection #93009 route).The handle was also a plain
shared_ptrwith no synchronisation, unlike the twelve other members of that class, andwaitForPathToBeProcessedread it with no null check, which segfaulted.The fix guards it with the existing class mutex and gives every operation one snapshot it owns for its whole duration, so a handle observed non-null cannot become null halfway through.
getTableMetadatais removed rather than reimplemented on the accessor: it returned a reference into the object the snapshot owns, which a snapshot local to the accessor would leave dangling. Its seven callers each take their own. Where the state is legitimate the code reportsTABLE_IS_DROPPED, matchingIStorage; the background streaming path returns instead, a null handle there meaning shutdown.Such a table now reports a clear error; it does not become usable again, since recovery is a
DatabaseAtomic/InterpreterDropQueryconcern for every engine, out of scope here.All three reproduce on unpatched master with a stack frame-for-frame identical to the CI report, the concurrent-teardown one with no fault injection (8/8). Three integration tests cover them: pristine master reports 1 failure, the fix 18 passes, 30/30 repeats green.
Workflow [PR]
Sync PR [sync-upstream/pr/113695]
Version info
26.9.1.54(included in26.9and later)26.8.1.1996,26.7.6.34,26.6.4.39