Skip to content

Backport #113224 to 26.3: Do not read the internal database of temporary tables in Merge - #113929

Merged
alexey-milovidov merged 2 commits into
26.3from
backport/26.3/113224
Aug 9, 2026
Merged

alexey-milovidov merged 2 commits into
26.3from
backport/26.3/113224

Conversation

@robot-clickhouse-ci-1

@robot-clickhouse-ci-1 robot-clickhouse-ci-1 commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Original pull-request #113224
Cherry-pick pull-request #113880

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.3.18.13

@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added pr-backport Changes, backported to release branch. Do not use manually - automated use only! pr-critical-bugfix labels Aug 8, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [BackportPR], commit [959a732]

Summary: ✅

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Both failed checks are unrelated to this backport (the StorageMerge temporary-database guard):

Merged 26.3 into the branch and pushed to refresh CI.

@groeneai, investigate the 04238_alter_rename_column_merge_race flakiness on master: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=113929&sha=731b917fb0a2533da48dc46dc334bd30c8570bfe&name_0=BackportPR&name_1=Stateless%20tests%20%28amd_asan%2C%20distributed%20plan%2C%20parallel%2C%201%2F2%29 and provide a fix in a separate PR. If the fix is already in progress, link it here.

@groeneai

groeneai commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

@alexey-milovidov That report is not a master flake. It is deterministic data loss that only fires on 26.3, and it already has a verified one-line fix that I have not published because the route to land it needs your decision.

The row you linked carries the data-loss oracle. Commit 731b917fb0a2, base_ref = 26.3: FAIL on iteration 17: expected 10 non-empty rows, got 0. The renamed column reads back empty for all 10 rows.

Last 30 days in default.checks, split by lineage and by failure signature:

lineage OK data-loss FAIL other FAIL
master, plus PRs based on master 82,762 0 14
26.3 1,048 22 0

Those 14 are 13 MEMORY_LIMIT_EXCEEDED at current RSS: 41.84 GiB, maximum: 41.84 GiB (11 of them on 2026-07-15 alone) plus one Internal query (CREATE/DROP DATABASE) failed. They exit with code 1, so they share the return code: 1 reason string with the data-loss rows, which is probably where the master-wide reading comes from. Over 90 days master lineage has exactly one data-loss row: 2026-07-02, on the pre-merge branch of the fix itself, one commit behind its own merge commit. Zero since. There is also no retry_ok matcher issue for this test: the test name has 19 hits in this repo and every one is a PR.

Why 26.3 only. IStorage::getInMemoryMetadataPtr takes a defaulted bool on 26.3 (IStorage.h:212) and a mandatory (ContextPtr, bool) on master (IStorage.h:229). So master's merge-selection read getInMemoryMetadataPtr(getContext(), false) (StorageMergeTree.cpp:1764) cherry-picked as the bare getInMemoryMetadataPtr() (26.3:StorageMergeTree.cpp:1666), which consults MergeTreeData's per-query metadata cache. OPTIMIZE fills that cache with the pre-ALTER snapshot and then merges synchronously on the query thread, so the read under the mutex returns the stale snapshot. The cherry-pick compiled cleanly and lost the fix's meaning.

The fix is one line at that site, passing bypass_metadata_cache = true. Measured on 26.3 both directions: 16/7000 iterations lose data without it and 0/7000 with it (Fisher exact 3.0e-05); 30/7000 against 0/7000 in a crossover arm with the two binaries swapped onto each other's ports; and 80 runs of the unmodified test per arm give 77 OK / 3 FAIL carrying the exact CI signature, against 80 OK / 0 FAIL.

The decision I need. Master is immune by construction, so there is no master commit for a backport label to cherry-pick, and @ pufit's rule stops me hand-authoring a release-branch fix. I asked about this on 2026-08-07: #104822 (comment). Say the word and I will open the 26.3-only PR with the one-line change and this evidence.

One input for that call: @ yariks5s asked not to backport 104822 because it broke the sync builds, and the 26.3 backport merged about 34 hours later with that concern still open. If the answer is that 26.3 should not carry this fix at all, I will send a PR disabling the test there instead.

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 @groeneai Thank you for the correction — you are right, and my "master-wide flake" attribution above was wrong. I verified the code claim: on 26.3, IStorage::getInMemoryMetadataPtr takes a defaulted bool bypass_metadata_cache = false, so the merge-selection site (StorageMergeTree.cpp:1666) that master spells as getInMemoryMetadataPtr(getContext(), false) cherry-picked as the bare call and reads the per-query cached (pre-ALTER) snapshot — the exact stale-metadata read that #104822 closed. The evidence (0/7000 with the fix vs 16/7000 and 30/7000 without, crossover arm, and the reproduced CI signature) settles it.

Please open the 26.3-only PR with the one-line bypass_metadata_cache = true change and this evidence, and link it here. Rationale for going ahead:

  • The backport of Fix race between ALTER RENAME COLUMN and merge causing data loss (#80648) #104822 has already merged into 26.3, so this is not a new hand-authored release-branch fix — it restores the intended semantics of a backport the branch already carries. The rule against release-branch-only fixes is about divergence from master; here master is immune by construction and the divergence already exists (in the wrong direction).
  • Disabling the test instead would mask deterministic data loss on a supported release branch — not an option.
  • Regarding the sync-build concern from the 26.3 backport of Fix race between ALTER RENAME COLUMN and merge causing data loss (#80648) #104822: this one-liner changes no signatures and only a call site, so it does not reintroduce that problem; if the sync issue with the original backport is still open, it should be tracked separately.

Use the "Bug Fix" changelog category and put Related: https://github.com/ClickHouse/ClickHouse/pull/104822 and a link to this thread in the description.

@groeneai

groeneai commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator

Acknowledged, and thank you for the authorization and for spelling out the rationale.

Re-confirmed at the live 26.3 head before starting, so the one-line change still applies as described: IStorage.h:212 declares getInMemoryMetadataPtr(bool /*bypass_metadata_cache*/ = false), and StorageMergeTree.cpp:1666 is the bare call sitting directly under the See #80648 comment that the backport brought over.

I am opening the 26.3-only PR with the Bug Fix category, a Related: link to 104822, a link to this comment as the authorization, and the verification numbers in the description. I will link it here.

@groeneai

Copy link
Copy Markdown
Collaborator

Opened as requested: #114913. It is 26.3-only, one line at StorageMergeTree.cpp:1666, Bug Fix category, with the evidence and a link to your authorization above in the description.

kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Aug 24, 2026
…g Parquet record batches

After the `arrow` 25.0.0 bump (ClickHouse#113539), an allocation failure inside
`RecordBatchReader::Next` surfaces as an arrow `OutOfMemory` status instead of
propagating the memory-tracker exception, so the error was reported as
`CANNOT_READ_ALL_DATA` (33) instead of `MEMORY_LIMIT_EXCEEDED` (241), making
`03147_parquet_memory_tracking` flaky on 26.3. Map `IsOutOfMemory` to
`MEMORY_LIMIT_EXCEEDED` at this call site, like the `THROW_ARROW_NOT_OK` macro
already does.

Seen in: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=113929&sha=731b917fb0a2533da48dc46dc334bd30c8570bfe&name_0=BackportPR&name_1=Stateless%20tests%20%28amd_asan%2C%20db%20disk%2C%20distributed%20plan%2C%20sequential%29
On PR: ClickHouse#113929

Co-Authored-By: Claude Fable 5 <[email protected]>
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