Repository navigation
Fix Bad cast on data-lake SETTINGS disk = '...' with wrapped object storage - #104258
Conversation
… storage `StorageS3Configuration::fromDisk` (and the Azure parallel) called `assert_cast<const S3ObjectStorage &>(*disk->getObjectStorage())` directly. `assert_cast` checks `typeid` exactly, so any decorator that wraps the underlying `S3ObjectStorage` — most importantly `CachedObjectStorage` for disks created with `wrapWithCache(...)` — caused `Logical error: 'Bad cast from type DB::CachedObjectStorage to DB::S3ObjectStorage'` during argument parsing. Historically this also surfaced as `Bad cast from type DB::PlainObjectStorage<DB::S3ObjectStorage> to DB::S3ObjectStorage` (reported in ClickHouse#89300). The `PlainObjectStorage<>` decorator was removed in ClickHouse#90580, but the same pattern still bites for `CachedObjectStorage`. CIDB shows the cached-disk variant being hit by the BuzzHouse fuzzer (e.g. a `CREATE TABLE ... ENGINE = DeltaLakeS3(...) SETTINGS disk = '...'` query on PR ClickHouse#94148) and by `test_storage_iceberg_disks` runs. Use the existing `IObjectStorage::getUnderlying()` virtual to walk past any decorator layers before the cast. Apply the same fix to the Azure path which has the identical pattern. Add a stateless regression test that exercises `icebergS3` with three disk shapes (`s3_disk` raw, `s3_cache` wrapped, `s3_plain_disk` plain metadata). The test does not need a real iceberg table — it asserts that argument parsing no longer throws a logical error and the query fails with an expected S3/iceberg error code instead. The CI test config now allows-lists those four disks for use with table engines so the data lake disk-validation gate lets the queries through to the real check. Closes ClickHouse#89300
|
cc @kssenii @Michicosun @PedroTadim — could you review this? The fix unwraps decorator object storages (notably |
|
Workflow [PR], commit [c39f742] Summary: ✅ AI ReviewSummaryThis PR fixes argument parsing for data-lake table functions/engines when Missing context
ClickHouse Rules
Final Verdict
|
LLVM Coverage Report
Changed lines: 50.00% (6/12) · Uncovered code |
The stress-test log scanner (`ci/jobs/scripts/log_parser.py`) uses `rg --text -A 10 -o 'Logical error.*'` against the server log. Test `04208_iceberg_disk_with_cache_no_bad_cast.sql` previously included the literal exception string in its SQL comments. When such a query fails (it is expected to fail at table-resolution time), the full query — including those comments — is echoed into the `<Error> executeQuery` log entry. If a later, completely unrelated fatal error occurs in the same stress-test run, the scanner picks up the SQL-comment occurrence first and uses it as the failure name, even though the actual stack trace (and `STID`) belong to a different bug. Three master/PR runs on 2026-05-07 hit this false positive: - `Stress test (experimental, serverfuzz, arm_tsan)` on master (commit 69167ef) — actual abort was a `chassert(false)` in `paranoidCheckForCoveredPartsInZooKeeperOnStart`, reported as `STID 2508-5dc3`. - `Stress test (arm_asan_ubsan)` on PR ClickHouse#100377 — actual abort was `Not-ready Set is passed as the second argument for function 'in'` in `FunctionIn::executeImpl`, reported as `STID 0250-4e52`. - `Stress test (amd_msan)` on PR ClickHouse#93037 — same `Not-ready Set` family, reported as `STID 0250-41a5`. The original `Bad cast from CachedObjectStorage to S3ObjectStorage` bug that this test guards against is genuinely fixed by ClickHouse#104258 — the unwrap loop in `S3StorageParsedArguments::fromDisk` is in place and none of these three runs actually crashed in that code path. This commit reworks the comments in 04208 so they describe the bug without containing the verbatim `Logical error: '...'` pattern that the scanner greps for, and adds a `NOTE` explaining why the verbatim text is intentionally avoided. The SQL queries and expected `serverError` codes are unchanged. CI report (master arm_tsan): https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=69167ef25d21358fd8f171e593849ea73195dd1b&name_0=MasterCI&name_1=Stress%20test%20%28experimental%2C%20serverfuzz%2C%20arm_tsan%29 Co-Authored-By: Claude Opus 4.7 <[email protected]>
Fixes #89300.
Motivation
A user reported via #89300 that
against a disk configured with
metadata_type = plainaborted withLogical error: 'Bad cast from type DB::PlainObjectStorage<DB::S3ObjectStorage> to DB::S3ObjectStorage'.The
PlainObjectStorage<>decorator was deleted by #90580, so theexact crash from the original report is gone, but the underlying bug
pattern remains:
S3StorageParsedArguments::fromDisk(and the Azuresibling) call
assert_cast<const S3ObjectStorage &>(*disk->getObjectStorage())directly.
assert_castperforms an exacttypeidmatch indebug/sanitizer builds, so any decorator that wraps the underlying
storage instead of being it (most importantly
CachedObjectStorage,returned by
DiskObjectStorage::wrapWithCache) still crashes argumentparsing with
Logical error: 'Bad cast from type DB::CachedObjectStorage to DB::S3ObjectStorage'.I confirmed this is currently reachable in trunk:
CREATE TABLE d1.t28 ENGINE = DeltaLakeS3(s3, filename = 't28', format = 'Parquet') SETTINGS disk = 'disk1', iceberg_format_version = 3.cache-typed disk overs3andSETTINGS disk = '<cache_disk>'aborts the server in theexact same way.
Approach
IObjectStoragealready exposesgetUnderlying()which returns theinner storage for decorator types and
nullptrotherwise. Walk thatchain before the cast in both
S3StorageParsedArguments::fromDiskandAzureStorageParsedArguments::fromDisk. After unwrapping, the castsees the concrete
S3ObjectStorage/AzureObjectStorageandsucceeds.
Validation
Pre-PR validation gate:
Logical error: 'Bad cast from type DB::CachedObjectStorage to DB::S3ObjectStorage'and kills the server.
assert_castinDEBUG_OR_SANITIZER_BUILDdoes a stricttypeid(from) == typeid(To)check (see comment at
src/Common/assert_cast.h:19).CachedObjectStorageinherits only from
IObjectStorage, not fromS3ObjectStorage, sothe equality fails and the helper throws
LOGICAL_ERROR. In releasebuilds the underlying
static_castis undefined behaviour becausethere is no inheritance relationship at all.
the typeid matches. No
assert_castsemantics are weakened.binary returns
FILE_DOESNT_EXIST(as expected for a missing icebergtable) instead of crashing. Verified for
s3_disk(raw),s3_cache(cached), ands3_plain_disk(plain metadata).and uses the existing
getUnderlying()virtual so any futuredecorator added to
IObjectStorageis handled automatically.The new stateless test
tests/queries/0_stateless/04208_iceberg_disk_with_cache_no_bad_cast.sqlexercises all three disk shapes (raw, cached, plain metadata) and
asserts that the query fails with an S3/iceberg-level error rather
than a
LOGICAL_ERROR. The existing test config is extended with anarrow
allowed_disks_for_table_enginesso the data-lake disk gatelets the queries through to the real check.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a logical error (
Bad cast from type DB::CachedObjectStorage to DB::S3ObjectStorage) that aborted argument parsing of data-lake table functions and engines (icebergS3,deltaLakeS3, etc.) when called withSETTINGS disk = '...'against a disk whose underlying object storage is wrapped by a decorator such as a filesystem cache. Closes #89300.Documentation entry for user-facing changes