Skip to content

Use one source instead of N for parallel_inserts of AzureQueue/S3Queue (re-land #130864 with a fix) - #131689

Merged
alexey-milovidov merged 8 commits into
masterfrom
s3queue-max-files-override-reset
Nov 19, 2026
Merged

alexey-milovidov merged 8 commits into
masterfrom
s3queue-max-files-override-reset

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

Related: #130864
Related: #131691
Related: #98810
Related: #130904

Re-lands #130864 (reverted in #131691) together with a fix for the regression it exposed.

#130864: with parallel_inserts=1, the setting was never serialized into table metadata but was read from it to decide the parallelism of SELECTs, so it had no effect. Now it is not read from metadata, and each streaming task uses one source.

The fix: with one streaming task per processing thread, all tasks share max_files_override. When an INSERT fails (e.g. a CHECK constraint), the failing task halves the override so the bad file eventually lands alone in a batch and its retry count is reduced. But every successful commit reset the override to 0, including empty commits by idle tasks ("Successfully committed 0 files"), so the halving never took effect: the same batch (test_22.csv, test_999.csv, test_9999.csv) was retried forever without reducing retries, and the good file in it was never processed. Now the override is reset only after a batch which committed files, and only via compare-exchange from the value this iteration started with, so a task can't undo a halving made by another task meanwhile.

Also, the polling backoff is now kept per streaming task. All tasks shared reschedule_processing_interval_ms, so with N tasks every idle poll of each task added polling_backoff_ms (e.g. 4 tasks waited 121 s after one idle poll), and a reset by the task which found files did not shorten the waits of the others. Found from 05618_s3queue_alter_parallel_inserts timing out in #130904.

Also, with one processor per task, a task releases only the bucket locks of its own processors after its commit. Before, it released the finished locks of all processors, so in ordered mode it could release a bucket whose insert in another task was still running. And empty batches are now detected with a counter of acquired files that is kept regardless of the commit limits. Before, with max_processed_files_before_commit = 0 and a row or byte limit set, every batch looked empty, so the backlog was drained one batch per poll.

This fixes test_storage_s3_queue/test_parallel_inserts.py::test_parallel_inserts_with_failures[1-exclusive] (5 failures out of 532 runs after #130864, 0 before): https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=83b6da0324076eb3a1c8f1ea58fee8c57e24e757&name_0=MasterCI&name_1=Integration%20tests%20%28arm_binary%2C%20distributed%20plan%2C%204%2F4%29

Follow-up: #130904 recreates the streaming tasks when processing_threads_num is changed with ALTER (with one source per task, the number of tasks is otherwise fixed at table creation).

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Fix parallel_inserts of S3Queue/AzureQueue: the setting had no effect on the parallelism of reading, because it was read from table metadata where it was never stored.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/131689]

Version info

  • Merged into: 26.11.1.2822-master (included in 26.11 and later)

After #130864, `parallel_inserts=1` runs one streaming task per processing
thread. Every successful commit, including commits of empty batches by idle
tasks, reset the shared `max_files_override` to 0, undoing the halving done
by the task that hit a failing INSERT. The bad file then never ended up alone
in a batch, its retry count was never reduced, and good files batched together
with it were never processed.

Reset the override only after a batch which committed files, and only if no
other task changed it since this iteration started.

Failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=83b6da0324076eb3a1c8f1ea58fee8c57e24e757&name_0=MasterCI&name_1=Integration%20tests%20%28arm_binary%2C%20distributed%20plan%2C%204%2F4%29

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

clickhouse-gh Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [808b84c]

Summary: ✅


AI Review

Summary

Restores the intended source count for parallel_inserts in S3Queue and AzureQueue, protects batch-size reductions with failure generations, and corrects polling and bucket-release accounting. The earlier batch-reset, bucket-release, and empty-batch findings are addressed. One acknowledged regression remains deferred to the follow-up PR.

Missing context / blind spots
  • ⚠️ Targeted functional and integration jobs for head 808b84c3ff6d67ed278da38f282d5a7db28a74d3 were pending when inspected. No local ClickHouse binary or build directory was available; runtime validation still depends on those CI results.
Findings

⚠️ Majors

  • StorageObjectStorageQueue.cpp:1075: Allowed concurrency changes no longer take effect. [dismissed by author -- https://github.com/Use one source instead of N for parallel_inserts of AzureQueue/S3Queue (re-land #130864 with a fix) #131689#discussion_r4576700599] With parallel_inserts = 1, streaming tasks are created only in the constructor, while alter updates metadata without resizing them. Changing processing_threads_num from 4 to 1 still leaves four tasks inserting; increasing it likewise cannot increase concurrency until reattachment. This remains present in the current code despite the reported setting changing. The author deliberately defers task recreation to #130904, which remains open. Ship that fix with this change. The author-resolved thread is left resolved, with no repeated inline comment.
Final Verdict

Status: ⚠️ Request changes

Minimum required action: include the task-recreation fix from #130904 in the same rollout so supported ALTER operations retain their effect.

@clickhouse-gh clickhouse-gh Bot added pr-not-for-changelog This PR should not be mentioned in the changelog comp-s3queue S3Queue/AzureQueue engines (queue-based ingestion from object storage). labels Nov 14, 2026
@alexey-milovidov alexey-milovidov changed the title Do not let idle S3Queue/AzureQueue tasks reset the batch halving Use one source instead of N for parallel_inserts of AzureQueue/S3Queue (re-land #130864 with a fix) Nov 14, 2026
@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default and removed pr-not-for-changelog This PR should not be mentioned in the changelog labels Nov 14, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 808b84c3f with master 1439dc82b (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

1423 translation units recompiled, 224 s compile time in total, 1423 of them have a recent master baseline.

Job report

alexey-milovidov added a commit to groeneai/ClickHouse that referenced this pull request Nov 15, 2026
Runs the play.clickhouse.com "Failed checks" query (or decodes the query from
a play link), groups failures into kinds, classifies them with history
(first bad commit, release branches, flakiness onset), investigates the
unexplained ones with subagents, searches for existing issues and PRs, and
opens one PR per new fix. Written from the 2026-11-14 triage, which produced
ClickHouse#131689.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov alexey-milovidov self-assigned this Nov 15, 2026
A numeric compare-exchange could not tell that a failure happened after a
batch started if the halved limit came back to the same value, so an older
successful batch could clear a newer reduction. Move the shared limit into
`ObjectStorageQueueBatchSizeOverride`, which pairs it with a generation that
every failure increments; a success resets the limit only if the generation
is unchanged since its batch started.

Review: #131689 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
With `parallel_inserts` there is one streaming task per processing thread,
but they shared one `reschedule_processing_interval_ms`. Every task that
found no files added `polling_backoff_ms` to it, so N idle tasks grew the
backoff N times faster (e.g. 4 tasks reached 121 s after one idle poll), and
a reset by the task which found files did not shorten the wait of the
others, which were already scheduled far out. New files then waited for
minutes. Keep the interval per task, as it was with the single task.

Found from `05618_s3queue_alter_parallel_inserts` timing out in
#130904:
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=130904&sha=c8b5134c4293785f35c7ed755b32af690c093a0b&name_0=PR&name_1=Stateless%20tests%20%28arm_asan_ubsan%2C%20targeted%29

Co-Authored-By: Claude Opus 5.5 <[email protected]>
With one source per streaming task, a task can get no files while the
shared iterator is not finished, e.g. in ordered mode when the remaining
cached paths belong to buckets held by other tasks. It then committed empty
batches and rebuilt the insert pipeline in a loop, never reaching its
polling backoff. End the cycle instead.

Review: #131689 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov and others added 2 commits November 18, 2026 23:38
…ndependently of commit limits

With `parallel_inserts` each streaming task has its own processor and commits independently,
but `FileIterator::releaseFinishedBuckets` released the finished bucket holders of all processors.
A holder is finished when its source reaches the end, before the insert of that source completes,
so a commit of one task could release the bucket lock of another task whose insert was still running,
letting another replica take the bucket and process later files before the first insert failed.
Now `releaseFinishedBuckets` takes the processors of the batch which has just been committed.

`ProcessingProgress::processed_files` is counted only when `max_processed_files_before_commit` is set,
so with that limit disabled and a row or byte limit enabled, a batch which processed files looked empty:
the consumption cycle ended after every batch and the backlog was drained one batch per poll.
Now a separate `acquired_files` counter, maintained regardless of the commit limits, is used to detect
empty batches, to guard the reset of the batch size override, and as the size of a failed batch.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Nov 19, 2026
Merged via the queue into master with commit 0f20741 Nov 19, 2026
194 checks passed
@alexey-milovidov
alexey-milovidov deleted the s3queue-max-files-override-reset branch November 19, 2026 09:08
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 19, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 20, 2026
ClickHouse#131689 ends the streaming cycle when a task acquired no files, so the
loop exit this PR added is gone from it after the master merge, and arm D
covered only that. The test is back to the version of 085ac51.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-s3queue S3Queue/AzureQueue engines (queue-based ingestion from object storage). pr-bugfix Pull request with bugfix, not backported by default 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.

2 participants