Skip to content

Fix flaky test_s3_plain_rewritable: opt in to legacy REPLACE PARTITION from empty source - #108350

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-s3-plain-rewritable-replace-empty-partition
Jun 25, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-s3-plain-rewritable-replace-empty-partition

Conversation

@groeneai

@groeneai groeneai commented Jun 24, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

...

Description

Fixes flaky test_s3_plain_rewritable/test.py::test.

#104939 (fixing the silent data loss in #23727) made ALTER TABLE ... REPLACE PARTITION ... FROM ... from a source that has no parts in the requested partition throw BAD_ARGUMENTS by default, gated behind the new allow_replace_partition_from_empty_source setting. It updated the affected stateless tests but missed this integration test.

The test inserts random.randint(1, MAX_ROWS) rows with consecutive ids (PARTITION BY id % 10). When a node draws a row count of 1, only id=0 exists, so partition 1 of test is empty. The test then does MOVE PARTITION 0 TO test_dst (emptying test) followed by REPLACE PARTITION 1 FROM test, which now reads an empty source partition and throws.

This surfaced as a low-rate flake (~0.05% of master runs) across the asan/tsan/msan integration builds within hours of #104939 merging.

Fix: pin allow_replace_partition_from_empty_source = 1 on the REPLACE PARTITION query to restore the legacy no-op semantics the test relies on, matching the fix applied to the stateless tests in #104939. The destination partition 1 is also empty at that point, so no data is lost and the existing assertions (count_dst > 0, count_dst == count_part_0 + count_part_1) still hold.

CI report (one of the failures): https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=105387&sha=fb91a686249e35a738fd3be8f2fb480dc39ddc95&name_0=PR&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20db%20disk%2C%20old%20analyzer%2C%204%2F6%29

Version info

  • Merged into: 26.7.1.85 (included in 26.7 and later)
  • Backported to: 26.6.2.10

…N from empty source

When a node's random row count (random.randint(1, MAX_ROWS)) is 1, only id=0
exists, so partition 1 of `test` is empty. After MOVE PARTITION 0 TO test_dst,
`test` is empty and REPLACE PARTITION 1 FROM test reads an empty source partition.

ClickHouse#23727 (PR ClickHouse#104939) made REPLACE PARTITION from an empty source partition throw
BAD_ARGUMENTS by default, gated by allow_replace_partition_from_empty_source. That
PR updated the affected stateless tests but missed this integration test, which then
failed intermittently (~0.05% of master runs across asan/tsan/msan once ClickHouse#104939 merged).

Pin allow_replace_partition_from_empty_source=1 on the REPLACE query to restore the
legacy no-op semantics the test relies on, matching the fix applied to the stateless
tests in ClickHouse#104939. The destination partition 1 is also empty here, so no data is lost.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate

# Question Answer
a Deterministic repro? Yes. With a master binary (contains #104939), clickhouse local: CREATE test/test_dst (PARTITION BY id%10); INSERT INTO test VALUES (0,'a'); ALTER TABLE test MOVE PARTITION 0 TO TABLE test_dst; ALTER TABLE test_dst REPLACE PARTITION 1 FROM test; throws Code 36 / BAD_ARGUMENTS: Source table ... has no parts in partition 1: refusing REPLACE PARTITION ... every time. This is the exact CIDB error (first seen 2026-06-23 23:58, only 3 occurrences ever, all in this test).
b Root cause explained? The test inserts random.randint(1, MAX_ROWS) rows with consecutive ids and PARTITION BY id % 10. When a node draws row count 1, only id=0 exists so partition 1 is empty; after MOVE PARTITION 0 TO test_dst, test is empty, and REPLACE PARTITION 1 FROM test reads an empty source partition. #104939 (fix for #23727) made empty-source REPLACE PARTITION throw BAD_ARGUMENTS by default (gated by allow_replace_partition_from_empty_source); it updated the stateless tests but missed this integration test.
c Fix matches root cause? Yes. Pin allow_replace_partition_from_empty_source = 1 on the REPLACE query to restore the legacy no-op semantics the test relies on, identical to the fix #104939 applied to its own stateless tests (00626, 02486, 03100). Not a band-aid: it targets the exact behavior change.
d Test intent preserved / new tests added? Preserved. The test still exercises MOVE/REPLACE PARTITION on s3_plain_rewritable disks and keeps both assertions (count_dst > 0, count_dst == count_part_0 + count_part_1). Verified they hold in the size==1 edge case (count_part_0=1, count_part_1=0, count_dst=1) and the size>=2 case (1+2=3). No new test needed: this is a test-only fix to an existing behavior-change-induced flake, not a code bug.
e Both directions demonstrated? Yes. Without the setting: REPLACE PARTITION 1 from empty source throws Code 36. With SETTINGS allow_replace_partition_from_empty_source = 1: succeeds (count_dst=1), no data loss (destination partition 1 is also empty).
f Fix is general across code paths? N/A (test setting fix, not a code bug). Checked siblings anyway: scanned all integration tests using REPLACE PARTITION — only this test uses a random (possibly single-row) source. test_s3_plain_rewritable_rotate_tables uses a fixed 1000-row source (partition 1 never empty); others use deterministic non-empty sources or are negative tests. CIDB confirms the new error has only ever fired in this one test.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (test setting fix, not a code bug). The three parametrized variants (s3_plain_rewritable, cache_s3_plain_rewritable, s3_plain_rewritable_with_metadata_cache) share the same code path; the setting applies to all.
h Backward compatible? (maintainer-approved exception only) N/A (test setting fix, not a code bug). No production behavior change; the new behavior and its compatibility were already handled in #104939 (SettingsChangesHistory updated there).
i Invariants and contracts preserved? N/A (test setting fix, not a code bug). The setting restores the documented legacy semantics for the empty-source case; the destination partition being replaced is empty, so the REPLACE is a no-op and all data-count invariants the test asserts continue to hold.

Session id: cron:clickhouse-worker-slot-0:20260624-040200

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @CheSema — follow-up to #104939: that PR made empty-source REPLACE PARTITION throw by default but missed this integration test, which does REPLACE PARTITION 1 FROM test where partition 1 is empty whenever a node's random row count is 1. Pins allow_replace_partition_from_empty_source = 1 to restore the legacy no-op semantics the test relies on, matching the stateless-test fixes in #104939.

@tiandiwonder tiandiwonder self-assigned this Jun 24, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [6310f67]

Summary: ✅


AI Review

Summary

This PR fixes the test_s3_plain_rewritable integration-test flake by opting the specific REPLACE PARTITION query into the legacy empty-source behavior. The changed query matches the described edge case: after MOVE PARTITION 0, destination partition 1 is empty, so allowing the empty-source no-op does not hide a data-loss path, and the existing count assertions still cover the intended result.

Final Verdict

Status: ✅ Approve

@tiandiwonder tiandiwonder added the can be tested Allows running workflows for external contributors label Jun 24, 2026
@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jun 24, 2026
count_part_1 = int(node.query("SELECT count(*) FROM test WHERE id % 10 = 1"))
node.query("ALTER TABLE test_dst REPLACE PARTITION 1 FROM test")
# Source partition 1 is empty when this node's random row count was 1 (only id=0).
# Opt in to the legacy no-op semantics; #23727 made empty-source REPLACE PARTITION throw by default.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional: the attribution here is a bit off — #23727 is the original silent-data-loss issue, but the empty-source REPLACE PARTITION throw-by-default was introduced by the fix in #104939. Worth pointing the comment at #104939 so a future reader finds the actual behavior change.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 6310f67 — comment now reads "#104939 (fix for #23727) made empty-source REPLACE PARTITION throw by default", so a reader lands on the actual behavior change while keeping the original issue as context.

…r change), keep ClickHouse#23727 as original issue

Per review on PR ClickHouse#108350: ClickHouse#104939 (the fix for ClickHouse#23727) introduced the
empty-source REPLACE PARTITION throw-by-default; reference it so future
readers find the actual behavior change.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.30% 85.30% +0.00%
Functions 92.50% 92.50% +0.00%
Branches 77.60% 77.50% -0.10%

Changed lines: No C/C++ source files changed — skipping uncovered code analysis.

Newly covered by added/modified tests: 275 line(s), 50 function(s) across 104 file(s) · Details

Top files
  • src/Processors/Formats/Impl/Parquet/Decoding.cpp: 16 line(s)
  • src/AggregateFunctions/TimeSeries/AggregateFunctionTimeseriesLinearRegression.h: 14 line(s), 32 function(s)
  • src/Parsers/parseFieldFromCastedLiteral.cpp: 10 line(s), 11 function(s)
  • src/Functions/array/arrayUniq.cpp: 9 line(s)
  • src/Storages/MergeTree/ReplicatedMergeTreeQueue.cpp: 7 line(s)

Full report

@alexey-milovidov
alexey-milovidov merged commit 2b4ed4f into ClickHouse:master Jun 25, 2026
166 of 167 checks passed
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 25, 2026
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Jun 28, 2026
robot-ch-test-poll4 added a commit that referenced this pull request Jun 28, 2026
Cherry pick #108350 to 26.6: Fix flaky test_s3_plain_rewritable: opt in to legacy REPLACE PARTITION from empty source
robot-clickhouse added a commit that referenced this pull request Jun 28, 2026
…to legacy REPLACE PARTITION from empty source
@robot-clickhouse robot-clickhouse added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Jun 28, 2026
clickhouse-gh Bot added a commit that referenced this pull request Jun 28, 2026
Backport #108350 to 26.6: Fix flaky test_s3_plain_rewritable: opt in to legacy REPLACE PARTITION from empty source
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…r change), keep ClickHouse#23727 as original issue

Per review on PR ClickHouse#108350: ClickHouse#104939 (the fix for ClickHouse#23727) introduced the
empty-source REPLACE PARTITION throw-by-default; reference it so future
readers find the actual behavior change.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…ain-rewritable-replace-empty-partition

Fix flaky test_s3_plain_rewritable: opt in to legacy REPLACE PARTITION from empty source
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-ci pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.6-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants