Repository navigation
Report a too long async distributed INSERT directory name as a user error - #113083
Conversation
…rror With use_compact_format_in_distributed_parts_names = 0 an async INSERT into a Distributed table spools blocks into one on-disk directory per destination, named user[:password]@host:port[#default_database]. For a shard with internal_replication that name is additionally comma-joined across every replica of the shard, so around ten ordinary replicas already exceed NAME_MAX (255 bytes) without any single field being long. The resulting failure was misreported on both shard shapes, even though the condition is purely input-driven (cluster configuration plus a per-query setting) and therefore not an invariant violation: - internal_replication = true: Cluster::ShardInfo::insertPathForInternalReplication threw LOGICAL_ERROR, which aborts the server in assert builds. - internal_replication = false: there was no check at all, so mkdir failed with ENAMETOOLONG and surfaced as Code: 1001 DB::Exception: std::exception, naming neither the cluster nor the limit. Add a single length check at the top of DistributedSink::writeToShard, which is the sole creator of these directories (including the hardlink loop over the later destinations) and is reached by both shard shapes, and throw ARGUMENT_OUT_OF_BOUND mirroring DatabaseOnDisk::checkTableNameLength. Placing it above the storage-policy reservation means nothing is reserved and no partial directories are left behind on the failing path. The now redundant LOGICAL_ERROR in Cluster.cpp is removed, leaving insertPathForInternalReplication a pure accessor; its !has_internal_replication check is unchanged. The message deliberately reports the length rather than the name, because the name embeds the password that system.distribution_queue masks out. Names of 255 bytes or less are unaffected, and the compact format stays unaffected because shard<N>_replica<M> is bounded by construction. The check covers the write path only: an over-long directory already present on disk is still tolerated when directory queues are initialized, so table loading cannot start failing after an upgrade. Rejecting the combination earlier, at CREATE TABLE or at config parse time as the issue suggests, is not possible, because use_compact_format_in_distributed_parts_names is a per-query setting and at that point it is unknown whether such a name is ever built. A config-time check would reject clusters used only for SELECT or only with the compact format. Closes: ClickHouse#112719
The tests pinned only the error code, so shrinking the message would have left them green while the fix's stated contract (name the table, the cluster and the limit) went untested. That contract is the second half of issue ClickHouse#112719, whose complaint is that the old failure named "neither the cluster, nor the directory, nor the limit". The stateless test asserts the table name and the limit; the cluster is asserted in the integration case, which is the only place a real named cluster exists (the Remote engine reports the <remote> fallback). The new positive row also makes the adjacent password_not_leaked zero self-evidencing: it previously held vacuously on a reverted fix, where the exception code is 1001 and its predicate selects no rows. Verified by shrinking the format string to just the length: exactly the new assertion reddens, every other arm stays green.
Internal second-model reviewAn independent model reviewed this change cold, without access to the reasoning behind it.
Verified during review and deliberately left alone: the deleted |
Pre-PR validation gate
|
|
cc @devcrafter @alexey-milovidov, could you review this? An async INSERT into a Distributed table names its spool directory after the destination address, comma-joined across replicas for an |
|
Workflow [PR], commit [1339110] Summary: ❌
AI ReviewSummaryThis PR moves the async distributed-insert directory-name validation to the actual queue-directory creation boundary, reclassifies the overlong-name failures as user-facing Final Verdict✅ No blocking findings. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 23/23 (100.00%) · Uncovered code |
A shard without internal replication that contains this server plus a remote destination whose directory name exceeds NAME_MAX inserted into the local table first and only then hit the length check, so the INSERT reported ARGUMENT_OUT_OF_BOUND after it had already changed local state, and a retry duplicated rows on the local replica. Move the check ahead of writeToLocal by assembling the destination list first and validating it there. The check is extracted into checkDirectoryNameLengths and is still called from writeToShard, which is the only creator of these directories, so both callers remain covered structurally. Reported by the automated review on ClickHouse#113083. Co-Authored-By: Claude Fable 5 <[email protected]>
Automated review round 1 - adjudication
Details are in the inline thread. Summary: the ordering claim is correct and I reproduced the Validation on the pushed head: Session id: cron:clickhouse-maint-slot-18:20260803-152500 |
CI finish ledger - 1339110Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
158 success, 15 skipped, 2 failures out of 175 check-runs. Session id: cron:our-pr-ci-monitor:20260804-000000 |
bb47935
Closes: #112719
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed the error reported when an asynchronous
INSERTinto aDistributedtable needs a queue directory whose name exceeds the 255-byte filesystem limit (reachable withuse_compact_format_in_distributed_parts_names = 0). It was aLOGICAL_ERRORfor a shard withinternal_replicationand an unattributedCode: 1001. std::exceptionotherwise; both now reportARGUMENT_OUT_OF_BOUNDnaming the table, the cluster and the limit.Description
With
use_compact_format_in_distributed_parts_names = 0an asyncINSERTspools blocks into one directory per destination, nameduser[:password]@host:port[#default_database]. For a shard withinternal_replicationthat name is comma-joined across all replicas, so ~10 replicas exceedNAME_MAX(255) with no single long field.The condition is purely input-driven, so neither failure mode was an invariant violation:
internal_replication = true:Cluster::ShardInfo::insertPathForInternalReplicationthrewLOGICAL_ERROR, which aborts the server in assert builds.internal_replication = false: no check at all.mkdirfailed withENAMETOOLONG, surfacing asCode: 1001. DB::Exception: std::exception, naming neither the cluster nor the limit.The fix adds one length check at the top of
DistributedSink::writeToShard, the sole creator of these directories (including the hardlink loop over the later destinations) and reached by both shard shapes. It throwsARGUMENT_OUT_OF_BOUND, mirroringDatabaseOnDisk::checkTableNameLength, before any disk reservation. The now-redundantLOGICAL_ERRORinCluster.cppis removed, leavinginsertPathForInternalReplicationa pure accessor. The message omits the name itself, which embeds the passwordsystem.distribution_queuemasks out.Names of 255 bytes or less behave exactly as before, and the compact format is unaffected (
shard<N>_replica<M>is bounded by construction). The check is on the write path only, so a too long directory already on disk stays tolerated and table loading cannot start failing.Rejecting the combination at
CREATE TABLEor config parse time, as the issue suggests, is not possible:use_compact_format_in_distributed_parts_namesis a per-query setting, so at that point it is unknown whether such a name is ever built.Validated by a new stateless test (the unguarded branch, the exactly-255 boundary, a multi-destination shard whose first address is short, and the password not being disclosed) plus a new
test_distributed_formatcase for theinternal_replicationhalf. Both fail on master.