Skip to content

Backport #115334 to 25.8: Do not let SET <name> = DEFAULT bypass the settings constraints - #116258

Merged
alexey-milovidov merged 2 commits into
25.8from
backport/25.8/115334
Aug 27, 2026
Merged

alexey-milovidov merged 2 commits into
25.8from
backport/25.8/115334

Conversation

@robot-ch-test-poll3

@robot-ch-test-poll3 robot-ch-test-poll3 commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Original pull-request #115334
Cherry-pick pull-request #115936

This pull-request is a last step of an automated backporting.
Treat it as a standard pull-request: look at the checks and resolve conflicts.
Merge it only if you intend to backport changes to the target branch, otherwise just close it.

The PR source

The PR is created in the CI job

Version info

  • Merged into: 25.8.34.7

@robot-ch-test-poll3 robot-ch-test-poll3 added pr-backport Changes, backported to release branch. Do not use manually - automated use only! pr-critical-bugfix labels Aug 25, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [BackportPR], commit [67fec0b]

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 The only CI failure here was 02443_detach_attach_partition (ATOMIC_RENAME_FAIL, "File exists" on detached/attaching_all_94_94_0) — a long-known flaky test unrelated to this settings-constraints backport (it also failed on unrelated #114927 on 2026-08-16, and has a history of closed flaky-test issues, e.g. #54748). I merged the 25.8 base branch to re-run CI.

@groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=116258&sha=629bd7e0f725f065b6ea8e783f98ae4b3e28e067&name_0=BackportPR&name_1=Stateless%20tests%20%28amd_asan%2C%20distributed%20plan%2C%20parallel%2C%202%2F2%29 and provide a fix in a separate PR. If the fix is already in progress, link it here.

@groeneai

Copy link
Copy Markdown
Collaborator

Investigated. This is a second, distinct failure mode in that test, not the one that failed on #114927 on 2026-08-16.

The 08-16 one was Code: 76 CANNOT_OPEN_FILE, errno 13, writing detached/attaching_*/metadata_version.txt; #87838 fixed it and #115009 backported it to 25.8 on 2026-08-18. This one is errno 17 on the rename of the part directory itself, and the state that produces it is created moments earlier in the same run. From clickhouse-server.log of the run you linked, table test_sj8fi9pu.alter_table1:

  1. A replication queue entry for all_94_94_0 enters attachPartHelperFoundValidPart, which renames detached/all_94_94_0 to detached/attaching_all_94_94_0. That reserves the attaching_ name and releases the base name.
  2. 10:37:55.971 the concurrent DETACH PARTITION (executed as DROP_RANGE all_0_96_999999999_999999999) detaches the active all_94_94_0. getRelativePathForPrefix only tests whether detached/all_94_94_0 exists, finds it free after step 1, and reuses the base name with no _tryN suffix.
  3. 10:37:56.104 loadPartAndFixMetadataImpl on the attaching directory throws NO_FILE_IN_DATA_PART (no count.txt), so the code quarantines the part with renameToDetached("broken").
  4. 10:37:56.224 that rename fails, ENOENT on detached/broken_detached/attaching_all_94_94_0. The part is built with part_dir equal to detached/attaching_all_94_94_0, and DataPartStorageOnDiskBase::getPartDirForPrefix prepends the prefix to the whole part_dir, so the target becomes detached/ plus broken_detached/attaching_all_94_94_0, whose parent does not exist. Because that rename threw, the old_dir.clear() that would have made the rollback a no-op is skipped.
  5. 10:37:56.333 PartsTemporaryRename::rollBackAll renames attaching_all_94_94_0 back to all_94_94_0, which step 2 has re-taken: ATOMIC_RENAME_FAIL, caught and logged.

detached/attaching_all_94_94_0 is now orphaned, and every later ATTACH PARTITION on that table renames detached/all_94_94_0 onto that same occupied name and fails identically: 11 such events between 10:37:56.587 and 10:38:07.912, 10 of them reaching clients as Code: 521. The last one is the test's only unfiltered ATTACH, which is what turns this into a test failure.

Outside the test, ATTACH PARTITION for that partition stays broken on that replica until detached/attaching_* is removed by hand, and the broken part is never quarantined into broken_*.

rollBackAll and getPartDirForPrefix are the same on master, so this is not specific to 25.8. Master is quiet only because #86128 tagged the test disabled and was never backported, which makes 25.8 the only active branch where it still runs.

No open PR fixes this signature. I will fix it on master and link the PR here. Clearing this red on 25.8 will then need v25.8-must-backport on that PR once it merges.

@groeneai

Copy link
Copy Markdown
Collaborator

Fixed on master in #116734.

The quarantine rename in the replicated ATTACH_PART path could never succeed. The part is built
with a detached/-qualified part_dir and renameToDetached derives the target from it, so it aimed
at detached/broken_detached/attaching_<part>, whose parent does not exist. The broken part is
therefore never quarantined and the rollback runs instead; in your run that rollback collided with a
name a concurrent DETACH had re-taken, which is the ATOMIC_RENAME_FAIL on
detached/attaching_all_94_94_0, and it left that directory orphaned. Every later
ATTACH PARTITION for the partition then failed on it. No concurrency is needed to reach the dead
branch itself: it has never once succeeded since 2025-06-04, when the quarantine was introduced as a
local rename inside detached/ and replaced by renameToDetached the same day.

This is a different signature from the 2026-08-16 failure on another PR (Code: 76, errno 13, on
detached/attaching_*/metadata_version.txt). That one was fixed by #87838, backported to 25.8 as
#115009, and has held.

02443_detach_attach_partition is tagged disabled on master (#86128, never backported), so 25.8 is
the only branch where it still runs. I will ask for the backport label once #116734 is merged.

@alexey-milovidov
alexey-milovidov merged commit fa9699c into 25.8 Aug 27, 2026
33 checks passed
@alexey-milovidov
alexey-milovidov deleted the backport/25.8/115334 branch August 27, 2026 20:07
qiuyanjun888 pushed a commit to qiuyanjun888/ClickHouse that referenced this pull request Sep 20, 2026
A replicated `ATTACH_PART` log entry claims a candidate directory in
`detached/` by renaming it to `attaching_<dir>`, builds the part with a
two-component `part_dir` (`detached/attaching_<dir>`) and loads it. When
the load throws a non-retryable exception the part must be renamed aside
under a `broken_` prefix so it stops being an attach candidate, and
`old_dir` is then cleared so the rollback becomes a no-op.

That rename could never succeed. `renameToDetached` routes through
`DataPartStorageOnDiskBase::getPartDirForPrefix`, which appends `part_dir`
verbatim, and `getRelativePathForDetachedPart` prepends `detached/` again,
so the target is `detached/broken_detached/attaching_<dir>` and its parent
does not exist. The `_tryN` existence probe passes for the same reason, so
no retry fires. The rename dies with ENOENT, `old_dir` is left set, and
the broken part stays an attach candidate, so every later
`ATTACH PARTITION` for that partition keeps failing on it. No concurrency
is required.

This is a regression. a5eeba9 introduced
the quarantine as a local rename inside `detached/`, and
56cd154, under three hours later the
same day, replaced it with `part->renameToDetached("broken", false)`
while adding the correct retryable/non-retryable split. The branch has
been dead on arrival since.

Restore the local rename, targeting a free `detached/broken_<dir>[_tryN]`.
`broken_<dir>` parses with a non-empty prefix and a valid name, so it is
excluded from both attach candidate filters and stays removable by both
`DROP DETACHED PART` and `DROP DETACHED PARTITION`; routing through the
generic allocator would instead produce a name that does not parse, which
`DROP DETACHED PARTITION` skips. The target is handed to `renameTo`
explicitly, with `remove_new_dir_if_exists` false, so the rename refuses
an occupied directory instead of recursively removing a part an earlier
quarantine put there, and the collision advances to the next `_tryN` name.
`renameToDetached` cannot be reused for this because it passes true. On
any other error, or when the last attempt collides, the exception is
rethrown so the failure is logged, `old_dir` is left set and the rollback
runs as before.

Nothing generic changes and the branch has no working caller to regress.
A rollback whose target base name was re-taken concurrently can still
orphan `attaching_<dir>`, and the claim can still take a directory a
concurrent `DETACH` is populating; neither is addressed here.

Add an integration test rather than a functional one, because it has to
remove `count.txt` from a part directory inside `detached/`.

Reported on ClickHouse#116258
CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=116258&sha=629bd7e0f725f065b6ea8e783f98ae4b3e28e067&name_0=BackportPR&name_1=Stateless%20tests%20%28amd_asan%2C%20distributed%20plan%2C%20parallel%2C%202%2F2%29
Related: ClickHouse#54748
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backport Changes, backported to release branch. Do not use manually - automated use only! pr-critical-bugfix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants