Skip to content

S3Queue: keep inherited failed_files_ttl_sec in sync with tracked_file_ttl_sec until set explicitly - #125433

Open
adityaksolves wants to merge 24 commits into
ClickHouse:masterfrom
adityaksolves:feature/s3queue-inherited-failed-ttl-flag
Open

adityaksolves wants to merge 24 commits into
ClickHouse:masterfrom
adityaksolves:feature/s3queue-inherited-failed-ttl-flag

Conversation

@adityaksolves

@adityaksolves adityaksolves commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Related: #113054
Depends on #121752 (the diff below also shows #121752's commits until it is merged; the only new commit here is 31ad5cd).

Changelog category (leave one):

  • Bug Fix

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
S3Queue: keep the inherited failed-files TTL for legacy tables in sync with later tracked_file_ttl_sec changes until failed_files_ttl_sec is set explicitly.

Detailed Description

This is Phase 2, PR 1 of splitting #113784. It is the "inherited flag" item that was deferred from #121752.

Problem: for a legacy table (no failed_files_ttl_sec key in Keeper metadata), failed_files_ttl_sec is copied from tracked_file_ttl_sec on attach. toString() then wrote this copied value to Keeper as if it were explicit, so a later ALTER TABLE ... MODIFY SETTING tracked_file_ttl_sec = N left the failed TTL stuck on the old value (see the AI review finding at ObjectStorageQueueTableMetadata.cpp:118 on #121752).

Fix: a new failed_files_ttl_sec_inherited flag in the table metadata.

  • Key missing in Keeper (legacy table): flag is true.
  • Flag true: altering tracked_file_ttl_sec also updates failed_files_ttl_sec.
  • User alters failed_files_ttl_sec explicitly: flag becomes false.
  • Tables created with failed_files_ttl_sec set explicitly: flag is false.
  • On replica sync, the flag is taken from Keeper unless the user set the setting locally.

Also updates the setting description and the docs note in registerQueueStorage.cpp.

Tests (test_failed_files_ttl.py):

  • test_legacy_inherited_failed_files_ttl_follows_tracked_ttl_alter
  • test_explicit_failed_files_ttl_ignores_tracked_ttl_alter

Not in this PR

Stale .retriable cleanup and the in-flight retry race (#125565), exclusive mode failure terminality and live loading_retries handling (#125604), ordered mode support, and the LIKE 'prefix/%' filter in SYSTEM DROP. These come in separate follow-up PRs.


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

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
@clickhouse-gh clickhouse-gh Bot added comp-s3queue S3Queue/AzureQueue engines (queue-based ingestion from object storage). external Author is not a member of the ClickHouse organization labels Oct 12, 2026
@george-larionov george-larionov added the can be tested Allows running workflows for external contributors label Oct 13, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [cee0ed9]

Summary: ✅


AI Review

Summary

This PR persists failed_files_ttl_sec_inherited so legacy S3Queue tables keep their failed-file TTL synchronized with tracked_file_ttl_sec until an explicit opt-out. Reviewing head cee0ed9a4d66f1a5304eba047898254b15aaf3bb found another path that silently ignores a requested TTL and prevents reattach. The full diff also includes unresolved retry-state and performance issues from the still-open stacked base, #121752. ❌ Block pending the fixes below; deferred findings remain in this summary without reopening their threads.

Findings

❌ Blockers

  • ObjectStorageQueueMetadata.cpp:437: An explicit TTL assignment must take effect even when it matches the local SQL definition. Start legacy replicas A and B with tracked_file_ttl_sec=3600; A changes it to 10, then B requests 3600. StorageObjectStorageQueue::alter filters out B's assignment at StorageObjectStorageQueue.cpp:1749–1752 because its SQL definition already contains 3600. The new Keeper refresh retains and persists 10 for both TTLs despite a successful ALTER; B subsequently fails to reattach with METADATA_MISMATCH. Restoring failed_files_ttl_sec to its local SQL value has the same problem. Forward explicitly requested TTL assignments to alterSettings even when SQL values are unchanged, letting its Keeper-based comparisons decide whether they are no-ops. Continue filtering unrelated unchanged settings.

  • ObjectStorageQueueIFileMetadata.cpp:413: An active retry must not be terminalized by another consumer. After lowering loading_retries, another replica can remove the live .retriable marker and create a terminal failed node while the owner is processing. A later successful ordered-mode commit can coexist with that terminal node, causing the successfully processed path to be reported as failed. Enforce absence of processing ownership atomically with terminalization, or tie the transition to the current owner. [dismissed by author -- https://github.com/S3Queue: keep inherited failed_files_ttl_sec in sync with tracked_file_ttl_sec until set explicitly #125433#discussion_r4261678007] The current multi still contains only remove/create requests; deferring the ownership fix to S3Queue: clear stale .retriable marker on terminal failure and skip terminalization while processing #125565 leaves this race in the reviewed head.

  • ObjectStorageQueueIFileMetadata.cpp:639: Batched claiming must not add one dependent Keeper round trip per fresh file. With enable_hash_ring_filtering=1, FileIterator::next serially calls isRetriableMarkerExhausted for the listing batch while holding the iterator lock. A batch of 1000 fresh files adds 1000 synchronous reads before any file reaches a reader, including when every retry marker is absent. Batch these reads with the existing filtering/claim work. [dismissed by author -- https://github.com/S3Queue: keep inherited failed_files_ttl_sec in sync with tracked_file_ttl_sec until set explicitly #125433#discussion_r4271033484] The serial lookup remains in the hot path; moving its fix to follow-up work on the base does not remove the regression.

⚠️ Majors

Tests
  • ⚠️ Extend the existing two-replica fixture: A changes the tracked TTL to 10, B explicitly requests its unchanged SQL value 3600, then assert both Keeper TTLs are 3600 and B reattaches. Cover the equivalent restoration of an explicitly configured failed TTL. The current stale-cache regression requests a value different from B's SQL definition and therefore misses this outer filter.
  • ⚠️ The deferred claim-path regression needs Keeper request counts or a small-file throughput comparison with hash-ring filtering enabled; verify that lookups scale by batches rather than individual files. Terminalization also needs a focused case where the owner succeeds after another consumer observes the lowered retry budget.
Final Verdict

❌ Block. Preserve explicitly requested TTL assignments through the outer ALTER filter and add the focused regression. Before merging the full stacked diff, incorporate the deferred ownership, live-budget, and batching/cache-eviction fixes, or remove the affected changes from this diff. Dismissed findings remain summary-only.

@clickhouse-gh clickhouse-gh Bot added the pr-feature Pull request with new product feature label Oct 13, 2026
@adityaksolves

Copy link
Copy Markdown
Contributor Author

CI status at 31ad5cd: all S3Queue-related checks pass (Style check, Fast test, all asan/tsan/msan builds, Parser memory check, integration tests for ObjectStorageQueue). The remaining failures look unrelated to this change: 02968_file_log_multiple_read (FileLog), DeltaLake/Iceberg integration tests, and infra-level failures in Build (s390x/wasm64/arm_fuzzers) and an Azure stateless job whose logs are empty.

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default and removed pr-feature Pull request with new product feature labels Oct 14, 2026
…t-out from a stale cache

alterSettings built the new table metadata from the locally cached table_metadata, which can be stale. An unrelated ALTER on one replica could therefore write back an old failed_files_ttl_sec_inherited flag and undo an opt-out made on another replica. Start from the retention state read from Keeper under the alter lock, and make the same-value opt-out check use it as well. Add a two-replica regression test.
…eshed metadata in alterSettings

The no-op check in alterSettings compared the requested value against the possibly stale local table_metadata. After the Keeper refresh of tracked_files_ttl_sec, a real change could be skipped, leaving Keeper with the old TTL and causing METADATA_MISMATCH on a later reattach. Compare against new_table_metadata instead, as the failed_files_ttl_sec branch already does, and extend the two-replica integration test to cover this case.
/// Start from the retention state currently stored in Keeper so an unrelated ALTER does not revert it.
new_table_metadata.failed_files_ttl_sec = metadata_from_zk.failed_files_ttl_sec.load();
new_table_metadata.failed_files_ttl_sec_inherited = metadata_from_zk.failed_files_ttl_sec_inherited.load();
new_table_metadata.tracked_files_ttl_sec = metadata_from_zk.tracked_files_ttl_sec.load();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Forward explicitly requested TTLs before filtering SQL no-ops

The Keeper refresh also needs a change in StorageObjectStorageQueue::alter: its filter at StorageObjectStorageQueue.cpp:1749–1752 drops a requested assignment when it equals the stored SQL setting, before alterSettings can compare it with Keeper.

For example, start two legacy replicas with tracked_file_ttl_sec=3600. Replica A sets it to 10; replica B then explicitly sets it back to 3600. B's SQL definition already contains 3600, so changed_settings is empty. This refresh retains Keeper's 10 and writes it back, although B's ALTER succeeds. Both effective TTLs remain 10, and detaching/attaching B raises METADATA_MISMATCH because its SQL definition still says 3600. The same filter prevents restoring failed_files_ttl_sec to a value already present in the local SQL definition.

Please forward TTL assignments explicitly present in the ALTER commands even when their SQL values are unchanged, and let the Keeper-based comparisons decide whether they are no-ops. Keep unrelated unchanged SQL settings filtered out. Extend the existing two-replica regression with the requested-value-equals-SQL case and assert the Keeper TTLs and successful reattach.

qiuyanjun888 pushed a commit to qiuyanjun888/ClickHouse that referenced this pull request Oct 16, 2026
…ing them

The waits before the two SELECTs required `count() >= 1` and `count() >= 11`,
which only proves that one FileLog batch was committed. The second round
appends lines 1..20 with separate writes, so a batch can start in the middle
of the loop and read a prefix, with the rest arriving in the next batch. On
`Stateless tests (arm_binary, s3 storage, DBReplicated, sequential)` the
SELECT then ran between the part with 11..18 and the part with 19, 20, and
printed 1..18 (PR ClickHouse#125135) or 1..19 (PR ClickHouse#125433).

Wait for every row the following SELECT prints instead (10 and 20).

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

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-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants