Skip to content

executor: report and cancel an online attach's index builds - #658

Draft
Kiran01bm wants to merge 1 commit into
mainfrom
kiran01bm/pd109-attach-index-tracker
Draft

Kiran01bm wants to merge 1 commit into
mainfrom
kiran01bm/pd109-attach-index-tracker

Conversation

@Kiran01bm

Copy link
Copy Markdown
Collaborator

An online ATTACH PARTITION now reports its index builds to the run's progress tracker, so a host can watch them and stop one with CancelBuild.

Why

Before attaching a table as a partition, pg-sprite builds on it every index the parent has, concurrently, which on a large table can take hours. Those builds ran without the run's progress tracker, so a host such as SchemaBot showed nothing while they ran and had no way to stop one short of killing the session, unlike every other concurrent index build pg-sprite runs.

What

  • The attach flow hands its tracker and step callback to ensureAttachIndexes, which passes them to both build paths: a plain index, and a key index through the leaf key step (ensureAttachKeyIndex, ensureLeafKeyExcept, buildLeafKeyIndex). Each build is announced as concurrent-index-build with its statement before it starts. The partitioned key build still passes nil, as before.
  • The leaf key step's refusal details and error context say "table" for a table not yet attached (partitionNode.noun()); the partitioned key build's wording is unchanged.
  • The attach index refusals already had codes on main (attach-partition-index-unsupported, permanent; attach-partition-not-ready, retryable). schemabot-integration.md gains rows for a cancelled build (invalid-index-own-leftover, rerun gets past it) and for the key step's refusals reached from an attach (permanent), and no longer says hosts see no progress.
  • LK-2 names the attach index and leaf key steps as handing the tracker to their builds.
  • Tests: an old snapshot stalls the first build in its "waiting for old snapshots" phase; the tracker shows the build's step, operation, statement and server counters; CancelBuild stops it with invalid-index-own-leftover, the table stays unattached, and a rerun attaches. Plain and key variants, on PG 14 and 16; a flow-level test checks the unsupported and conflict codes.

Before / after

The same attach of a large events_2026 table whose parent has a primary key, while an operator wants to stop the build.

ALTER TABLE events ATTACH PARTITION events_2026 FOR VALUES FROM ('2026-01-01') TO ('2027-01-01')

Before
  CREATE UNIQUE INDEX CONCURRENTLY ... ON events_2026 (id)    running for hours
  tracker.Progress()      → nothing about the build
  tracker.CancelBuild()   → ErrNoActiveBuild           only pg_cancel_backend stops it

After
  CREATE UNIQUE INDEX CONCURRENTLY ... ON events_2026 (id)    running
  tracker.Progress()      → step 1, concurrent-index-build, the statement, server counters
  tracker.CancelBuild()   → build stops: invalid-index-own-leftover, events_2026 not attached
  rerun                   → drops the leftover, builds the index, attaches

The attach flow built the table's indexes with no tracker, so a host could
neither show nor stop a build that can run for hours. The leaf refusals it
reuses now say "table" for a table not yet attached.
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.

1 participant