Skip to content

s3queue: fix stale processing state in in-memory metadata - #118111

Merged
kssenii merged 7 commits into
masterfrom
s3queue-retry-foreign-processing-state
Sep 16, 2026
Merged

kssenii merged 7 commits into
masterfrom
s3queue-retry-foreign-processing-state

Conversation

@kssenii

@kssenii kssenii commented Sep 4, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

In S3(Azure)Queue table engine fix stale processing state in in-memory metadata


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

Version info

  • Merged into: 26.9.1.1577 (included in 26.9 and later)

`trySetProcessing` treats a cached `Processing` file status as terminal, so
once this table lost the race for the `processing` node in keeper and cached
that observation, it never rechecked keeper for that file.

Unlike `Processed` and `Failed`, `Processing` is not backed by a persistent
node: the processor holding the file can release it without committing it -
it can die, or fail the file and reset the node - and nothing resets the
cached status. The file stayed skipped by this table until its file status
was evicted from the metadata cache or the server restarted.

A cached `Processing` state which was observed in keeper rather than set by a
processor of this table is now trusted only while it is fresh, bounded by the
new table setting `processing_state_cache_ttl_seconds` (300 by default, zero
to always recheck keeper). A file released without a commit is therefore
retried within the timeout, while a file which really is being processed
elsewhere costs one keeper probe per timeout instead of one per listing pass.
A `Processing` state owned by a processor of this table stays terminal as
before: its owner updates it on commit.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [6be47fa]

Summary: ✅


AI Review

Summary

This PR fixes the functional stale-Processing retry path by bounding how long keeper-observed Processing rows are trusted and by cleaning up the cache-state transitions around observed terminal states. I did not find a remaining engine correctness issue in the touched claim/finalize paths, but one user-facing contract is still too strong for the same-server shared-FileStatus case.

Findings

💡 Nits

  • [src/Storages/ObjectStorageQueue/ObjectStorageQueueSettings.cpp:49] The new processing_state_cache_ttl_seconds wording still says a Processing state set by a processor of this server is not affected, but the new same-server trace (ObjectStorageQueueFileStatus.CommitDropsObservationMarkerOfALocallyOwnedState) shows that another local processor can later mark that shared FileStatus as processing_observed_in_keeper_time != 0, after which hasNonProcessableState does apply the TTL. The same assumption is repeated in the longer registerQueueStorage.cpp text and in the new system.s3queue_metadata_cache wording about the companion fields always describing “the last attempt” rather than possibly the ongoing local one.
Final Verdict

Status: ✅ Approve

LLVM Coverage Report

Measured on commit 6be47fa.

Metric Baseline Current Δ
Lines 89.10% 89.00% -0.10%
Functions 91.80% 91.80% +0.00%
Branches 81.50% 81.40% -0.10%

Changed lines: Changed C/C++ lines covered: 223/225 (99.11%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Sep 4, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-s3queue S3Queue/AzureQueue engines (queue-based ingestion from object storage). label Sep 4, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 6be47fa85 with master 95448e95a (stripped binary size, per-symbol sizes and ThinLTO time; 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.

Compile time of recompiled translation units

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

Job report

`onProcessingByAnotherProcessor` keeps `rows_processed`, `processing_start_time`,
`processing_end_time` and `exception` of the last local attempt, while setting the
state to `Processing` observed in keeper. `system.s3queue_metadata_cache` documents
those columns as the current state of the file, so a local failure followed by a
foreign retry showed a `Processing` row carrying an end time and an exception of
the previous attempt, with nothing telling the two apart.

Expose `foreign_processing_time` as `processing_by_another_server_time`: it is set
exactly when the `Processing` status was observed in keeper rather than set by a
processor of this server, and in that case the per-attempt columns describe the
last local attempt, not the ongoing processing.

Co-Authored-By: Claude Opus 5 <[email protected]>
@kssenii
kssenii force-pushed the s3queue-retry-foreign-processing-state branch from 335ec5f to 8b9c315 Compare September 10, 2026 10:29
@CheSema CheSema self-assigned this Sep 10, 2026
if (file_state.value() == FileStatus::State::Processing)
file_status->onProcessingByAnotherProcessor();
else
file_status->updateState(file_state.value());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

do not see why we do not we handle it inside updateState call

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.

updateState only knew the target enum, but the policy here depends on provenance, not just the final state. When keeper reports Failed again for a state we already had, we want to keep the local attempt data; when keeper reports a different terminal state, we want to drop it; and only the keeper-observed Processing case should set the observation marker.

That is why the current code replaced the blind setter with onStateObservedInKeeper: it carries the “this came from keeper after a failed claim” context that a generic state setter cannot infer.

kssenii and others added 3 commits September 10, 2026 15:35
…oduce

`afterSetProcessing` updated the file status from what keeper has for the file
through two different calls, and the one for a committed (`Processed`/`Failed`)
state only overwrote the state. It left `foreign_processing_time` set and the
data of the last attempt of this server (processed rows, timings, exception) in
place, so `system.s3queue_metadata_cache` could show a `Processed` row carrying
the marker of the `Processing` state it replaced and the exception of an earlier
local failure.

Both calls are replaced by `onStateObservedInKeeper`, which keeps the data of the
local attempt only while it can still describe the observed state: for a state we
did not have before, `resetAttempt` drops that data together with the marker. An
own `Failed` node observed again keeps its exception, which is what that state is
about.

`trySetProcessing` also consulted the file status before taking the processing
lock, so it could miss a `Processing` state which a processor of this server was
setting under that lock and mark it as foreign. The check is moved under the lock,
as `prepareSetProcessingRequests` already did it, and committing a file now clears
the marker, which also covers the batched claim path, where the state is set after
the lock is released.

The transitions are covered by a new unit test: they are reachable in production
only through a race between listing a file and claiming it, because a file which
keeper already has a `processed`/`failed` node for is filtered out of the listing.
`test_retry_file_released_by_another_processor` is also parametrized over
`enable_hash_ring_filtering` now, so that the batched claim path, which shares the
`Processing` state cache check, is covered as well.

Co-Authored-By: Claude Opus 5 <[email protected]>
`ObjectStorageQueueExclusiveFileMetadata`, added on master in the meantime, does
not compile against the constructor of `ObjectStorageQueueIFileMetadata` of this
branch, which takes the new `processing_state_cache_ttl_seconds` setting.

Co-Authored-By: Claude Opus 5 <[email protected]>
…ther server

`processing_by_another_server_time` promised more than the marker knows. It is set
whenever a processor failed to take the file and read the `Processing` state from
keeper, and the processor which holds the file is usually on another server, but it
can also be one of this server which had just taken it - the case the unit test of
the previous commit pins down. As the column is new in this pull request, name it
after what it records: `processing_observed_in_keeper_time`.

Co-Authored-By: Claude Opus 5 <[email protected]>
`system.s3queue_metadata_cache.status` listed three states, but the cache also
dumps `None`, which a file gets when its processing is reset. And the description
of `processing_state_cache_ttl_seconds` claimed the timeout applies to the
in-memory `Processing` state in general, while `hasNonProcessableState` applies it
only to a state read from keeper: a `Processing` state owned by a processor of
this server stays terminal, because its owner updates it itself.

Both strings are autogenerated into the documentation, so they are what an
operator reads.

Co-Authored-By: Claude Opus 5 <[email protected]>
@kssenii
kssenii added this pull request to the merge queue Sep 16, 2026
Merged via the queue into master with commit 69ff981 Sep 16, 2026
176 checks passed
@kssenii
kssenii deleted the s3queue-retry-foreign-processing-state branch September 16, 2026 11:08
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 16, 2026
alexey-milovidov added a commit that referenced this pull request Sep 17, 2026
…-processing-node-cache

Master merged #118111, which fixes the core bug of this pull request with its own
design: `processing_state_cache_ttl_seconds` (kept in the shared `ObjectStorageQueueMetadata`)
and `FileStatus::processing_observed_in_keeper_time` / `onStateObservedInKeeper`.
The merge adopts that design and drops the duplicate one of this branch:
`foreign_processing_node_cache_ttl_seconds`, the per-table `ForeignProcessingObservers`
registry and its generation scoping. What this branch adds on top is kept on the new
primitives: the terminal-state write-back of the listing pre-filter and of the
set-processing probe (`FileTerminalState`), the terminal-state generation guard against
a loser of the `processing` race, the foreign-processing recheck lists and the wake-up
cap of the streaming task, and the ordered-mode blocking of an ordering domain behind
a foreign-held file (with the replay cap). The gtests of the removed registry and the
two integration tests pinning per-table observation deadlines are dropped, the rest is
renamed to the setting of master.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-s3queue S3Queue/AzureQueue engines (queue-based ingestion from object storage). pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants