Repository navigation
Conversation
Log and TinyLog store every column stream in its own <derived name>.bin, and
StorageLog::addDataFiles built that path with no length policy, so CREATE TABLE
accepted a column the filesystem could never hold. The table was then permanently
unwritable: the LogSink ctor calls saveFileSizes -> FileChecker::update ->
fileReallyExists -> std::filesystem::status, which fails ENAMETOOLONG. That arrives
as a std::filesystem::filesystem_error rather than a DB::Exception, so its text was
dropped and the client saw a bare Code: 1001 (STD_EXCEPTION) naming neither the
column nor any limit. Reads and DROP kept working.
The check measures the derived, escaped stream name inside the enumerateStreams
callback rather than the column name, because both escaping and substreams expand it:
84 '%' characters escape to 252 bytes, and a Nested(a UInt64) column overflows at 246
characters via <name>%2Ea.size0 while a plain column fits up to 251. A column-name
check misses both. The budget is pathconf(_PC_NAME_MAX) probed at the disk root, since
pathconf on a path that does not exist yet answers -1/ENOENT and the disk root is
created at registration. The measured boundary (251 accepted, 252 refused) matches
budget - strlen(".bin"), and .bin is the only suffix the family derives.
An existing table whose stored metadata already carries an over-long name still loads,
because the check is gated on a freshness flag: attach_short_syntax marks every
definition read back from stored metadata, exempting a restart, a short ATTACH and a
Replicated DDL replay. A RESTORE is deliberately not exempt, since it shares
SECONDARY_CREATE with that replay and only is_restore_from_backup separates them, and
a restored table that can never accept a row is not a successful restore. Writing to
such a legacy table now reports the offending file and the limit instead of the
filesystem error, which is the one runtime site that needed the translation.
That translation is conditional on the refused basename being over the budget:
ENAMETOOLONG also covers a PATH_MAX overflow, and StorageLog::rename rebuilds paths
from an unconstrained table path, so a short column name under a deep table path keeps
its existing error instead of being misattributed to a column.
The DDL rejection was chosen over hashing the on-disk name because Log has nowhere to
record a mapping: sizes.json keys are the basenames themselves, backupData writes them
into the backup, and the family has no settings schema to carry a max_file_name_length
analogue. Since no ALTER can introduce a column name after creation, a CREATE-time
check is complete for this engine.
Closes: ClickHouse#112714
Internal second-model review (1 finding, adjudicated)An independent model reviewed this diff cold, and I reviewed it separately before seeing its
|
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-43:20260803-040500 (implementation) / cron:clickhouse-review-slot-48:20260803-083300 (review) |
|
cc @azat @alesapin, could you review this? |
|
Workflow [PR], commit [9ea8522] Summary: ❌
AI ReviewSummaryThis PR fixes the local Findings
Final VerdictChanges required: the per-host stream-name check still misses fresh LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 92/128 (71.88%) · Uncovered code |
| #include <Storages/LogStreamFileNameLength.h> | ||
|
|
||
| #include <Common/ErrnoException.h> | ||
| #include <Common/Exception.h> |
There was a problem hiding this comment.
@groeneai again, do you need such a long PR to fix the issue?
There was a problem hiding this comment.
No, and you were right to ask twice. It is now +85/-0 over 4 files (047e54e1), down from +466/-3 over 10. Three things went:
LogStreamFileNameLength.{h,cpp}existed to re-type the filesystem'sENAMETOOLONGby inspecting an in-flight exception, and to keep that basename-conditional so aPATH_MAXoverflow was not blamed on the column. Checking the derived names inStorageLog::writebefore the sink runs gives the same message with no exception plumbing at all, so the file, its twocatch (...)classifiers and thePATH_MAXambiguity are gone.- The
is_fresh_definitionbool threaded through the constructor, the header andregisterStorageLogcollapses tomode <= LoadingStrictnessLevel::CREATE, already a constructor parameter, which is howcheckTableNameLengthgates itself atInterpreterCreateQuery.cpp:2162. - The integration test existed only to plant metadata on disk to build a legacy table. An A/B against the pre-fix binary proves the same property directly, so the whole directory went and the stateless test is 30 lines.
One trade this creates, so you can reverse it if you disagree: RESTORE of such a table, and a full-definition ATTACH (only reachable on the deprecated Ordinary engine, Atomic refuses the syntax), now report the limit at the first write instead of refusing the DDL. Measured, both give the typed ARGUMENT_OUT_OF_BOUND, and neither is a regression since master gives Code: 1001 for both. Refusing them at DDL time is what needed the freshness flag plus the integration test to separate RESTORE from a Replicated replay, i.e. most of what I just deleted. Say the word and it comes back.
On #113044: it is a different size, +1269/-87, and I will look at it there rather than argue it here.
Two mechanical lint failures, no change to the fix logic. The `catch (...)` blocks in `recoverFailedPath` and `isFilenameTooLongError` classify an exception that the caller still owns and rethrows, so nothing is swallowed there. `check_catch_all` cannot see that, and the convention it asks for is a comment containing `Ok`, matching the existing form at `src/Client/LocalConnection.cpp:445`. `various_checks.sh` requires an `__init__.py` in every `tests/integration/test_*` directory; the new integration test was missing its (empty) one. Also corrects a comment in the stateless test. It named a derived stream `%2Ea.size0` that does not exist: with `flatten_nested = 1` the column is `<base>.a`, and `share_nested_offsets` makes the `ArraySizes` substream use the extracted table name, so the two derived streams are `<base>%2Ea` and the shared `<base>.size0`. In-tree artifact `02047_log_family_complex_structs_data_file_dumps.reference` shows exactly this shape (`y%2Ez.bin`, `y%2Ew.bin`, shared `y.size0.bin`). The measured 245/246 boundary is unaffected: `.size0` is the longer suffix and 245 + 6 is 251, the limit. Co-Authored-By: Claude Fable 5 <[email protected]>
@PedroTadim asked twice today whether these PRs need to be this long. This one did not: it is now +84/-0 over 4 files, down from +470/-3 over 10. Three things went away. The separate translation unit `LogStreamFileNameLength.{h,cpp}` existed to re-type the filesystem's own `ENAMETOOLONG` into `ARGUMENT_OUT_OF_BOUND` by inspecting an in-flight exception, and to keep that inspection basename conditional so a PATH_MAX overflow from a deep table path was not blamed on the column. Checking the derived names in `StorageLog::write` before the sink runs gets the same message without ever touching an exception, so the exception plumbing, its two `catch (...)` classifiers and the PATH_MAX ambiguity are all gone. The check is one loop over `data_files`, whose names `addDataFiles` already derived. The `is_fresh_definition` flag threaded through the constructor, the header and `registerStorageLog` reduces to `mode <= LoadingStrictnessLevel::CREATE`, which is already a constructor parameter. That is exactly how the in-tree precedent for this check gates itself: `InterpreterCreateQuery.cpp:2162` skips `checkTableNameLength` for secondary creates for the same backward compatibility reason. The previous three-term flag also checked `RESTORE`, but a restore of an over-long definition is now refused at the first `INSERT` rather than at `RESTORE`, which is the same place every other legacy table reports it. The integration test went with it. It existed only to build a legacy table by planting metadata on disk, which @alexey-milovidov's rule keeps out of functional tests. That fixture was proving the same thing an A/B against the pre-fix binary proves directly: a table created by the old binary still loads, still SELECTs, still DROPs, and its INSERT now reports the file and the limit instead of `Code: 1001`. The remaining stateless test is 30 lines and keeps the cases that are not obvious from the code: the boundary for both engines, an 84 character name that overflows because escaping expands it, a `Nested` column that overflows 6 characters early because a substream appends to the name, and StripeLog staying unaffected. Co-Authored-By: Claude Fable 5 <[email protected]>
| DROP TABLE IF EXISTS t_at_limit; | ||
| DROP TABLE IF EXISTS t_nested_at_limit; | ||
|
|
||
| CREATE TABLE t_at_limit (`ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc` UInt8) ENGINE = Log; |
There was a problem hiding this comment.
@groeneai add test examples with RENAME table. Are long column names safe for these engines?
There was a problem hiding this comment.
Added the RENAME TABLE case, and no, a rename cannot make these names unsafe.
A rename never touches a column name, and the limit is per path component, so the derived
<name>.bin component is unchanged however long the table or database name becomes. I
measured it both ways: the at-limit 251-byte column stays writable after a rename within a
database, after a rename into a database with a 200-byte name, and under Ordinary, where
the data path really is name-derived and grew from 96 to 191 bytes. The test now pins the
same-database case.
No ALTER can introduce a long name after creation either: StorageLog does not override
checkAlterIsPossible, so IStorage refuses every non-comment alter, and RENAME COLUMN
comes back Code: 48.
Your question did find something, though. ATTACH TABLE t [FROM '<path>'] (<definition>) ENGINE = Log supplies a fresh definition but arrives under LoadingStrictnessLevel::ATTACH,
so the mode <= CREATE gate skipped the check and that DDL accepted a name a plain CREATE
refuses. Fixed in 1bf035b by using the predicate registerStorageMergeTree already
uses for this exact question: fresh means CREATE, or an ATTACH that did not come from
stored metadata (attach_short_syntax). Existing tables are unaffected, verified against a
table built by a pre-fix binary: it still loads, reads and drops, and its INSERT reports
the file and the limit.
+31/-5 over 5 files now, one commit on top of the reduction.
There was a problem hiding this comment.
One correction to my last answer, since I found a case where the answer is not simply yes.
A RESTORE can still bring in a name that does not fit. The DDL check and the write-time check
both run before any file is opened, but restoreDataImpl appends the backup's files directly and
goes through neither, so a backup taken where the derived name fits and restored where it does not
still surfaces the raw Code: 1001 rather than the typed message. I reproduced it by restoring a
backup whose data file already carries an over-long name: master and this PR behave identically,
so the guard genuinely does not cover that path. I am adding the same check before the append.
Worth saying what is not affected, because it narrows the fix: a table that predates the check
can never hold data, since its first INSERT always failed before any file was created. Its
backup therefore contains only metadata, restoreDataFromBackup returns early, and restoring it
works today and keeps working; the first INSERT afterwards reports the limit. So the fix belongs
at the append site, not as a refusal of restored tables, which would break those empty ones.
Separately, the test I added is not parallel-safe and the flaky check caught it: the
full-definition ATTACH case pins a literal table UUID, and a UUID is server-global, so
concurrent copies race and one gets TABLE_ALREADY_EXISTS instead of the expected error. The
explicit UUID is mandatory for that syntax, so I am moving the case to a shell test that generates
one per run rather than serialising the test.
There was a problem hiding this comment.
Both landed in f261948, and one correction to what I said above: the test did not need a
shell after all.
I said I would move the full-definition ATTACH case to an .sh test to generate a unique UUID
per run. That is unnecessary, because the FROM '<path>' form of the same full-definition
ATTACH requires no UUID clause at all and reaches the identical predicate, so the case stays
pure SQL with no new file and no tag. Measured with 24 simultaneous attaches, one database each:
the old form returns TABLE_ALREADY_EXISTS 8 times out of 24, the new form returns the expected
ARGUMENT_OUT_OF_BOUND 24 out of 24. The runner alone does not expose the collision at
--test-runs 34 -j 8, which is why the flaky check only caught it 10 times in 34.
The restoreDataImpl guard is the typed check before the append, as described. An at-limit table
with data still backs up and restores, and the empty pre-fix tables still restore, which is why
the check is not at creation.
+7/-2 over 2 files on top of the previous commit.
`ATTACH TABLE t [FROM '<path>'] (<definition>) ENGINE = Log` supplies a fresh definition but reaches the storage under `LoadingStrictnessLevel::ATTACH`, so gating the check on `mode <= CREATE` skipped it and the DDL still accepted a column whose derived file name cannot exist. The write-time check kept the error typed, so this was never a return to the reported `Code: 1001`, but the name was accepted where a plain `CREATE` refuses it. The gate is now the predicate `registerStorageMergeTree` already uses for the same question: fresh means `CREATE`, or `ATTACH` that did not come from stored metadata. Definitions replayed from metadata carry `attach_short_syntax` (set in `createTableFromAST`), so a restart, a short `ATTACH TABLE t`, an `ATTACH DATABASE` and a `Replicated` DDL replay stay exempt and a table whose stored name is already over the limit still loads, still reads and still drops. The test also covers `RENAME TABLE`, which @PedroTadim asked about. A rename cannot cross the bound: it never touches a column name, and the limit is per path component, so the derived `<name>.bin` component is unchanged however long the table or database name becomes. No `ALTER` can introduce a name either, since `StorageLog` does not override `checkAlterIsPossible` and `IStorage` refuses every non-comment alter, including `RENAME COLUMN`. Co-Authored-By: Claude Fable 5 <[email protected]>
…st parallel-safe Two fixes from the CI of the previous commit. The `Stateless tests (amd_tsan, flaky check)` job failed 10 of 34 runs of `04686_log_column_name_length` with `Expected server error code: 69 but got: 57`. The full-definition `ATTACH` case pinned a literal table UUID, and a table UUID is server-global under `Atomic`, so the flaky check's concurrent repetitions of the test collided and one got `TABLE_ALREADY_EXISTS` before the length check could run. The explicit UUID is mandatory for that syntax, but the `FROM '<path>'` form of the same full-definition `ATTACH` needs none and reaches the identical predicate, so the case now uses it and stays pure SQL, with no tag and no new file. Measured with 24 simultaneous attaches, one database each: the old form returns `TABLE_ALREADY_EXISTS` 8 times out of 24, the new form returns the expected `ARGUMENT_OUT_OF_BOUND` 24 times out of 24. `StorageLog::restoreDataImpl` appends the backup's data files with `copyFileToDisk` and goes through neither the DDL check nor `StorageLog::write`, so a backup carrying a derived stream name that does not fit the destination was refused by the filesystem as an untyped `filesystem_error` whose own message is lost, surfacing as a bare `Code: 1001`. It now runs the same typed check before the append. This happens for a backup taken where the derived name fits and restored where it does not; a table that predates the check cannot reach it, because its first `INSERT` always failed before any data file was created, so its backup holds only metadata and `restoreDataFromBackup` returns early. Refusing restored tables at creation instead would have rejected exactly those empty tables, which restore cleanly today. Co-Authored-By: Claude Fable 5 <[email protected]>
The stateless test only reaches the fresh-definition DDL checks: every over-long name is refused at DDL, so `StorageLog::write` is never reached, and every at-limit name fits, so the guard there is a no-op. The two runtime guards added by this PR were therefore verified only by hand, against a pre-fix binary, and a refactor could drop either `checkStreamFileNameLengths` call with nothing going red. Both are reachable from a unit test without fabricating any on-disk state, which is what made the earlier integration test unnecessary. `StorageLog`'s constructor already takes `is_fresh_definition`, so passing it false with an over-long column builds exactly the state a table created before the check loads in, with no metadata planted on disk. The write path then needs nothing more than a `write` call. For the restore path only the derived file name matters, because the guard runs before any backup entry is read, so a minimal `IBackup` that answers `hasFiles` and `fileExists` reaches it and fails the test if `copyFileToDisk` is ever called. A third case pins the compatibility direction: the same over-long definition must keep loading, since the DDL check stays exempt for stored metadata. Removing both guards fails exactly the two guard tests with code 107, the untyped filesystem error this PR replaces, and leaves the loading test green.
Asserting only the error code and the phrase let an implementation drop the offending file name and the two lengths while still passing. Degrading the message to keep just its class now fails both guard tests, and the message is the whole point of the change: the untyped filesystem error it replaces is refused for losing exactly that information. The bound itself is whatever the disk reports, so the test requires a digit after the phrase rather than a fixed 251.
Requiring only a digit after the phrase let an implementation report an arbitrary bound while passing. The test now derives the value the storage must report from the test disk and asserts it, so reporting 1 instead of the real limit fails.
| /// that runs under `ATTACH`; definitions read back from stored metadata carry | ||
| /// `attach_short_syntax` (see `createTableFromAST`). Same predicate as | ||
| /// `registerStorageMergeTree`. | ||
| const bool is_fresh_definition = args.mode <= LoadingStrictnessLevel::CREATE |
There was a problem hiding this comment.
SECONDARY_CREATE is still being treated as "already validated metadata", but this check depends on pathconf(disk->getPath(), _PC_NAME_MAX), i.e. the local target disk rather than just the AST. In a Replicated database or CREATE ... ON CLUSTER, only the initiator reaches this branch as CREATE; the other hosts replay the same definition under SECONDARY_CREATE, skip the constructor check here, and can still create an unwritable Log/TinyLog table if their local disk has a smaller component limit. The failure then moves back to the first INSERT on those nodes.
I think this predicate needs a SECONDARY_CREATE && !args.is_restore_from_backup arm so replicated / ON CLUSTER creates are revalidated per host, while the restore compatibility tradeoff stays intact.
Poco::Exception::message returns const std::string &, so copy-initializing a const String from it is a needless copy. clang-tidy's performance-unnecessary-copy-initialization is warnings-as-errors in the arm_tidy build, which failed the whole build on that one diagnostic. Also trim the registerStorageLog comment to the local invariant: the attach_short_syntax rationale and the cross-file citations belong here in the commit message, not at the call site.
CI finish ledger - 4cdb20aEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Not PR-caused. This diff validates Log-family column name length at DDL time and touches only On the first row: the sibling assert Session id: cron:our-pr-ci-monitor:20260804-160000 |
CI finish ledger correction - 4cdb20aRow 1 of my ledger above said the coverage of #113225 for this array shape "is not yet measured, so
Three arms, all pre-built binaries, Build IDs asserted, fixture = the CI shape minimised
The master arm is a valid control: The reason this fingerprint looked distinct from the The abort message is self-consistent with that: the dropped and re-added member The victim query is from Session id: cron:clickhouse-plan-slot-36:20260804-204400 |
Resolution of the
|
CI finish ledger - 0a512fcEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose
All 174 check-runs completed and Session id: cron:our-pr-ci-monitor:20260805-230000 |
|
Fixing PR for the It replaces the oracle that counted every The failure on this PR was on a build that predates that merge. Probing the test file per build (marker No action needed here beyond a rerun or a rebase onto current master. |
…-log-column-name-length
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 units10 translation units recompiled, 15 s compile time in total, 7 of them have a recent master baseline. |
CI finish ledger - 9ea8522Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task CI is fully finished on this head: 175/175 check-runs completed, 0 incomplete,
Not caused by this PR, and it is not a test failure. The job's own report says so: Note this is a different arm from the two Session id: cron:our-pr-ci-monitor:20260809-040000 |
|
I think the fix is easier than this. Thanks for trying. |
|
Taking the close as final, and correcting a question I asked 20 minutes ago on #113044. There I asked whether a bare length check on the derived
Every one of those failures produces a derived basename of exactly 256 characters, one past That makes the check one condition rather than a constant: in Two things I would want your call on, because they are the difference between one condition and the machinery you just rejected:
No test fabricates anything for this: |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
LogandTinyLogaccepted a column whose derived on-disk file name did not fit one path component, soCREATE TABLEsucceeded and everyINSERTthen failed withCode: 1001, STD_EXCEPTIONand no message. Such a column is now refused atCREATE TABLEwithARGUMENT_OUT_OF_BOUNDnaming the file and the limit, and an existing table with such a column keeps loading and reports the same typed message on write.Description
Every
Log/TinyLogstream is stored as<derived name>.binin one path component, and nothing bounded that name.CREATEaccepted it and the refusal surfaced only at the firstINSERT, as astd::filesystem::filesystem_errorrather than aDB::Exception, so its text was lost and onlyCode: 1001reached the client.The limit is now checked against the derived name at three sites, one per writer that can reach the filesystem:
CREATE, or anATTACHthat did not come from stored metadata, the predicateregisterStorageMergeTreeuses for the same question. The unwritable table is never created, and a full-definitionATTACHis covered too;StorageLog::write, so a table created before this check reports the file and the limit instead of the bareCode: 1001;StorageLog::restoreDataImpl, which appends the backup's files withcopyFileToDiskand passes through neither of the above. It is reachable with a backup taken where the derived name fits and restored where it does not. Refusing restored tables at creation would instead reject the empty pre-fix tables that restore cleanly today, whose backups hold metadata only because their firstINSERTfailed before any data file existed.The bound is probed with
pathconf(_PC_NAME_MAX)at the disk root, likecomputeMaxTableNameLengthdoes, and measured after derivation becauseescapeForFileNameand substreams both expand the name.StripeLogis unaffected, all its columns share onedata.bin.Verified in both directions: every rejection case succeeds wrongly on master, a pre-fix table still loads and drops with its
INSERTnow typed, and an at-limit table with data still backs up and restores cleanly.04686_log_column_name_lengthpins the DDL cases. Unit tests ingtest_storage_log.cpppin the two runtime guards: deleting either one fails them with the untypedCode: 107.Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=113072&sha=1bf035b384b0e9d81a95e12a393bc60eb1b4d3d8&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20flaky%20check%29