Repository navigation
Conversation
… startup The queuefs stale recovery only ever ran at backend open time: the SQLite backend recovered 'processing' rows once per process start, and the cache (Redis) backend ran three bounded startup sweeps covering the heartbeat-expiry window. A worker that wedged after mounting — alive but no longer processing — left its in-flight messages stuck until every process restarted, which is one of the mechanisms behind the 47-minute silent stall in volcengine#4303. Recovery is now a runtime property instead of a mount-time event: - SQLite backend (recover_stale_sec > 0): a background sweep thread re-runs the exact same atomic recovery UPDATE every recover_stale_sec seconds. The thread holds a Weak handle to the connection and exits as soon as the backend is dropped; failed sweeps are logged and retried on the next tick. recover_stale_sec <= 0 keeps the historical mount-time-only behavior, so existing deployments are unchanged. - Cache backend: the recovery task now runs for the lifetime of the storage (immediately, then every heartbeat TTL) instead of stopping after three sweeps. The per-instance heartbeat check inside the recover_stale script is unchanged, so live workers are never robbed. Both sweeps reuse the existing recovery predicates verbatim — no wire format, FFI, or configuration changes. Enabling the periodic sweep is purely a scheduling change, which pairs naturally with volcengine#3989 (default recover_stale_sec=300): once that lands, every bounded-recovery deployment also self-heals wedged workers at runtime. Delivery remains at-least-once: a legitimately slow handler that exceeds the threshold may see its message re-queued and processed again, the same trade-off the mount-time recovery already makes. Fixes runtime self-heal leg of volcengine#4303.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The queuefs stale recovery currently only runs at backend open time:
crates/ragfs/src/plugins/queuefs/backend.rs) callsrecover_stale()once insideSQLiteQueueBackend::open, andSTARTUP_RECOVERY_SWEEPS = 3).A worker that wedges after mounting — alive but no longer processing — therefore leaves its in-flight messages stuck in
processinguntil every process restarts. This is one of the mechanisms behind the 47-minute silent queue stall analyzed in #4303: nothing crashes, so no mount-time recovery ever fires again.Change
Recovery becomes a runtime property instead of a mount-time event, on both backends:
recover_stale_sec > 0): a background sweep thread re-runs the exact same atomic recovery UPDATE everyrecover_stale_secseconds. The thread holds aWeakhandle to the shared connection and exits as soon as the backend is dropped; a failed sweep (e.g. transient SQLite busy) is logged and retried on the next tick.recover_stale_sec <= 0keeps the historical mount-time-only behavior, so existing deployments see zero behavior change.recover_stalescript is unchanged, so messages owned by live instances are never re-queued.Both sweeps reuse the existing recovery predicates verbatim. There are no wire-format, FFI, or configuration changes — this is purely a scheduling change.
Relationship to related work
recover_stale_secto 300. That PR supplies the semantics (a bounded recovery window by default); this PR supplies the scheduling (mount-once → periodic). They compose: once fix(queue): default recover_stale_sec to 300 instead of mount-time recover-all (#3895) #3989 lands, every default deployment also self-heals wedged workers at runtime, using the same single knob.Residual risks (documented trade-offs)
recover_stale_secmay see its message re-queued and processed again. This trade-off already exists in the mount-time recovery; the periodic sweep only widens when it can trigger. Consumers must stay idempotent, as with any crash-recovery queue.queue.db). The Redis backend is stricter (per-instance heartbeat), but a worker whose tokio runtime still refreshes its heartbeat while its processing logic is wedged will not be detected. A lease/heartbeat protocol for the SQLite backend would be a larger follow-up; this PR deliberately does not change any protocol.Tests
test_sqlite_backend_periodic_recovery_recovers_stale_in_flight_message— a dequeued (wedged) message is re-queued by the periodic sweep after crossing the threshold, without reopening the database; below the threshold it is left alone.test_sqlite_backend_no_periodic_recovery_when_recover_stale_disabled— withrecover_stale_sec = 0(current default) an in-flight message staysprocessing: zero behavior change when disabled.recovery_loop_offsets_never_overflow_at_large_sweep_indexes— the now-unbounded sweep counter saturates instead of panicking/wrapping.periodic_recovery_returns_message_from_dead_instance_without_reopen— Redis integration test (REDIS_URL-gated, skipped by default like the existing shutdown-recovery test): after waiting past the three legacy startup sweeps, a message from an instance whose heartbeat disappeared is still re-queued by the long-running loop.Full local suites:
cargo test -p ragfs --features cache→ 471 passed / 0 failed; default-feature run → 437 passed / 0 failed;tests/misc/test_config_validation.py→ 51 passed.Fixes the runtime self-heal leg of #4303.