Queue storage: cancel_by_unique_key without a queue still reads every retained receipt claim

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

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

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

評価

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

調査の方向性

Start by reading the unscoped cancel_by_unique_key and cancel_by_unique_key_tx paths, open_receipt_running_claims_sql, and the existing test_queue_storage_cancel_by_unique_key_reads_live_work_only test. Compare the three proposed approaches against the oldest-nonterminal semantics and the 0.7 partition migration cost. Done means the extended test shows rows read stay flat as other queues' backlogs and retained claims grow, without changing which job is selected.

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

説明

Follow-up to #585 / #586.

With a queue, admin::cancel_by_unique_key / cancel_by_unique_key_tx now start from that queue's ready rows holding the key. They check only those jobs for being available, leased or on an open receipt claim, and answer from the deferred_jobs key index when the queue has no such row. That cost follows the queue's own rows.

Without a queue (keys inserted without by_queue), the lookup still:

  • walks every lane's available rows from its claim cursor;
  • reads every open receipt claim (open_receipt_running_claims_sql) before filtering by key.

The second part grows with claim-ring retention. A long-running job keeps the oldest claim slot from pruning, so row-local claims from completed jobs pile up behind it.

Measurement

Default awa schema on PostgreSQL 16, with 180,200 retained ready rows and 120,300 retained row-local claims in other queues. The lookup was timed through cancel_by_unique_key_tx, rolled back:

p50
0.6.9 lookup (any key) 2.8 s
Pre-fix 0.6.10 lookup with a queue (reads the claim ring like the unscoped path) 9.7 s
Key-first lookup with a queue: missing key 1.7 ms
Key-first lookup with a queue: cancel a scheduled job 11 ms
Key-first lookup with a queue: cancel an available job 20 ms

Unscoped lookups still behave like the pre-fix row.

Options
  1. awa.job_unique_claims as a fast path. Look up job_id by unique_key, then confirm it with a per-job state check.
    • As #585 notes, it can't replace the lookup. A claim exists only while its job's state is inside its unique_states mask, and the API promises the oldest nonterminal job holding the key.
    • So a hit can return a job when no live job outside the mask can share the key; a miss still needs the fallback.
    • It helps the common default mask, but not a missing key.
  2. A partial index on ready_entries (unique_key) WHERE unique_key IS NOT NULL. With it, an unscoped lookup can start from the key the way a scoped one starts from the queue.
    • It costs every unique enqueue and needs an upgrade path for existing partitions (0.7 migration).
  3. Leave unscoped lookups as they are and document the cost. Point callers at by_queue keys or cancel-by-id for latency-sensitive paths.
Done when

An unscoped lookup's rows read stay flat as other queues' backlogs and retained claims grow (extend test_queue_storage_cancel_by_unique_key_reads_live_work_only), and the oldest-nonterminal semantics are unchanged.

主要言語
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 を短くまとめたダイジェスト。