Skip to content

store: Persist postponed index creation as a once-only operation#6583

Merged
lutter merged 2 commits into
masterfrom
lutter/postpone
May 28, 2026
Merged

store: Persist postponed index creation as a once-only operation#6583
lutter merged 2 commits into
masterfrom
lutter/postpone

Conversation

@lutter
Copy link
Copy Markdown
Collaborator

@lutter lutter commented May 28, 2026

Track postponed-index creation in a new postponed_indexes_created column on subgraphs.deployment so the decision survives restarts and external index cleanup. The runner already gates creation on proximity to chain head; this makes the gate persistent.

Two problems with the prior behavior are fixed:

  1. An external process removes unused indexes. Because every call used CREATE INDEX CONCURRENTLY IF NOT EXISTS and we re-entered create_postponed_indexes on every restart, manually-dropped indexes were recreated. The flag now short-circuits the call after the first successful creation.

  2. start_subgraph called create_postponed_indexes eagerly on every restart, including immediately after a graft when the deployment is far below chain head. That call is removed; the runner-side path (already gated by close_to_chain_head) is now the only trigger.

The migration sets the flag to TRUE for deployments where synced_at IS NOT NULL, since those already had their postponed indexes created under the old code path.

Also removes the redundant WritableStore::postponed_indexes_created AtomicBool: the runner's in-memory guard already limits calls to at most one per restart, and the DB is now the single source of truth.

Copy link
Copy Markdown
Member

@incrypto32 incrypto32 left a comment

Choose a reason for hiding this comment

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

Should copying/graft also set postponed_indexes_created = true?

Otherwise copieddeployments can keep the flag false and later create_postponed_indexes may recreate indexes that was intentionally not carried over.

Copy link
Copy Markdown
Member

@incrypto32 incrypto32 left a comment

Choose a reason for hiding this comment

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

Looks good but left one question

lutter added 2 commits May 28, 2026 11:23
Track postponed-index creation in a new `postponed_indexes_created`
column on `subgraphs.deployment` so the decision survives restarts and
external index cleanup. The runner already gates creation on proximity
to chain head; this makes the gate persistent.

Two problems with the prior behavior are fixed:

1. An external process removes unused indexes. Because every call used
   `CREATE INDEX CONCURRENTLY IF NOT EXISTS` and we re-entered
   `create_postponed_indexes` on every restart, manually-dropped
   indexes were recreated. The flag now short-circuits the call after
   the first successful creation.

2. `start_subgraph` called `create_postponed_indexes` eagerly on every
   restart, including immediately after a graft when the deployment is
   far below chain head. That call is removed; the runner-side path
   (already gated by `close_to_chain_head`) is now the only trigger.

The migration sets the flag to TRUE for deployments where
`synced_at IS NOT NULL`, since those already had their postponed
indexes created under the old code path.

Also removes the redundant `WritableStore::postponed_indexes_created`
AtomicBool: the runner's in-memory guard already limits calls to at
most one per restart, and the DB is now the single source of truth.
@lutter lutter force-pushed the lutter/postpone branch from 4dca133 to 84293d2 Compare May 28, 2026 18:30
@lutter
Copy link
Copy Markdown
Collaborator Author

lutter commented May 28, 2026

Should copying/graft also set postponed_indexes_created = true?

Otherwise copied deployments can keep the flag false and later create_postponed_indexes may recreate indexes that was intentionally not carried over.

Nice catch! I changed things so that copy/graft now sets the flag when it is done creating indexes.

@lutter lutter merged commit 84293d2 into master May 28, 2026
6 checks passed
@lutter lutter deleted the lutter/postpone branch May 28, 2026 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants