Repository navigation
Keep an S3Queue file retryable after losing the race for its processing node - #112313
alexey-milovidov wants to merge 110 commits into
Conversation
In `S3Queue`/`AzureQueue`, when `ObjectStorageQueueIFileMetadata::trySetProcessing` fails because the `processing` node in keeper already exists, it belongs to another processor - another server, or another table on this server. The local `FileStatus` was then updated to `Processing` and, because the two non-processable checks in `trySetProcessing` and `prepareSetProcessingRequests` treat `Processing` as terminal, every later attempt short-circuited on that cached state without ever rechecking keeper. Unlike `Processed` and `Failed`, `Processing` is not backed by a persistent keeper node: the foreign processor can release the file without committing it (it can die, or fail the file and reset the node). Stale `processing` node cleanup does not evict `local_file_statuses` either - only the processed/failed node cleanup does. So this table kept skipping such a file until the file status was evicted from the cache or the server was restarted. The cached `Processing` state is now remembered as a hint: it still shows up in `system.s3queue`, but it no longer makes the file non-processable, so the file is picked up again as soon as the foreign `processing` node is gone. As soon as the foreign processor commits the file, the next attempt fails on the `processed` (or `failed`) node instead and the state becomes terminal again, so this costs at most one extra keeper request per listing pass for a contended file. Follow-up of #108977, where this was found during review: the regression test there has to accept losing one file for exactly this reason.
|
Workflow [PR], commit [24fed79] Summary: ⏳
AI ReviewSummaryThe PR prevents Findings❌ Blockers
Tests
Final VerdictStatus: ❌ Block Make retry-batch extraction exception-safe and add focused recovery coverage. Inline finding. |
…-processing-node-cache
…meout and keep a local `Processing` state Two changes from the review of #112313: - Per kssenii's suggestion, respect the cached `Processing` state of a foreign `processing` node until a timeout, storing the observation time in the cached `FileStatus`. The file is skipped without keeper probes while the observation is fresh, and is probed again (refreshing the observation) after the timeout, so a file released without a commit is retried within the timeout instead of being probed on every polling pass. - Per the AI review, `afterSetProcessing` no longer flips a locally-owned `Processing` state to "processing by another processor": when a same-server contender (the `FileStatus` is shared between tables using the same keeper path, and between insert threads) loses the race to a local processor, the local state is kept and its owner updates it on commit. Co-Authored-By: Claude Fable 5 <[email protected]>
Covers the same-server contention case requested by the AI review: a contender which loses the race for the `processing` node to a concurrent local processor sharing the same `FileStatus` must not relabel the locally-owned `Processing` state as "processing by another processor". Also covers caching the foreign observation as non-terminal and clearing the hint on real state transitions. Co-Authored-By: Claude Fable 5 <[email protected]>
…g and reset stale attempt data - The timeout for which an observation of a `processing` node of another processor is trusted is now a table setting, `foreign_processing_node_cache_ttl_seconds`, with the default of 5 minutes instead of the previous hardcoded 30 seconds (review by kssenii). - `onProcessingByAnotherProcessor` resets the per-attempt fields of the previous local attempt (`processed_rows`, `processing_end_time`, `last_exception`) and keeps `retries`, so that `system.s3queue_metadata_cache` does not show a `Processing` file with the failure data of a previous local attempt (review by `clickhouse-gh`). - The state is now represented by a single timestamp instead of a timestamp and a flag: this keeps `sizeof(FileStatus)` in the range asserted by `test_5.py::test_metadata_cache_exact_size_tracking`, which the previous commit broke. - Comments are shortened, as requested in the review.
…-processing-node-cache
|
Preview deployment for your docs. Learn more about Mintlify Previews.
|
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112313&sha=a238b9531b5a8ca0be9939116151a416126e74a3&name_0=PR&name_1=Stateless%20tests%20%28amd_llvm_coverage%2C%20ParallelReplicas%2C%20s3%20storage%2C%20parallel%29 and provide a fix in a separate PR. If the fix is already in progress, link it here. It is |
|
The fix is already merged: #111689 ("Fix unknown-stream LOGICAL_ERROR in parallel replicas with projection short-circuit"), merged 2026-07-31T15:40:01Z as
That is why no separate issue exists for The failure you linked predates the fix. Your build Since then the last So no separate PR is needed, and nothing is needed on this PR either: your current head |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 162/162 (100.00%) · Uncovered code |
… `system.s3_queue_settings` `StorageObjectStorageQueue::getSettings` reconstructs the queue settings, and it did not restore the new TTL, so `system.s3_queue_settings` always reported the default `300` regardless of the configured value. Add `ObjectStorageQueueMetadata::getForeignProcessingNodeCacheTTLSeconds` and use it in `getSettings`; the integration test now checks the reported value. Also move the documentation of the setting from the generated `docs/reference/engines/table-engines/integrations/s3queue.mdx` into the embedded `Documentation` block in `registerQueueStorage.cpp`, which is the source the page is generated from - direct edits to the generated page are rejected by the "No direct edits to generated or read-only docs" check.
…can run it `Bugfix validation (unit tests)` builds a "before" binary from the merge-base with only the PR's unit-test files overlaid, and reports a compile failure as inconclusive. The gtest referenced symbols that exist only in this branch (`isProcessingByAnotherProcessor`, `isProcessingRetryable`, and the new constructor parameter), so the "before" binary could never be built. Assert the behavior through the API that already exists on the merge-base: observing a foreign `processing` node drops the data of the previous local attempt, while a locally owned `Processing` state keeps it. That is a real reproduction - the first test fails without the fix - and it still covers the same-server contention case and the clearing of the foreign-processing hint. The timeout behavior is covered by the integration test. For this the new constructor parameter `foreign_processing_node_cache_ttl_sec_` is moved to the last position with the default of zero (always check keeper), so the constructor stays source-compatible with the merge-base.
…r-table setting `ObjectStorageQueueMetadataFactory` shares one `ObjectStorageQueueMetadata` between all tables with the same `keeper_path`, so the TTL kept in that shared object was silently fixed by the table created first, both for the retry window and for what `system.s3_queue_settings` reported. The value now travels from `StorageObjectStorageQueue` through `FileIterator` to `getFileMetadata`, so every table uses the value from its own DDL. Also, as requested in the review, `onProcessingByAnotherProcessor` now calls `onProcessing` instead of repeating it, and `isProcessingRetryable` is renamed to `shouldRetryProcessing`. A new integration test creates two tables sharing one `keeper_path` with different values of the setting and checks both the reported value and the retry window.
…-processing-node-cache
…pointer only for cached records With `after_processing = 'keep'`, ordered `AzureQueue` and partitioned `S3Queue` relist the whole retained processed history on each pass. Reading a `failed` node for each of these files sent keeper work proportional to the history on every pass, while the terminal state of a file without a cached `FileStatus` is not used anyway. Now the `failed` node of a file covered by the processed pointer is read only when the file has a cached record to reconcile (the cache is bounded), keeping `Failed` precedence over the processed pointer for `system.s3queue_metadata_cache`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-processing-node-cache Resolve the conflict in `StorageObjectStorageSource::createReader`: keep both master's new `prefetch_input_format` parameter and this PR's `iterator_consumed` parameter (in that order), and pass `prefetch_input_format = false` explicitly from `ObjectStorageQueueSource` so the pointer is not implicitly converted to `bool`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-processing-node-cache Resolved the conflict in `test_metadata_cache_exact_size_tracking`: keep the PR's upper bound (400, the PR adds atomics to `FileStatus`) and take master's comment about string capacity rounding. Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # src/Common/FailPoint.cpp
# Conflicts: # src/Storages/ObjectStorageQueue/ObjectStorageQueueOrderedFileMetadata.cpp # src/Storages/ObjectStorageQueue/ObjectStorageQueueOrderedFileMetadata.h # src/Storages/ObjectStorageQueue/StorageObjectStorageQueue.cpp
The `arm_tidy` build failed with `modernize-use-nodiscard` on `isSetProcessingContended`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
AI review of a later commit does not approve the PR, see the AI Review comment.
A file handed out by the `S3Queue` file iterator in `ordered` mode is an "unresolved set-processing" barrier of its ordering domain until the outcome of its claim is recorded somewhere else: as a foreign-held file, as a blocked file, or as a pending replay. Recording it allocates, so it can throw (e.g. `MEMORY_LIMIT_EXCEEDED`), and the hand-off was not exception-safe: - `recheckForeignProcessingLater` removed the unresolved barrier before `recordForeignHeldFile`. If the latter threw, the file was tracked nowhere, and a later file of the domain could be committed past it, losing it once the foreign processor released it without a commit. - `waitOrderingDomainGate` moved the object into `rememberBlockedFile` / `deferBehindReplay` before removing its barrier. If that threw, the barrier stayed registered with no owner, so the later files of the domain and `isFinished` waited forever. Now the barrier is always removed last, after the outcome is recorded, and every hand-off in `FileIterator::next` is guarded by `abandonOrderingBarrierHandOff`: it first blocks the rest of the listing pass (the state already used when the ordering barriers overflow: nothing more is handed out, nothing is inherited, the next pass lists everything again in order) and only then removes the orphaned barrier. Merely erasing the barrier would reopen the data-loss path. A failure to register the barrier of a file just taken from the listing invalidates the iterator, as a failure in `filterProcessableFiles` does. The failpoint `object_storage_queue_fail_ordering_barrier_hand_off` and `test_files_are_not_lost_after_ordering_barrier_hand_off_failure` cover the first case. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=4 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
…urce` - `abandonOrderingBarrierHandOff`: the `catch (...)` which clears all the unresolved set-processing barriers swallowed the exception silently (`catch_all` in the style check). Log it with `tryLogCurrentException`. - `OrderingDomainGate gate` was declared without an initializer (`cppcoreguidelines-init-variables` in the `arm_tidy` build). It is always assigned before use, the initializer only satisfies the check. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=112313&sha=25ba4261267c985e371b80f49d89d5375d6dab68&name_0=PR&name_1=Style%20check https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=112313&sha=25ba4261267c985e371b80f49d89d5375d6dab68&name_0=PR&name_1=Build%20(arm_tidy%2C%201%2F4) #112313 Co-Authored-By: Claude Fable 5.2 <[email protected]>
| due.push_back(std::move(pending.object)); | ||
| } | ||
| else | ||
| remaining.push_back(std::move(pending)); |
There was a problem hiding this comment.
[Blocker] Keep retry-queue entries valid when batch extraction throws
pending.object is moved out of the persistent deque before the whole transfer succeeds. With two expired rechecks, the first due.push_back can succeed and the second can throw std::bad_alloc; unwinding destroys due, but the original deque still contains the first entry with a null object. Replay bookkeeping can also be partially transferred.
This happens before the filterProcessableFiles exception guard in next. In unordered mode, and in ordered mode with buckets = 1, the iterator is retained after the exception. The next deadline calculation dereferences that null entry in getRecheckDeadline at line 858, so a recoverable allocation failure becomes undefined behavior. An allocation-failure probe using the current extracted method reproduced a null entry in the retained three-entry queue in both modes.
Please make batch extraction transactional, including its replay barriers, or discard the damaged iterator and its pending entries before it can be consulted again, preserving ordered relisting of the unprocessed prefix. Cover a failure after the first object has been transferred; the new claim hand-off failpoint does not exercise this path.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
S3Queue/AzureQueueinorderedmode losing a file which is held by theprocessingnode of another processor: committing a later file of the same bucket (or partition) advanced theprocessedpointer past the held file, and if the other processor then released the file without committing it, the file was never ingested. Also makesystem.s3queue_metadata_cachefollow Keeper when another processor commits or fails a file, retry a file skipped because of a foreignprocessingnode withinprocessing_state_cache_ttl_secondseven on an idle queue, and carry the exception of afailednode committed by another processor into the cache.Description
Found during the review of #108977 (the regression test there has to accept losing one file for exactly this reason).
The original bug of this pull request - a file whose
processingnode belongs to another processor was cached asProcessingand never retried by this table, even after the other processor released it without a commit - has meanwhile been fixed onmasterby #118111: the cachedProcessingstate carriesFileStatus::processing_observed_in_keeper_time, and it is trusted for the table settingprocessing_state_cache_ttl_seconds(5 minutes by default, zero means to always check Keeper). This pull request builds on those primitives (its own registry and setting were dropped whenmasterwas merged) and keeps what is not covered by that fix:Orderedmode: a foreign-held file blocks the later files of its ordering domain. An ordering domain is the scope of oneprocessedpointer: a bucket, and a partition within it when partitioning is used. Committing a later file of the domain advances the pointer past the held file, and the next listing pass then drops the held file as already processed - losing it forever if the foreign processor never commits it (it can die; its persistentprocessingnode is only cleaned up afterpersistent_processing_node_ttl_seconds). The file iterator records foreign-held files per ordering domain and drops the later files of the domain both at the listing pre-filter and before handing a file out; they are re-listed by the next pass. A held file stops blocking its domain as soon as this server wins itsprocessingnode or a terminal state for it is discovered in Keeper. The dropped files are retained in memory so that they can be replayed as soon as the blocker resolves, but the retention is only a shortcut and is capped at 1000 files: a blocker near the beginning of a large domain would otherwise buffer the whole rest of the namespace. Beyond the cap the files are not retained and the next pass lists them again. Because the blocker can resolve in the middle of the pass, the smallest path dropped by the cap is remembered per domain and everything from it on stays blocked for the rest of the pass, otherwise the files listed after the dropped range would advance the pointer past it. With several processing threads sharing one ordering domain (buckets = 1) the block alone is not enough: it is recorded only when the set-processing attempt of the held file fails, and a later file handed out to another thread before that could still be committed first. The file iterator therefore registers a file whose set-processing outcome is not yet known at hand-out time, and a later file of the domain waits until the outcomes of the smaller files are known before starting its own attempt.Rechecks within a listing pass and on an idle queue. A file skipped because of a trusted foreign
Processingobservation is kept in a recheck list by the file iterator, and every batch boundary of the pass takes the files whose observation has expired and runs them through the regular filtering, so the TTL is honored with batch granularity within a long pass. The streaming task also schedules its next cycle no later than the earliest pending recheck deadline, so that the TTL bounds the retry latency even when the polling backoff after zero-row cycles far exceeds it. That wake-up cap applies only to cycles which actually consume the iterator: aSYSTEM STOP/SYSTEM PAUSEd table never consumes it, so an overdue recheck must not make the background task reschedule in a tight loop.system.s3queue_metadata_cachefollows Keeper. The terminal states which the listing pre-filter discovers in Keeper are written back into the cachedFileStatus(unless the state is owned by an active local processor, whose owner updates it on commit), so the cache does not keep a staleProcessingafter another processor has committed the file. The write-back replaces the whole record: the per-attempt data of an abandoned local attempt is cleared, and a file failed by another processor carries the exception and retries from thefailednode. It is skipped when the cached state already equals the discovered terminal state (a finished local attempt whoserows_processedand timings must survive relistings); a cachedFailed, however, also describes retriable local attempts, so it is kept only when its retry count matches thefailednode payload. The set-processing probe (trySetProcessing/prepareSetProcessingRequests) follows the same contract: when it discovers aprocessed/failednode, it returns the metadata of that node andafterSetProcessingrefreshes the whole cached record with the same guards. Afailednode has precedence over the bucket-levelprocessedpointer in the pre-filter, because a later file may advance that pointer while afailednode for an earlier file remains in Keeper.Two writers of one shared record are ordered. The cached record of a file is shared between the tables of one
keeper_path. The pre-filter write-back takes the sameprocessing_lockthe set-processing probe holds, and the record keeps a terminal-state generation counter which the probe snapshots before reading Keeper, so a table which lost the race for theprocessingnode cannot downgrade a record which another table has meanwhile refreshed toprocessed/failed. A same-server contender losing to a concurrent local processor also keeps the locally ownedProcessingstate untouched instead of marking it as observed in Keeper: the owner updates it itself, and a false marker would make the other tables of this server block the ordering domain behind a file this server is processing.Tests:
tests/integration/test_storage_s3_queue/test_foreign_processing_node.py(12 tests) emulates the foreign processor with a realprocessingnode in Keeper. They cover the retry after the node disappears inunorderedandorderedmode; the later files of an ordering domain waiting for a held file in the middle of it; two processing threads over one domain with the set-processing attempt of the smallest file parked at a failpoint; the domain kept blocked when the replay cap drops files and the blocker resolves mid-pass (1102 files, a failpoint right after the first drop); the cache reportingProcessed/Failed(with the foreign exception) instead of a staleProcessing; afailednode appearing between the initial state read and the multi request of theorderedset-processing attempt; a terminalfailednode replacing a cached retriable local failure; afailednode taking precedence over theprocessedpointer; the retry within the TTL on an idle queue with a two-minute polling backoff; a paused table not busy-looping on an overdue recheck; andALTER TABLE ... MODIFY SETTING processing_state_cache_ttl_secondsshortening the retry window of a running table.src/Storages/ObjectStorageQueue/tests/gtest_file_status_foreign_processing.cppcovers the sharedFileStatusstate machine: the same-server contention case, the trust window of an observedProcessingstate, the whole-record refresh on a terminal state discovered by the set-processing probe, the retriable-vs-terminalFailedguard, and the loser of theprocessingrace not clobbering a terminal record refreshed by another table. The members added here are referenced fromif constexpr (requires ...)branches, so the gtest also compiles at the merge base (where it fails at runtime), which is what theBugfix validation (unit tests)job checks.The remaining ordered-mode gap raised by the AI review - a later file committed by another source of the same table while a smaller file is only locally
Processingand is then reset without afailednode - is pre-existing onmasterand independent of foreign processors; it is tracked separately in #118960.Related: #108977
Related: #118111
Related: #118960
Workflow [PR]
Sync PR [sync-upstream/pr/112313]