Skip to content

Backport #109356 to 26.6: Fix data loss when a merge races ALTER RENAME COLUMN on a column without a default expression - #112625

Merged
clickhouse-gh[bot] merged 2 commits into
26.6from
backport/26.6/109356
Aug 1, 2026
Merged

clickhouse-gh[bot] merged 2 commits into
26.6from
backport/26.6/109356

Conversation

@robot-ch-test-poll4

@robot-ch-test-poll4 robot-ch-test-poll4 commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Original pull-request #109356

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: 26.6.2.138

…ME COLUMN on a column without a default expression
@robot-ch-test-poll4 robot-ch-test-poll4 added pr-backport Changes, backported to release branch. Do not use manually - automated use only! pr-critical-bugfix labels Jul 30, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [BackportPR], commit [7fd1d87]

Summary: ✅

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 @groeneai, please investigate this infra failure: Integration tests (amd_asan_ubsan, db disk, old analyzer, 5/6) — it has now hung twice in a row on this PR, at the same point.

Evidence that it is a runner-level wedge, not a test failure and not caused by this backport:

I have merged 26.6 into the branch to trigger a fresh run on different runners.

@groeneai

groeneai commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the writeup. I investigated; three corrections and a likely mechanism.

1. It has now failed five times, including on the fresh run you triggered. All four attempts of run 30557613017 wedged on shard 5/6, each on a different instance, and so did the rerun after you merged 26.6:

attempt runner job start to GitHub finalizing the job
1 i-09b46737c5199148d 54.1 min
2 i-06d4a3a30e9a534e7 49.0 min
3 i-0be1e37412d88833b 49.0 min
4 i-00d543cdfe3899352 51.0 min
rerun 30693078875 i-0acf108988791bc7a 51.1 min

Five distinct on-demand instances, so it is not one bad machine, and different runners did not help. For the rerun I can so far only confirm the shape: GitHub marked the job failed at 51.1 min while its Run step is still in_progress and the log is not published yet, which is the same ordering as attempt 4 below.

2. The job is finalized about 50 minutes before the runner notices. For attempt 4 the API reports completed_at 14:25:34 and Finish Workflow started 14:25:37, yet the runner's own log keeps writing until 15:39:21 and only logs The operation was canceled. at 15:15:21. The delay from the log stream going quiet to finalization is 10.2 min (attempt 4) and 9.7 min (attempt 3), which matches a runner heartbeat timeout, not a harness bound: neither log has a praktika Job timed out marker, the job timeout is 5 h (the config sets none, so it inherits Job.Config.timeout), and --session-timeout=7200 never fired.

3. The 60 minutes is not a constant. Measured silences are 59.7 min (attempt 4) and 39.5 min (attempt 3). What is constant is the 49 to 54 min above.

Mechanism. All three xdist workers report FAILED within the same 2.28 ms, so one event ended them, not three independent timeouts. With git version then taking 24 min, the host was starved, not only the test process. The container gets --memory=64183246848, that is 59.78 GiB of a 61.78 GiB host, leaving 2.00 GiB for the runner agent, dockerd and the kernel. ci/defs/job_configs.py already documents this for the same image, in the comment above KEEPER_DIND_MEM: "Using nearly all host RAM for the outer container can starve the host runner and lead to runner lost communication. Reserve a larger margin on the host by capping Keeper to ~70% of physical memory." Keeper stress was capped for that reason; the regular integration job's common_integration_test_job_config still uses LIMITED_MEM, physical minus 2 GiB. The harness itself budgets far less: workers = min(ncpu // 5, mem_gb // 11) = 3, an assumed peak of 33 GiB.

Why this shard, deterministically: 26.6's 5/6 gets 144 modules with 268 add_instance declarations, including test_keeper_snapshot_chunked_transfer at 18 (12 Keeper nodes, 7 with MinIO) plus its test_concurrent.py at 10. The module list is byte-identical across attempts and --dist=loadfile pins modules to workers, so the same peak recurs at the same 61%. Your sibling comparison holds, but the shards are not comparable: 26.7's 5/6 has 201 modules and finished 1440 passed, 48 skipped in 5292.70s.

The backport is innocent independently of the sibling branches: changed_files is only src/Storages/MergeTree/MergeTask.cpp and the two 04648 stateless files, and changed_integration_tests is empty.

What I could not measure: these runs never reach the reporting stage, so there is no dmesg dump and no host memory metrics, and the report node is status: ERROR with duration: None and no links, which is why this class produces zero CIDB rows and is visible only in the Actions logs. So starvation is my best-supported explanation, not a measured one.

I will send a PR giving the regular integration job the same host margin as Keeper stress. That also moves the cgroup toward the 33 GiB the harness already budgets, so an overrun becomes a visible container cgroup event the OOM in dmesg check can catch instead of an invisible host wedge. Say so if you would rather I left the limit alone.

@clickhouse-gh
clickhouse-gh Bot merged commit 27e7400 into 26.6 Aug 1, 2026
76 of 78 checks passed
@clickhouse-gh
clickhouse-gh Bot deleted the backport/26.6/109356 branch August 1, 2026 12:33
@groeneai

groeneai commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator

The PR is open: #112984.

One correction to what I promised above. I said I would give the regular integration job the
same host margin as Keeper stress. I measured that change and it is inert for this failure:
lowering --memory alone does not bound the nested containers, because under --cgroupns=host
the nested daemon parents them at the host's /docker, a sibling of the job's own cgroup, so no
value of --memory reaches them. With the outer container capped at 1500 MiB, a resource-limited
nested child wrote 1900 MiB past it while the job's cgroup stayed at oom_kill 0. So the PR does
something different: the job asks for --cgroupns=private, which makes its own cgroup the
namespace root, docker_in_docker.sh delegates controllers there and caps three leaves whose sum
stays inside the job limit, and a failed precondition refuses to start the daemon rather than
running uncontained. LIMITED_MEM is untouched.

Two behaviour changes worth stating. Worker concurrency now derives from the containers' budget
rather than host memory, so --dist=each jobs drop from 3 workers to 2: they were budgeting
3 x 20 = 60 GiB inside what is now a 48 GiB cap. And an exhausted budget is now reported, because
capping the leaves moves the kill out of the host scope the dmesg check watched into a cgroup
where nothing was looking; the job reads each leaf's memory.events.local and fails with an
ERROR naming the leaf.

What this does not explain is the concentration on 26.6. The gap it closes is branch-invariant,
and I could not reproduce the host wedge itself: it needs the real runner and its 144-module
shard. So this closes a measured escape, and the reason 26.6 hits it while the sibling branches
do not remains open.

@groeneai

groeneai commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator

Correcting the PR I linked above: #112984 does not work on the CI runners, and the reason is
worth reporting here because it also constrains any future fix.

The runners boot with cgroup v1. From an integration job's dmesg.log:

Command line: BOOT_IMAGE=/boot/vmlinuz-6.8.0-1055-aws ... ro systemd.unified_cgroup_hierarchy=0

So /sys/fs/cgroup/cgroup.controllers does not exist, and neither do cgroup.subtree_control,
memory.max or memory.events.local. The containment I described (delegate controllers at the
job's own cgroup, cap three leaves inside the job limit) is cgroup v2 only, so on these hosts it
cannot engage. All six shards refused at startup rather than running uncontained. Six distinct
m7i.4xlarge instances, same kernel command line on all six, so it is an AMI property.

This is also why the equivalent block was left commented out in 2e12131a1de236a instead of
deleted: its [ -f /sys/fs/cgroup/cgroup.controllers ] guard made it a silent no-op on v1,
which is where master still is.

The measured escape I reported earlier stands (a nested child wrote 1900 MiB past a 1500 MiB
outer cap with the job's cgroup at oom_kill 0), but that was measured on a cgroup v2 machine.
On the v1 runners the same escape exists and the v2 remedy is unavailable, so bounding the
nested containers there needs memory.limit_in_bytes under /sys/fs/cgroup/memory/, a
different mechanism with different OOM reporting.

I have asked on the PR whether the CI team would rather move the runner AMI to cgroup v2 or
have the containment rewritten for v1. The AMI is not in this repo, so I cannot change it in a
PR, and I found no issue tracking such a migration. I am not going to make the precondition
fail open, since that would ship the guarantee without the containment.

The 26.6 concentration of the original wedge remains unexplained, as before.

groeneai added a commit to groeneai/ClickHouse that referenced this pull request Aug 15, 2026
The integration job runs under an outer `--memory` limit and starts a
nested Docker daemon, but its containers were charged outside that limit:
under `--cgroupns=host` dockerd parents them at the host's `/docker`, a
sibling of the job's cgroup. Measured, a resource-limited child wrote
1900 MiB past a 1500 MiB cap with the job's cgroup at `oom_kill 0`. The
limit bounded only the harness, while each test container defaults to 12g,
so an overrun starved the host instead of failing the job.

The job now asks for `--cgroupns=private`, making its own cgroup the
namespace root, and `docker_in_docker.sh` caps three leaves there: `/init`
for the harness, `/dockerd` for the daemons, `/docker` for the containers,
their sum inside the job limit so a leaf OOMs first. A failed precondition
refuses to start the daemon rather than running uncontained. Callers that
do not request containment take a byte-identical path.

Production is cgroup v1, which needs no `cgroup.subtree_control` but does
need the harness migrated into `/init` explicitly, and needs swap limited
per leaf or a leaf can exceed its cap by swapping. v2 has a separate
`memory.swap.max` that defaults to unlimited, so both versions are
limited, and a leaf that cannot be swap-limited refuses unless the host
provably has no swap.

`/init` holds more than pytest: `helpers/cluster.py` runs each node's
`clickhouse-client` and `helpers/iceberg_utils.py` runs Spark's `local`
driver on the host rather than in a container, so its cost tracks xdist
concurrency. It is a third of the job limit, floored at 8 GiB and capped
at 16, which leaves the 59.8 GiB carrier 40 GiB of container budget and
costs no worker; at 17 GiB the `--dist=each` plan would drop from 2 to 1.
Demand above a cap is never recorded, so each leaf's peak is printed
against its cap and flagged when the two are equal.

Two behavior changes. Worker concurrency derives from the nested budget
rather than host memory, so `--dist=each` drops from 3 workers to 2 - it
budgeted 3 x 20 = 60 GiB inside a 40 GiB budget. And an exhausted budget
is now reported instead of turning a resource kill into a green job: the
killed container's client raises `Connection reset by peer`, which
`_mark_infrastructure_errors` relabels `SKIPPED`, and `SKIPPED` counts as
successful. Reporting keys on the breached cgroup, so a container reaching
its own module's `mem_limit` stays unreported. On v1 a collective
`/docker` breach is only visible in dmesg, because the kill is charged to
the container and by teardown that cgroup is gone; a run without dmesg
says so rather than implying it checked.

Related: ClickHouse#112625
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Aug 15, 2026
The re-dump after the coverage merge used the return value of a best-effort
Shell.check nowhere, then reopened ./ci/tmp/dmesg.log unconditionally. A shell
redirect truncates the file when it OPENS it, so a command that merely exits
non-zero leaves it empty - but a redirect that cannot open the file at all
leaves the first scan's dump in place. Rereading that dates the evidence to
before the merge, which is the only window this second scan exists to cover, so
a /init kill during merge_profraw_files could still reach complete_job
unreported. The stale buffer also refilled late_dmesg, which suppressed the
dind_unreportable_leaves warning that keys on it being empty.

Guarding the read on the command's success is fail-closed without discarding
the report: on failure late_dmesg stays empty, so the counters remain the
source and the undetectable-leaf warning fires. strict=True was rejected -
the call sits before R.sort().complete_job(), which dumps the result and every
test row, so raising there would lose the whole report on a transient dmesg
failure.

The property had no oracle: reverting the guard left all 175 tests green,
because the existing late-scan test only pins where the call sits. Added an AST
test binding the read to the success check in the job script (kills both a bare
reread and a guard whose body does not contain the read) and a test running the
real redirect and Shell.check contract over all three outcomes.

Related: ClickHouse#112625
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.

5 participants