Repository navigation
Make S3Queue batch size halving global to fix flaky test - #98810
Conversation
When an INSERT batch fails in `streamToViews`, the code previously re-threw the exception after committing the failed batch. This caused the entire `streamToViews` to exit, requiring a rescheduling cycle (1+ seconds) before processing could resume. Under MSan (5-10x slower), this delay compounded: remaining files from the iterator went unprocessed until the next scheduling cycle, and the per-task batch halving never converged because different tasks encountered the bad file each time, each resetting their batch size on the next successful iteration. Replace `throw` with `continue` so the while loop immediately processes the next batch from the iterator. The failed batch is already properly committed (good files reset for retry, bad files marked appropriately), so there is no need to propagate the exception. Also increase `run_with_retry` default retries from 100 to 300 in the test for additional MSan robustness. https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=c90fedd0932aea5f5c4b4ed1a353b1255df9c759&name_0=MasterCI&name_1=Integration%20tests%20%28amd_msan%2C%206%2F6%29 Co-Authored-By: Claude Opus 4.6 <[email protected]>
The per-task batch halving didn't converge with many streaming tasks because different tasks encountered the bad file each time. Each task would halve once, then succeed without the bad file in the next batch, resetting to the default batch size. No single task ever reached batch size 1 to isolate the bad file. Replace the per-task `max_files_override_per_task` vector with a single shared `std::atomic<size_t> max_files_override`. Now when ANY task encounters a batch failure, ALL tasks see the halved batch size on their next iteration. This makes the halving converge regardless of which task encounters the bad file. Also restore the `throw` after batch failure (was changed to `continue` in the previous commit) since the batch must be retried as a whole for insert deduplication into MergeTree tables. Co-Authored-By: Claude Opus 4.6 <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
| if (!current_max) | ||
| current_max = processing_progress->processed_files.load(); | ||
| effective_max_files = std::max<size_t>(current_max / 2, 1); | ||
| max_files_override = std::max<size_t>(current_max / 2, 1); |
There was a problem hiding this comment.
Non-atomic load-compute-store allows stale halving overwrites
Medium Severity
The halving of max_files_override uses a non-atomic load-then-store pattern. Thread A can load a stale value (e.g., 4), get preempted while threads B and C further halve (4→2→1), then Thread A wakes and stores 2, overwriting the more-converged value of 1. Under MSan (which the PR explicitly targets), threads are significantly slowed, widening this race window. A compare-and-swap loop that only decreases the value would prevent stale writes from undoing convergence progress.
| commit(/*insert_succeeded=*/ true, rows, sources, transaction_start_time); | ||
| file_iterator->releaseFinishedBuckets(); | ||
| effective_max_files = 0; | ||
| max_files_override = 0; |
There was a problem hiding this comment.
Success reset undoes concurrent halving across all tasks
Medium Severity
The unconditional max_files_override = 0 on the success path resets the global override for ALL tasks. If Task A fails and halves the override while Task B (already running with the old batch size) succeeds, Task B's reset wipes out Task A's halving. This is the same non-convergence pattern the PR describes for the per-task approach — "each halving once and then resetting on the next successful batch" — but now at global scope, making it potentially worse since any single successful task undoes progress for everyone.


Summary
streamToViewsdidn't converge with many streaming tasks (16 in the test). Different tasks encountered the bad file each time, each halving once and then resetting on the next successful batch. No single task ever reached batch size 1 to isolate the bad file.std::vector<size_t> max_files_override_per_taskwith a singlestd::atomic<size_t> max_files_overrideshared across all tasks. When ANY task encounters a batch failure, ALL tasks see the halved batch size on their next iteration.run_with_retrydefault retries from 100 to 300 for additional MSan robustness.CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=c90fedd0932aea5f5c4b4ed1a353b1255df9c759&name_0=MasterCI&name_1=Integration%20tests%20%28amd_msan%2C%206%2F6%29
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Note
Medium Risk
Touches concurrent error-handling logic in
StorageObjectStorageQueue::streamToViews, which can change batching/throughput behavior under failures. Uses an atomic shared override, so concurrency semantics are improved but should be validated under load and repeated failures.Overview
Makes S3/Azure Queue streaming batch-size backoff global: replaces per-streaming-task
max_files_override_per_taskwith a singlestd::atomic<size_t> max_files_overrideso any task’s failed insert halves the next batch size for all tasks until a successful commit resets it.Also increases integration-test
run_with_retryretries from100to300to reduce flakiness in the parallel-inserts failure scenario (notably under MSan).Written by Cursor Bugbot for commit ba18e2c. This will update automatically on new commits. Configure here.
Version info
26.3.1.439