Skip to content

S3Queue: add failed_files_ttl_sec setting - #121752

Open
adityaksolves wants to merge 21 commits into
ClickHouse:masterfrom
adityaksolves:feature/s3queue-failed-files-ttl-setting
Open

adityaksolves wants to merge 21 commits into
ClickHouse:masterfrom
adityaksolves:feature/s3queue-failed-files-ttl-setting

Conversation

@adityaksolves

@adityaksolves adityaksolves commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Related: #113054

Changelog category (leave one):

  • New Feature

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

S3Queue: add failed_files_ttl_sec setting to automatically clean up terminal failed files from Keeper after TTL expires in unordered mode.

Detailed Description

This is Phase 1 of splitting PR #113784 per reviewer (@kssenii) feedback.

Adds the failed_files_ttl_sec table setting for S3Queue / AzureQueue engine in unordered mode:

  • Automatically cleans up tracked nodes of failed files in Keeper after the specified TTL in seconds.
  • Clears live retriable markers when files succeed or non-max files are processed.
  • Integrates cache reconciliation for stale retriable and failed states.

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

@clickhouse-gh

clickhouse-gh Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [03340ef]

Summary: ✅


AI Review

Summary

At head 03340ef4f8c67e433d8e641504a21ba192951c4b, this adds independent terminal-failure retention for unordered S3Queue / AzureQueue, preserves ordered-mode expiry, and reconciles cached retry state. Two deferred correctness issues still prevent approval. The latest processing-lock, cached-retry synchronization, and marker-removal polling fixes hold; their three review threads were resolved. No new inline findings were posted, and deliberately deferred discussions were left resolved.

Missing context / blind spots
  • ⚠️ The current-head Praktika report is still running, with queue integration jobs pending. No local build or integration tests were run. Completed queue integration results would close this execution gap.
Findings

❌ Blockers

  • src/Storages/ObjectStorageQueue/ObjectStorageQueueIFileMetadata.cpp:412–414: terminalization must preserve an active processor's right to finish. After a retry starts with a live .retriable marker, lowering loading_retries lets another replica create a terminal failure without checking /processing/<hash>. The active attempt can subsequently commit success, leaving both processed and failed state; ordered getPathState reports failure first. Serialize conversion with processing ownership and atomically require the processing node to be absent. [dismissed by author -- https://github.com/S3Queue: add failed_files_ttl_sec setting #121752#discussion_r4121313967] Deferred to the open S3Queue: clear stale .retriable marker on terminal failure and skip terminalization while processing #125565; the unsafe transaction remains in this head.

  • src/Storages/ObjectStorageQueue/ObjectStorageQueueIFileMetadata.cpp:863,971–980: terminal failure must consume any existing retry marker. Lowering loading_retries to zero during an attempt selects the non-retriable branch, which creates the terminal node but leaves the previous .retriable marker. After TTL deletes the terminal node, the claim path observes the surviving marker and recreates terminal failure without reading the file, so even repaired input can remain blocked through successive TTL cycles. Remove an existing marker in the same terminal-failure transaction, including when retries are now disabled. [dismissed by author -- https://github.com/S3Queue: add failed_files_ttl_sec setting #121752#discussion_r4092248653] The follow-up was deliberately deferred; this PR's cleanup still cannot clear that failure permanently.

⚠️ Majors

  • src/Storages/ObjectStorageQueue/ObjectStorageQueueIFileMetadata.cpp:537,647: fresh-file claims now synchronously read .retriable once per file, including files with no failures and tables with failed-file TTL disabled. In hash-ring mode these reads run serially while preparing the listing batch, replacing the previous batching benefit with a number of round trips proportional to the file count. Batch these reads with the existing filtering/claim preparation, or supply throughput measurements demonstrating acceptable impact. [dismissed by author -- https://github.com/S3Queue: add failed_files_ttl_sec setting #121752#issuecomment-6286212442] Batching was deferred, but the added latency applies to ordinary ingestion.

  • src/Storages/ObjectStorageQueue/ObjectStorageQueueMetadata.cpp:1613–1628: each deleted node now triggers a complete cache scan under the cache mutex. Removing K nodes from C cached entries therefore requires up to K × C comparisons instead of keyed removals, also affecting processed-file cleanup. This blocks foreground metadata lookups during each scan. Apply the generation predicate once per batch or use a conditional keyed removal. [dismissed by author -- https://github.com/S3Queue: add failed_files_ttl_sec setting #121752#issuecomment-6286212442] The author deferred these scans; their scaling and contention remain in the current code.

Tests
  • ⚠️ Cover an active retry on one replica while another lowers the retry limit, and a failure committed after lowering the limit to zero. Assert consistent Keeper state and successful reprocessing after TTL when the input is repaired.
  • ⚠️ Add focused regression coverage for the latest cache synchronization fix: retain an exhausted cached retry count while another replica starts a fresh retry sequence with a lower live count, then verify the surviving replica resumes processing.
  • ⚠️ Measure small-file hash-ring ingestion and cleanup with a populated metadata cache to quantify the two performance concerns.
Performance & Safety

The widened getPathState result was traced through trySetProcessing and prepareSetProcessingRequests, which compare retry counts and can terminalize markers, and through the initial and loop checks in waitForPathToBeProcessed, which distinguish terminal failures from retriable markers and apply the live limit. The waiter's checks at StorageObjectStorageQueue.cpp:2232,2323–2324 also ignore an active processing owner, so the ownership fix must cover waiting as well: an exhausted retry budget does not prove that an already-running attempt has failed.

Final Verdict

Status: ❌ Block. Include the two deferred retry-state fixes in the reviewed change and validate the focused scenarios before merge. Address or measure the ingestion and cleanup regressions. The previous claim that this PR introduces the ordered-mode default count cap was dropped: the base revision already applies that cap.

@clickhouse-gh clickhouse-gh Bot added the pr-feature Pull request with new product feature label Sep 23, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-s3queue S3Queue/AzureQueue engines (queue-based ingestion from object storage). label Sep 23, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 03340ef4f with master bdbd1b837 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of b02fbee24; 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.

Object file sizes

17 object files changed (+158.85 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Storages/ObjectStorageQueue/ObjectStorageQueueMetadata.cpp.o 889.71 KiB 957.96 KiB +68.24 KiB (+7.67%)
src/CMakeFiles/dbms.dir/Storages/ObjectStorageQueue/ObjectStorageQueueIFileMetadata.cpp.o 632.60 KiB 684.32 KiB +51.72 KiB (+8.18%)

719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

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

Job report

@clickhouse-gh clickhouse-gh Bot added the external Author is not a member of the ClickHouse organization label Sep 24, 2026
@adityaksolves

Copy link
Copy Markdown
Contributor Author

Pushed fixes for the two in-scope findings:

updateState(Processed) → onStateObservedInKeeper(Processed) (55e7bf9)
raised the FileStatus size sanity-check bound in test_metadata_cache_exact_size_tracking to 320, since the struct grew by two tracking fields (2f54892)

Per the scope discussion in
#113784, these are deferred to the follow-up PR and intentionally not addressed here: the inherited flag for the legacy failed_files_ttl_sec fallback, the stale .retriable cleanup in the !retriable branch, and tracked_files_limit alterability in ordered mode.

@adityaksolves

Copy link
Copy Markdown
Contributor Author

@kssenii Hi! Just wanted to gently follow up on this PR.

All CI checks have passed, and I've addressed the feedback from the initial review in the latest commits. Could you please take another look when you get a chance?

Thanks!

@adityaksolves

Copy link
Copy Markdown
Contributor Author

AI review on #125392 flagged a behavior change from this PR: for a legacy ordered table with tracked_file_ttl_sec set and tracked_files_limit = 0, failed-file expiry used to follow tracked_file_ttl_sec, but sweep_failed_by_ttl = isUnordered(mode) && failed_files_ttl_sec now disables it after upgrade, so failures persist indefinitely. Should legacy ordered tables keep the old expiry, or is this change intended?

@adityaksolves

adityaksolves commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor Author

@kssenii Phase 2 PRs are up and CI-tested: #125392 (SYSTEM DROP), #125433, #125565 (stale .retriable cleanup + live loading_retries), #125604 (ordered tracked_files_limit ALTER + exclusive-mode terminality). The AI-review blockers on those PRs come from this base PR and are covered by the follow-ups. One decision I need from you: for legacy ordered tables with tracked_file_ttl_sec set and tracked_files_limit = 0, failed-file expiry used to follow tracked_file_ttl_sec, but now sweep_failed_by_ttl is unordered-only, so failures persist after upgrade. Should I preserve the old expiry for legacy ordered tables, or is this change intended?

@adityaksolves

Copy link
Copy Markdown
Contributor Author

@kssenii Pushed e3b35e5 for the legacy ordered-table question: it was a regression from this PR, not intended. Before it, an ordered table with tracked_file_ttl_sec set expired /failed by that TTL, and the isUnordered gate (in cleanup_failed_files and in the sweep) dropped that. Ordered tables now expire /failed by tracked_file_ttl_sec again. failed_files_ttl_sec stays unordered-only, because I have not verified that removing a failed node by TTL is safe against the ordered watermark. I also restored the ordered retry assertion in test_max_set_age, which had been skipped for ordered mode.
The other open AI-review items (ownership check during terminalization, stale .retriable after lowering loading_retries) are handled in #125565. Batching the claim-side marker reads and the per-path cache scans in cleanup are deferred.

@clickhouse-gh

clickhouse-gh Bot commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Dear @kssenii, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

Adds the failed_files_ttl_sec engine setting, which controls time-based
expiry of terminal failed files in unordered mode. tracked_files_limit's
description is also updated to document that it caps the failed-files
set by count in both ordered and unordered mode, independently of the
new setting.

For tables created before this setting existed, the value is inherited
from tracked_file_ttl_sec at attach time; this inheritance is a one-time
fallback and is not kept in sync with later changes to tracked_file_ttl_sec.
…ck in hash-ring path; fix retriable marker test helper
…_ttl_sec

Before failed_files_ttl_sec, ordered tables expired /failed by tracked_file_ttl_sec. Gating the TTL sweep on isUnordered dropped that for existing ordered tables. Keep failed_files_ttl_sec unordered-only, and sweep /failed for ordered tables by tracked_file_ttl_sec as before. Restore the ordered-mode retry assertion in test_max_set_age.
…ring a keeper path

Ordered tables expire /failed by tracked_file_ttl_sec, so replicas sharing a keeper path must agree on it, as they did before failed_files_ttl_sec. Check it for all modes again and keep failed_files_ttl_sec and tracked_files_limit in the unordered block. Add a test for two ordered tables with different tracked_file_ttl_sec.
Ordered tables expire /failed by tracked_file_ttl_sec, unordered ones by failed_files_ttl_sec. Update the comments that said failed_files_ttl_sec is the only time-based control.
…cached retries from Keeper, poll for marker removal in tests
@adityaksolves
adityaksolves force-pushed the feature/s3queue-failed-files-ttl-setting branch from acb76fe to 03340ef Compare November 5, 2026 14:19

This branch has not been deployed

No deployments
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 comp-s3queue S3Queue/AzureQueue engines (queue-based ingestion from object storage). external Author is not a member of the ClickHouse organization pr-feature Pull request with new product feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants