Repository navigation
Conversation
|
Workflow [PR], commit [2a15a50] Summary: ❌
AI ReviewSummaryThe PR enables changing Findings❌ Blockers
Tests
Final Verdict❌ Block. Make reconfiguration safe for destinations without deduplication, preserve bucket ownership through each owning insert's durable boundary, fix the zero-counter polling regression, and add focused coverage for those cases and effective worker reconfiguration. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units22 translation units recompiled, 209 s compile time in total, 22 of them have a recent master baseline. |
NIKTONIKTO717
left a comment
There was a problem hiding this comment.
@ch-samuel-reviewer-1 open a PR with suggested change for this.
A possible change I suggest (on top of c83c685)
diff --git a/src/Storages/ObjectStorageQueue/StorageObjectStorageQueue.cpp b/src/Storages/ObjectStorageQueue/StorageObjectStorageQueue.cpp
index a8d9de6f434e..ebebe5129e1d 100644
--- a/src/Storages/ObjectStorageQueue/StorageObjectStorageQueue.cpp
+++ b/src/Storages/ObjectStorageQueue/StorageObjectStorageQueue.cpp
@@ -1092,7 +1092,7 @@ bool StorageObjectStorageQueue::streamToViews(size_t streaming_tasks_index, UInt
LOG_TEST(log, "Using {} processing threads (processing_threads_num: {}, parallel_inserts: {}, async deduplicate: {})",
threads, processing_threads_num, use_parallel_inserts, is_deduplication_v2);
- while (!shutdown_called && !file_iterator->isFinished() && !stream_control.isCancelRequested(cycle_epoch))
+ while (!shutdown_called && !file_iterator->isFinished() && !isStreamingCycleCancelled(cycle_epoch))
{
/// All tasks share a single batch size override so that the halving
/// converges regardless of which task encounters the bad file.
@@ -1172,7 +1172,7 @@ bool StorageObjectStorageQueue::streamToViews(size_t streaming_tasks_index, UInt
executor.setCancelCallback(
[this, cycle_epoch, &cancelled_mid_insert]
{
- if (stream_control.isCancelRequested(cycle_epoch))
+ if (isStreamingCycleCancelled(cycle_epoch))
{
cancelled_mid_insert = true;
return true;
@@ -1260,6 +1260,11 @@ bool StorageObjectStorageQueue::streamToViews(size_t streaming_tasks_index, UInt
return total_rows > 0;
}
+bool StorageObjectStorageQueue::isStreamingCycleCancelled(UInt64 cycle_epoch) const
+{
+ return stream_control.isCancelRequested(cycle_epoch) || restarting_streaming_tasks;
+}
+
void StorageObjectStorageQueue::postProcess(
const StoredObjects & successful_objects,
UnorderedSetWithMemoryTracking<String> & post_processing_failed_paths,
@@ -1884,11 +1889,14 @@ void StorageObjectStorageQueue::alter(
/// The number of streaming tasks changes, so they are re-created once the running ones finish.
const bool recreate_streaming_tasks = parallel_inserts_changed || (processing_threads_num_changed && new_parallel_inserts);
const bool restart_streaming = requires_detached_mv || recreate_streaming_tasks;
- /// Otherwise the running tasks finish only once the whole backlog is processed.
- if (recreate_streaming_tasks)
- stream_control.requestCancel();
if (restart_streaming)
{
+ /// Otherwise the running tasks finish only once the whole backlog is processed.
+ if (recreate_streaming_tasks)
+ restarting_streaming_tasks = true;
+ /// No streaming cycle runs after the tasks are deactivated.
+ SCOPE_EXIT({ restarting_streaming_tasks = false; });
+
std::lock_guard lock(streaming_tasks_mutex);
LOG_TRACE(log, "Deactivating {} streaming tasks", streaming_tasks.size());
diff --git a/src/Storages/ObjectStorageQueue/StorageObjectStorageQueue.h b/src/Storages/ObjectStorageQueue/StorageObjectStorageQueue.h
index 977e702b6b57..8408acddfb81 100644
--- a/src/Storages/ObjectStorageQueue/StorageObjectStorageQueue.h
+++ b/src/Storages/ObjectStorageQueue/StorageObjectStorageQueue.h
@@ -185,6 +185,9 @@ private:
};
mutable std::mutex streaming_tasks_mutex;
std::vector<std::unique_ptr<StreamingTask>> streaming_tasks TSA_GUARDED_BY(streaming_tasks_mutex);
+ /// Set by `ALTER` while it waits for the running streaming cycles to finish before re-creating the
+ /// streaming tasks, so that the cycles stop early. Unlike `SYSTEM CANCEL`, it does not abort direct `SELECT`.
+ std::atomic<bool> restarting_streaming_tasks{false};
std::atomic<size_t> max_files_override{0};
LoggerPtr log;
@@ -226,6 +229,8 @@ private:
void createStreamingTasks(size_t count);
/// A subset of logic executed by threadFunc.
bool streamToViews(size_t streaming_tasks_index, UInt64 cycle_epoch);
+ /// The streaming cycle started at `cycle_epoch` is cancelled by `SYSTEM STOP/CANCEL` or by `ALTER`.
+ bool isStreamingCycleCancelled(UInt64 cycle_epoch) const;
/// Apply after_processing action to successfully processed files.
void postProcess(
const StoredObjects & successful_objects,|
@NIKTONIKTO717 Opened azat#1. |
Previously the only way was to re-create the table, which is not trivial if you need to preserve the history of processed files in Keeper. And apply ALTER of `processing_threads_num` with `parallel_inserts` without re-attaching the table. It does not require detaching materialized views. ALTER asks the running streaming to stop, so it waits only for the in-flight INSERT (or interrupts it if deduplication is enabled), not for the whole backlog of files. Co-Authored-By: Claude Fable 5.2 <[email protected]>
c83c685 to
75739a7
Compare
Stop the running streaming cycles with a flag instead of `stream_control.requestCancel()`: the latter only bumps the epoch, so a cycle that started after it drained the whole backlog, and it aborted direct `SELECT` with `QUERY_WAS_CANCELLED`. ClickHouse#130904 (comment) ClickHouse#130904 (comment) Co-Authored-By: Claude Fable 5.1 <[email protected]>
Stop the running streaming cycles with a flag instead of `stream_control.requestCancel()`: the latter only bumps the epoch, so a cycle that started after it drained the whole backlog, and it aborted direct `SELECT` with `QUERY_WAS_CANCELLED`. ClickHouse#130904 (comment) ClickHouse#130904 (comment) Co-Authored-By: Claude Fable 5.1 <[email protected]> Co-Authored-By: Samuel Krempaský <[email protected]>
75739a7 to
c8b5134
Compare
|
|
||
| # Changes the number of streaming tasks | ||
| $CLICKHOUSE_CLIENT -q " | ||
| ALTER TABLE queue MODIFY SETTING processing_threads_num = 8; |
There was a problem hiding this comment.
[Major] Verify reconfiguration with an active background insert
Each topology change follows wait_rows, and new files are uploaded only after the ALTER returns. There is therefore no intentional backlog or guaranteed active insert to exercise the new stop flag and deduplication cancellation callback. The separate direct-SELECT test has no materialized view and cannot cover those background paths. Also, checking system.s3_queue_settings and eventual row counts does not verify the effective worker count: removing the createStreamingTasks call would still satisfy these assertions. Please add a focused stateless case that alters the topology with an attached view while an insert is active and more files remain, covering deduplication enabled and disabled. Assert complete, nonduplicated output and that the effective streaming parallelism changes, so the promised safe reconfiguration is actually tested.
There was a problem hiding this comment.
🕵 Done in e66e1d6: 05618 now uploads 300 files right before each ALTER that changes the number of streaming tasks (processing_threads_num = 8 and parallel_inserts = 0), so background inserts are running while the tasks are stopped and re-created, and after each step it checks count() = uniqExact(x) = <expected>, i.e. every file is inserted exactly once.
There was a problem hiding this comment.
[Major] The backlog and uniqueness checks improve coverage, but the original issue is still partly present at tests/queries/0_stateless/05618_s3queue_alter_parallel_inserts.sh:86-95: there is no synchronization proving an insert is active when ALTER starts, and the assertions still observe only the setting and eventual rows. Removing the createStreamingTasks call at StorageObjectStorageQueue.cpp:1996 would still satisfy them with the old workers. The test also never selects deduplication_v2 = 0, so it cannot verify the branch that must finish the in-flight insert instead of cancelling it. Please synchronize with active processing and assert the effective streaming task count after reconfiguration, with coverage for both cancellation and draining.
After ClickHouse#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]>
…ue/S3Queue" This reverts commit c778410.
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: ClickHouse#131689 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # src/Storages/ObjectStorageQueue/StorageObjectStorageQueue.cpp # src/Storages/ObjectStorageQueue/StorageObjectStorageQueue.h
…Queue`/`AzureQueue` Table creation already refuses zero, but `ALTER ... MODIFY SETTING processing_threads_num = 0` was accepted, stored in keeper, and with `parallel_inserts` replaced the streaming tasks with none. Check it while validating the changed settings, before any task is deactivated or keeper is updated. Review: ClickHouse#130904 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s processed in 05618 Upload 300 files right before each `ALTER` that changes the number of streaming tasks, so that background inserts are running while the tasks are stopped and re-created, and check that every file is inserted exactly once. Also check that `processing_threads_num = 0` is rejected. Review: ClickHouse#130904 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 ClickHouse#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]>
# Conflicts: # src/Storages/ObjectStorageQueue/StorageObjectStorageQueue.cpp # src/Storages/ObjectStorageQueue/StorageObjectStorageQueue.h
The test waits for new files after each `ALTER`, and with the default `polling_backoff_ms = 30000` an idle poll right after re-creating the streaming tasks delays processing by at least 31 s per step, which made the test exceed the 180 s limit in every sanitizer job: 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]>
|
🕵 Continued this PR (pushed
Only syntax-checked locally; CI will run the tests. |
| [this, cycle_epoch, &cancelled_mid_insert] | ||
| { | ||
| if (stream_control.isCancelRequested(cycle_epoch)) | ||
| if (stream_control.isCancelRequested(cycle_epoch) || restarting_streaming_tasks) |
There was a problem hiding this comment.
[Blocker] Drain the insert when a destination does not deduplicate
is_deduplication_v2 only checks the queue and query flags (line 1072); it does not establish that the materialized-view targets deduplicate. For example, a plain MergeTree target has non_replicated_deduplication_window = 0 by default, so MergeTreeSink ignores these tokens. With a file spanning multiple output blocks, let some blocks commit, then run ALTER TABLE queue MODIFY SETTING parallel_inserts = 1 while the file is still being inserted. This new condition cancels the pipeline; commit(false, ...) resets the file for retry without rolling back the target's committed parts. The replacement worker rereads the file from the beginning and duplicates the committed prefix. The same issue applies to AzureQueue and to a view chain containing a non-deduplicating destination.
For ALTER, let the current insert finish unless every affected destination is known to deduplicate retries. Keeping the restart flag in the outer loop, without using it to cancel the executor, would still stop at the current insert boundary. Add a focused stateless case that alters after a prefix of a multi-block file becomes visible in a non-deduplicating target and checks the final count and unique count.
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: ClickHouse#131689 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
| const bool parallel_inserts = table_metadata.parallel_inserts; | ||
| const size_t threads = parallel_inserts ? 1 : processing_threads_num; | ||
| const bool use_parallel_inserts = parallel_inserts; | ||
| const size_t threads = use_parallel_inserts ? 1 : processing_threads_num; |
There was a problem hiding this comment.
[Blocker] Keep ordered bucket locks until their owning insert commits
With mode = 'ordered', buckets > 1 and parallel_inserts = 1, these independent inserts share one FileIterator. getNextKeyFromAcquiredBucket marks a holder finished when its source reaches the end of its bucket (ObjectStorageQueueSource.cpp:896–900), before the insert commits. However, both cleanup calls in streamToViews invoke releaseFinishedBuckets, which scans every processor's holders (ObjectStorageQueueSource.cpp:713–737). An unrelated task, including one committing an empty batch, can therefore release that bucket while its owning insert is still pending.
Another consumer can acquire the bucket, skip the still-processing file and commit a later filename. If the original insert fails or is cancelled by ALTER, its retry is now below the processed watermark, so its missing rows are permanently skipped. Keep the lock until the owning batch has committed or reset its files; scope releases to processors whose batches have completed, or track outstanding batches explicitly. Please cover ordered parallel ingestion with an unfinished insert and a competing consumer.
| if (processing_progress->processed_files.load() == 0) | ||
| break; |
There was a problem hiding this comment.
[Major] Count acquired files independently of the configured file limit
ProcessingProgress::processed_files is incremented only inside if (commit_settings.max_processed_files_before_commit) in ObjectStorageQueueSource::generateImpl (ObjectStorageQueueSource.cpp:1268–1270). Thus a valid configuration such as processing_threads_num = 1, max_processed_files_before_commit = 0, max_processed_rows_before_commit = 1 leaves this counter at zero after every successful one-row file. This new condition exits despite a remaining backlog, and threadFunc waits polling_min_timeout_ms before processing the next batch. With the default polling timeout this limits ingestion to roughly one such file per second; previously it continued immediately after each commit. Byte- and time-limited batches have the same problem when the file-count limit is disabled.
Use an unconditional acquired-file count, with consistent decrement handling, or another measure that distinguishes an empty batch from a successful batch with no file-count limit. Add a focused case with the file limit disabled and another commit limit enabled.
Blocked by #130864
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Allow to change
parallel_insertsofS3Queue/AzureQueuewith ALTERPreviously the only way was to re-create the table, which is not trivial if you need to preserve the history of processed files in Keeper.
And apply ALTER of
processing_threads_numwithparallel_insertswithout re-attaching the table.It does not require detaching materialized views. ALTER asks the running streaming to stop, so it waits only for the in-flight INSERT (or interrupts it if deduplication is enabled), not for the whole backlog of files.
Workflow [PR]
Sync PR [sync-upstream/pr/130904]