Skip to content

feat(pg-delta): split plans to fit the lock-table budget - #462

Open
avallete wants to merge 10 commits into
mainfrom
avallete/230e62b4
Open

feat(pg-delta): split plans to fit the lock-table budget#462
avallete wants to merge 10 commits into
mainfrom
avallete/230e62b4

Conversation

@avallete

@avallete avallete commented Sep 7, 2026

Copy link
Copy Markdown
Member

Summary

  • Empty-target baselines can exhaust PostgreSQL's lock table in one transaction. Call estimateLockTableBudget on the apply target, then optionally splitPlan({ maxLocks }) so each segment tries to stay under that many lock slots.
  • apply honors newSegmentBefore already on the plan and does not probe or refuse. A single action that still exceeds the budget stays in its own segment; Postgres may still fail mid-statement.
  • CLI: --max-locks <n> (plan / apply / schema apply) and --split-to-fit (apply / schema apply; probes the target). Extra COMMITs are only safe when nothing else reads the target. Off by default, so existing plans and the corpus are unchanged.

Linked issue

Linear CLI-2304 (no GitHub issue).

  • The linked issue is open and carries the open-for-contribution label (or I'm a Supabase maintainer).

Checklist

  • Tests added or updated for the change
  • Changeset added if this is a user-facing fix/feature (bunx changeset)
  • bun run format-and-lint and bun run check-types pass

Test plan

  • Unit: bun test src/plan/baseline-commit.test.ts src/apply/lock-table.test.ts src/apply/apply.test.ts src/cli/commands/apply.test.ts and bun test src/
  • Integration: PGDELTA_TEST_IMAGE=postgres:17-alpine bun test tests/lock-table-budget.test.tssplitPlan({ maxLocks: budget.available }) then apply succeeds with residual 0
  • Corpus: PGDELTA_TEST_IMAGE=postgres:17-alpine bun test tests/engine.test.ts (666/666)
  • Confirm --max-locks / --split-to-fit appear on pgdelta apply --help and pgdelta schema apply --help; --max-locks only on pgdelta plan --help
  • Platform applyBaseline should later compose estimate + split (empty target by construction; out of this PR)

A single-transaction apply holds every created relation lock until COMMIT.
Probe the target budget (with connection/2PC reserve) and refuse before
the first DDL; opt-in baselineCommitEvery commits in chunks on empty
targets.
@changeset-bot

changeset-bot Bot commented Sep 7, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: cd33006

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@supabase/pg-delta Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

…chet

The new lock-holding kind set lives outside plan/rules, so the per-file
count proxy must include it or unit tests fail.
@pkg-pr-new

pkg-pr-new Bot commented Sep 7, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/supabase/pg-toolbelt/@supabase/pg-delta@462
npm i https://pkg.pr.new/supabase/pg-toolbelt/@supabase/pg-topo@462

commit: cd33006

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f2d81c37f6

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/pg-delta/src/apply/lock-table.ts Outdated
Comment thread packages/pg-delta/src/apply/lock-table.ts Outdated
Comment thread packages/pg-delta/src/apply/lock-table.ts
Comment thread packages/pg-delta/src/cli/commands/plan.ts Outdated
Comment thread packages/pg-delta/src/apply/lock-table.ts Outdated
Comment thread packages/pg-delta/src/apply/apply.ts Outdated
CI bun 1.3.13 timed those two tests out at 5s; the same file is instant
locally. Use the scripted one-client mock and a 1–2 action plan, and
preflight the working copy apply actually segments.
oxlint flags `await expect(...).rejects` as await-thenable; use the same
try/catch pattern as the other apply tests.
@avallete
avallete requested a review from jgoux September 7, 2026 16:48
Those two tests hang for the full 5s timeout on GitHub Actions bun 1.3.13
and do not reproduce locally. Preflight math stays in lock-table.test.ts;
apply wiring is covered by tests/lock-table-budget.test.ts.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 182f58b3d4

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/pg-delta/src/apply/lock-table.ts Outdated
… probe

Invalid --baseline-commit-every was parsed after extracts/profile resolve.
Reject it before opening a pool, and surface the lock-table preflight
SELECT as an apply control event so --verbose shows the wire.
avallete and others added 2 commits September 8, 2026 14:07
Drop the apply-time lock-table throw. Callers estimate a budget and
optionally split so each segment tries to stay under that many lock
slots; apply honors existing marks only.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ede43af7e2

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/pg-delta/src/plan/baseline-commit.ts
@avallete avallete changed the title feat(pg-delta): fail fast when a baseline would exhaust the lock table feat(pg-delta): split plans to fit the lock-table budget Sep 8, 2026
# Conflicts:
#	packages/pg-delta/src/cli/commands/plan.ts
#	packages/pg-delta/src/cli/commands/schema.ts
#	packages/pg-delta/src/cli/flags.test.ts
#	packages/pg-delta/src/cli/flags.ts
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