Skip to content

Fix flaky/slow test_s3_glob_scheherazade - #110167

Merged
alexey-milovidov merged 3 commits into
ClickHouse:masterfrom
groeneai:fix-test-s3-glob-scheherazade-flaky
Jul 12, 2026
Merged

alexey-milovidov merged 3 commits into
ClickHouse:masterfrom
groeneai:fix-test-s3-glob-scheherazade-flaky

Conversation

@groeneai

@groeneai groeneai commented Jul 12, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #110165

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

test_s3_glob_scheherazade was slow (~10 min/run) and flaky. It wrote 1001 night_<i>/tale.csv objects with 30 Python threads each doing sequential single-row INSERT ... VALUES round-trips. Under ASan-server load a writer connection hit Code: 210 Broken pipe (NETWORK_ERROR) and the thread died silently (threading.Thread swallows the exception, join() returns), so the following glob read a partial object set and returned a short count() (e.g. 509/779/783 instead of 1001). It is a write-side race, not an S3 listing bug.

Replaces the threaded writer with server-side partitioned inserts, batched to bound the number of concurrently open partition write buffers. All 1001 objects are written without client threads or ~1000 round-trips. column1 carries the night index, so the assertion is strengthened to 1001 500500 1001 1001 (sum(column1) = 0+...+1000), verifying every distinct file exists.

Verified locally: the test passes in ~34s (was ~10 min and failing 3/3 in the flaky check).

Reported from @ alexey-milovidov's investigation on #109310.

Version info

  • Merged into: 26.7.1.836 (included in 26.7 and later)

The test wrote 1001 night_<i>/tale.csv objects with 30 Python threads,
each doing a sequential single-row INSERT ... VALUES round-trip to S3
(~1001 round-trips, ~10 min). Under ASan-server load a writer connection
hit Code: 210 Broken pipe (NETWORK_ERROR); the thread died silently
(threading.Thread swallows the exception, join() returns), so the glob
then read a partial object set and returned a short count (e.g. 509/779/783
instead of 1001). It is a write-side race, not an S3 listing bug.

Replace the threaded writer with server-side partitioned inserts, batched
to bound the number of concurrently open partition write buffers. All 1001
objects are written without client threads or ~1000 round-trips. column1
carries the night index, so the assertion is strengthened to 500500 for
sum(column1), verifying every distinct file exists.

Closes: ClickHouse#110165
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. CI showed 3/3 failures in Integration tests (amd_asan_ubsan, flaky); from the gw0 logs only 514/1001 inserts were issued and 491 finished before the SELECT, with Code: 210 Broken pipe (NETWORK_ERROR) on the writer connections.
b Root cause explained? 30 threading.Thread writers do sequential single-row S3 INSERT ... VALUES. A writer thread that hits a transient network error dies silently (Thread swallows the exception, join() returns), so the glob reads a partial object set → short count. Slowness = ~1001 sequential client round-trips.
c Fix matches root cause? Yes. Removes the threaded/round-trip writer entirely and writes all objects with server-side partitioned inserts, so there is no client thread to die and no ~1000 round-trips.
d Test intent preserved / strengthened? Strengthened. Still writes 1001 distinct night_*/tale.csv objects and globs >1000 objects. column1 now carries the night index, so the assertion checks sum(column1)=500500, proving every distinct file was written (the old assert only summed constant 1s).
e Demonstrated in both directions? Fails without fix (3/3 in CI, short counts). Passes with fix locally (1 passed in 32.6s) — verified on a master-based branch.
f Fix general, not a narrow patch? N/A (test-only change; no product code touched).
g Generalizes across inputs? N/A (test-only change).
h Backward compatible? N/A (test-only change).
i Invariants/contracts preserved? N/A (test-only change). PartitionedSink writes each partition as its own object; max_partitions_per_insert_block is MergeTree-only, so 1001 partitions across batched inserts is fine, and batching bounds concurrently-open S3 write buffers.

Session id: cron:clickhouse-worker-slot-1:20260712-154900

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @kssenii — could you review this? It rewrites test_s3_glob_scheherazade to write the 1001 objects with server-side partitioned inserts instead of 30 Python threads doing sequential single-row S3 inserts, fixing a silent-thread-death write race (short counts) and the ~10 min runtime.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Jul 12, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [4d3c38f]

Summary: ✅


AI Review

Summary

This PR rewrites the two S3 glob integration tests that exercise the >1000-object boundary to use synchronous server-side partitioned inserts and direct object-cardinality checks, removing the silent worker-thread failure mode that made them slow and flaky. In the current code, the earlier review concerns are addressed and I did not find any remaining correctness, coverage, or PR-metadata issues that need a new inline comment.

Final Verdict

✅ No remaining review findings in the current diff.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jul 12, 2026
Add a direct object-count assertion (len(list_objects(prefix=night_)) == 1001)
after the partitioned writes, so the test still proves the glob lists more than
1000 separate objects even if partitioned writes ever coalesced partitions into
fewer objects. Keep the row-level count()/sum(column1) query as a second check.

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

Copy link
Copy Markdown
Collaborator Author

Done in 5cddba9. Added a direct object-cardinality assertion right after the writes and kept the row-level query as the second check:

night_objects = list(
    started_cluster.minio_client.list_objects(
        bucket, prefix="night_", recursive=True
    )
)
assert len(night_objects) == 1001

This restores the >1000-object listing-boundary contract: if partitioned writes ever coalesced partitions into fewer night_*/tale.csv objects, len(...) == 1001 fails even though the row-level count()/sum(column1) would still pass. Verified locally against MinIO (python3 -m ci.praktika run "integration" --test "test_storage_s3/test.py::test_s3_glob_scheherazade"): 1 passed in 36.47s.

Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Original flaky failure was a write-side race (a threaded single-row writer hit Code 210 Broken pipe under ASan-server load, died silently, glob then read a short object set). The PR's batched server-side partitioned insert removes the client threads/round-trips entirely; test now passes deterministically.
b Root cause explained? Bot concern: count()+sum(column1) only proves 1001 rows round-trip; it does not prove the glob lists >1000 distinct objects. If partitioned writes coalesced partitions into fewer objects, the row assertion would still pass and stop exercising the >1000-object listing boundary.
c Fix matches root cause? Yes — asserts object cardinality directly (len(list_objects(prefix="night_", recursive=True)) == 1001), which is exactly the contract the bot flagged as no longer proven.
d Test intent preserved / new tests added? Strengthened: the direct object-count assert is added, the row-level count()/sum(column1) check is kept as a second check. The scheherazade >1000-object intent is now explicitly asserted.
e Both directions demonstrated? New assertion passes with the current partitioned-insert writer (1001 objects written, 1001 listed). It would fail if objects coalesced (the scenario the bot raised), which the row-level check alone could not catch.
f Fix is general across code paths? N/A (integration test assertion change, not a code bug).
g Fix generalizes across inputs? N/A (integration test assertion change, not a code bug).
h Backward compatible? N/A (integration test assertion change, not a code bug).
i Invariants and contracts preserved? Yes — restores the scheherazade >1000-distinct-object listing-boundary contract that the row-level check alone did not guarantee.

Session id: cron:clickhouse-worker-slot-0:20260712-173400

Same server-side partitioned insert rewrite applied to the sibling test:
replace the fire-and-forget threaded single-row writers (whose
QueryRuntimeException would die silently in the worker and let the final
count go short) with batched server-side partitioned inserts, and assert
the folder1 object cardinality (len == 1008) directly so a coalescing of
partitions can no longer pass unnoticed.

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

Copy link
Copy Markdown
Collaborator Author

Applied the same rewrite to the sibling test_s3_glob_many_objects_under_selection in this PR (commit 4d3c38f). The 16 fire-and-forget threading.Thread writers doing single-row INSERT ... VALUES are replaced with batched server-side partitioned inserts (partition by column1, folder1/file{_partition_id}.csv), so a QueryRuntimeException now surfaces synchronously instead of dying in a worker. Added a direct object-cardinality check len(list_objects(bucket, prefix="folder1/", recursive=True)) == 1008 right after the writes, and kept the row-level glob query as a second check (now count()=1009, sum(column1)=507529).

Verified locally against MinIO: 1 passed in 33.62s.

Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes — old form let a threaded writer die on Code 210 Broken pipe under load, leaving folder1 short of 1008 objects; the glob count() then read a partial set.
b Root cause explained? Fire-and-forget threading.Thread workers each ran sequential single-row inserts; a QueryRuntimeException in a worker was swallowed, join() returned OK, and count() went short — identical to the scheherazade flake.
c Fix matches root cause? Yes — removes the threaded writer entirely; inserts run server-side on the main connection, so any write error propagates and fails the test loudly.
d Test intent preserved? Yes — still writes 1008 objects under folder1/ + 1 under folder2/ and exercises the folder{1,2}/file*.csv glob over the >1000-object listing boundary; strengthened, not weakened.
e Demonstrated both directions? Rewrite passes deterministically (1 passed, 33.62s); the removed threaded path was the source of the intermittent short-count.
f Fix general, not narrow patch? Yes — mirrors the scheherazade fix in the same file; both sibling tests now use the same safe write path.
g Generalizes across inputs? N/A (integration test rewrite, not a code bug).
h Backward compatible? N/A.
i Invariants preserved? N/A.

Session id: cron:clickhouse-worker-slot-4:20260712-181200

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 4d3c38f

Finish Workflow, Mergeable Check, and PR all green. Zero failures (49 pass, 125 skipping). Both clickhouse-gh[bot] change-requests addressed (direct object-cardinality asserts for test_s3_glob_scheherazade and the sibling test_s3_glob_many_objects_under_selection).

Session id: cron:our-pr-ci-monitor:20260712-210000

@alexey-milovidov alexey-milovidov self-assigned this Jul 12, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 12, 2026
Merged via the queue into ClickHouse:master with commit b2a474e Jul 12, 2026
176 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 12, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…cheherazade-flaky

Fix flaky/slow test_s3_glob_scheherazade
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-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky/slow integration test: test_s3_glob_scheherazade (concurrent-write race + ~10 min runtime)

3 participants