Skip to content

perf(github_hooks,zebra): add jobs expiring index - #1351

Open
loadez wants to merge 2 commits into
mainfrom
mf/zebra-jobs-retention-index
Open

loadez wants to merge 2 commits into
mainfrom
mf/zebra-jobs-retention-index

Conversation

@loadez

@loadez loadez commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-19T16:18:15.602165Z 974d4f2 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@loadez loadez changed the title perf(zebra): add partial index on jobs organization_id and created_at perf(github_hooks,zebra): add jobs expiring index and autovacuum thresholds Oct 20, 2026
skipi
skipi previously approved these changes Oct 29, 2026

@skipi skipi left a comment

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.

DDL ownership is right (github_hooks is the real migration, zebra the mirror) and the index matches zebra's unmark query. Nits on down, sizing and whether this already exists in prod.

On the PR description: Empty body. A line saying github_hooks is the real migration and zebra is the test mirror, and that prod already has these (so it no-ops there), would save the next reviewer the digging.

name: "index_jobs_on_organization_id_and_created_at_expiring",
algorithm: :concurrently,
where: "expires_at IS NOT NULL",
if_not_exists: true

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.

nit: Is index_jobs_on_organization_id_and_created_at_expiring already in prod under exactly this name? If it isn't, this builds concurrently on jobs while the hooks/sidekiq/repo-proxy pods are booting, and the other two deployments fail to get the migration lock until it finishes. I'd build it by hand first and check indisvalid: if_not_exists will also accept an INVALID leftover from an interrupted build.

Comment on lines +24 to +25
if PREVIOUS_SCALE_FACTOR.include?(table)
execute "ALTER TABLE #{table} SET (autovacuum_vacuum_scale_factor = 0.02)"

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.

nit: No migration ever set scale_factor = 0.02 on jobs / job_stop_requests, so on a DB built from migrations down leaves a setting that wasn't there before up. RESET alone is the inverse. Same in zebra/priv/legacy_repo/migrations/20261020120000_tune_autovacuum_on_jobs_tables.exs.

Comment on lines +4 to +9
THRESHOLDS = {
jobs: 500_000,
job_stop_requests: 50_000,
workflows: 300_000,
builds: 200_000
}.freeze

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.

nit: 500k / 300k / 200k dead tuples are prod-sized, and every install runs this. On a small install scale_factor = 0 means jobs effectively stops vacuuming on dead tuples and only vacuums on inserts. If prod already has these values, does it need to be a migration, or could the scale factor stay small but above zero?

@loadez
loadez force-pushed the mf/zebra-jobs-retention-index branch from 8e45440 to c6386a3 Compare October 29, 2026 16:52
@loadez
loadez force-pushed the mf/zebra-jobs-retention-index branch from c6386a3 to cb57ff0 Compare November 3, 2026 13:20
@loadez loadez changed the title perf(github_hooks,zebra): add jobs expiring index and autovacuum thresholds perf(github_hooks,zebra): add jobs expiring index Nov 3, 2026
@loadez

loadez commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

Dropped the autovacuum part, same as in #1350: fixed thresholds sized for large tables don't fit small installs, and large installations can tune these per table themselves. This PR now only adds the partial index on jobs (organization_id, created_at) WHERE expires_at IS NOT NULL, in the zebra test migrations and in github_hooks.

@loadez
loadez force-pushed the mf/zebra-jobs-retention-index branch 2 times, most recently from b1e577f to 14294fe Compare November 10, 2026 11:33
Build the index concurrently and only if it is missing so the migration
is safe on databases that already have it.

[db] Database changes (migrations, indexes, schema)
Add the partial index on jobs (organization_id, created_at) for rows
with expires_at set, the same index added to the zebra test migrations.
It is built concurrently and only if missing.

[db] Database changes (migrations, indexes, schema)
@loadez
loadez force-pushed the mf/zebra-jobs-retention-index branch from 14294fe to 6d8ff4e Compare December 4, 2026 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

2 participants