Queue storage: one starved lane pins the queue ring, so storage stops being reclaimed for every queue

オープン
#779 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
15/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
postgresql, rust
領域
backend, databases

調査の方向性

Start with awa-model/src/queue_storage.rs, especially rotate, prune_oldest, and queue_prune_has_pending_ready_tx, then review tests #780 and #781. The issue outlines observability, documentation, and row-migration approaches; agree on which proposal to pursue before implementation. For the planned 0.6.18 work, done means reporting the pinning lane and pending-row age and documenting the operational impact.

索引モデルが issue の本文から書いたものです。

説明

One lane that nobody claims stops the queue ring from reclaiming storage for every queue in the schema. 0.6.18 reports the lane and releases the ring once its jobs are moved or cancelled. This issue tracks the rest: a patch-line mitigation, then a structural fix in 0.7.

Observed

The deployment ran a mix of 0.6.16 and 0.6.17 runtimes in queue-storage mode on a 16-slot queue ring. The ring stopped rotating for several days.

  • The oldest sealed slot still held about 18,000 ready entries in the priority-4 lane of one queue. Every other lane in that slot had been fully claimed, and the slot had no leases or unclosed claim references.
  • That queue runs with priority aging disabled (priority_aging_interval_secs: 0). Its priority-3 lane carried a backlog of about 50,000 jobs and cleared well under one job per second net of new arrivals. Under strict priority, the priority-4 lane is not claimed until priority 3 is empty.
  • On every tick, prune_oldest returned SkippedActive { reason: QueuePendingReady } for that slot, and rotate returned SkippedBusy when it reached it.
  • Because the ring couldn't advance, the current slot took every queue's ready, done, segment and claim-attempt rows. It reached about 11 GB of ready_entries, 2 GB of done_entries, 1.2 GB of ready_segments and 0.8 GB of ready_claim_attempt_batches.
  • Nothing failed. Claims, completions and the other queues were healthy. The cost was storage and bloat that couldn't be reclaimed until that lane drained.

Mechanism

rotate only advances into an empty slot, and prune_oldest correctly refuses to truncate a slot while any lane has a ready row at or past its claim cursor. So:

Retained ring storage ≈ the write rate of every queue × the age of the oldest pending row in any lane.

Two kinds of lane matter, and they need different fixes:

  • A stalled lane makes no progress at all, so the age is unbounded and the ring stops. Causes: a paused queue, a queue no worker serves, a lower priority under strict priority while a higher one stays backlogged, and (planned in 0.7) a head blocked by per-key capacity (ADR-033).
  • A slow lane, such as a deep backlog, a rate limit or too few permits, doesn't stop the ring; it stretches it. Each slot covers more time and retention settles at the total write rate × that lane's lag.

The incident above was both: the priority-4 lane was stalled behind a priority-3 lane that was itself about 50,000 jobs behind.

Done

  • 0.6.18 (#780, #781): the awa.maintenance.prune.pinned_ready_age gauge, a warning naming the pinning lane, QueueStorage::queue_ring_pin, and docs, including storage isolation.
  • 0.6.18 (#797): maintenance steps a lane's claim cursor past moved, reprioritised or cancelled jobs in any order, so those commands now release the ring.

Plan

0.6.x: no schema change, no change to the claim SQL
  1. Release faster after clearing (#800). Time-budget the maintenance cursor advance and pace it by its own progress instead of prune's backoff.

  2. Escalate aging while a queue's own lane pins the ring (#886). Rust only. While a lane of priority P > 1 appears in queue_ring_pin, that queue's claims pass an aging interval of head_age / (P - 1), so the lane's head reaches effective priority 1. The queue goes back to its configured interval when the lane leaves the pin. It's on by default with a per-queue opt-out, and the pin warning gains a cause (paused, no runtime, starved, advancing).

    What it does and doesn't do:

    • While one of its lanes pins the ring, the queue is served oldest-first across priorities for rows older than the pin. It wins only when the starved head is older than the heads above it.
    • In the incident above it would have cut retention to priority 3's lag, not to zero.
    • It does nothing for paused or unserved queues, rate limits or permits. On 0.6 those remain an operator action (the warning, then move, cancel or resume), backed by storage isolation.
0.7
  1. Forward-port #797, #800 and step 2 to main. advance_spent_claim_heads exists only on release/0.6.6.
  2. Make the claim correct for any non-overlapping layout (#885). This is a prerequisite for moving rows between slots.
  3. Parked slots for stalled lanes. An ADR comes first. Shape:
    • Two extra slot numbers in the same partitioned tables, outside the ring arithmetic, so rotation, the ledger and the authority model are untouched. Upgrades build each child standalone and ATTACH it, since CREATE TABLE … PARTITION OF queues every query on the parent behind it.
    • The maintenance leader moves a stalled lane's whole pending range out of the oldest sealed slot into a parked slot, tombstoned rows included, in one transaction, and deletes the source rows. Batches are allowed only once step 4 is installed.
    • The trigger is a claim cursor that hasn't moved for a few ring wraps, not head age. A lane that is merely behind stretches the ring rather than stopping it, and parking it would double its write cost under overload.
    • There is no enqueue routing: new rows for a parked lane go to the ring and are moved when their slot becomes the oldest.
    • Off by default, and enabled only once every live runtime knows about parked slots.
    • The invariant to state is contiguity: for each lane and each slot, the lane's unclaimed rows there form a contiguous run of its unclaimed rows.
  4. Compaction, then slow lanes. When a parked slot holds more consumed rows than live ones, move every lane's remaining range to the other parked slot and truncate the first. Then consider parking slow lanes when the move frees more than it costs. If parking becomes the default, strict priority can be honoured exactly again, and step 2 becomes opt-in.
Not doing, and why
  • Carrying pending rows forward into the current slot (the original proposal 2). It puts a lane's oldest and newest rows in one slot with its middle elsewhere. A claim reads a slot from the cursor upwards, so it would take the newer rows and step the cursor past the middle ones. That loses jobs (#885).
  • Routing a parked lane's new enqueues elsewhere (a cold ring, per-lane slots, a slot pool). Every enqueue path would need a route that stale snapshots and older binaries can't misread. All it saves is one copy, on lanes nobody is consuming.
  • A second ring with its own cadence, or a dynamic slot pool. A stalled lane already has rows in every slot by the time it's detected, so both still need compaction. Step 6 gets the same reclamation without making the ring a dimension of every rotation, prune and metric path.
  • Demoting pinned rows to deferred_jobs. It changes job state (which interacts with unique_states), hides depth from autoscalers, and reorders the lane.
  • Making the prune gate ignore tombstones or look at segments instead of rows. Both weaken the check #847 relied on. Moving tombstoned rows along with their tombstones needs neither.
  • Separate rings per priority band, hash sub-partitions, or bigger rings. These only contain the problem, at a high catalog cost.

Reproduction

  1. Create a queue with lanes at priority 1 and priority 4, and set the priority aging interval to 0.
  2. Enqueue a few priority-4 jobs.
  3. Keep the priority-1 lane continuously backlogged with a small worker pool.
  4. Rotate slot_count - 1 times.

Expected: rotation then returns SkippedBusy indefinitely, and prune_oldest returns SkippedActive(QueuePendingReady) for the slot holding the priority-4 rows. Pausing a queue that has ready rows, then rotating, reproduces the same stall without priorities.

主要言語
Rust
スター
37
フォーク
8
平均マージ
14時間 16分
マージ済み PR(30日)
244

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

hardbyte/awa のほかの issue

hardbyte/awa の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。