Skip to content

fix: a backfilled window always attaches with writers held at the parent - #89

Merged
AlexeyShalaev merged 1 commit into
masterfrom
fix/backfill-attach-holds-writers
Oct 1, 2026
Merged

AlexeyShalaev merged 1 commit into
masterfrom
fix/backfill-attach-holds-writers

Conversation

@AlexeyShalaev

Copy link
Copy Markdown
Member

Second thing the Outpost measurement found, after #87. During backfill, with a writer inserting 20 events a second into the current month, two inserts failed:

CheckViolationError: new row for relation "events_default" violates partition constraint

_attach_with_reconcile tries a plain ATTACH first and moves to reconcile_and_attach only on a DEFAULT conflict. After a fill, DEFAULT usually holds nothing for the window, so the plain attach goes through. It takes SHARE UPDATE EXCLUSIVE on the parent, which writers pass. An insert for the window that arrives during the attach routes to DEFAULT from the tree as it was, queues on DEFAULT's ACCESS EXCLUSIVE, and once the attach commits it is rejected by DEFAULT's narrowed constraint. _lock_for_attach describes exactly this race, and the backfill docs already say this attach holds writers at the parent; the code only did when rows had arrived.

A window filled from DEFAULT now skips the plain attempt and attaches through reconcile_and_attach: EXCLUSIVE on the parent, so the insert waits there and lands in the new partition, and whatever arrived after the last batch goes in under the same lock. Attaches that follow no fill are unchanged: create-ahead windows are attached before anything writes into them.

The test holds the attach's transaction open after its ATTACH, sends one insert for the window, waits until it is queued, and lets the attach commit. Before the fix the insert fails with the check violation; after it, it is in the partition.

  • unit: 2861 passed
  • integration (PG 17): 573 passed
  • ruff, mypy clean

The attach that ends a window partition_data filled tried a plain
ATTACH first and fell back to reconcile_and_attach only on a DEFAULT
conflict. With nothing left in DEFAULT for the window, the plain attach
went through, and an insert into the window that got past the parent
while it was in flight chose DEFAULT from the old tree, queued on
DEFAULT's lock and was rejected by the narrowed constraint. The current
month under a live writer hits that.

A filled window now skips the plain attempt and attaches through
reconcile_and_attach, which holds writers at the parent and takes the
rows that arrived after the last batch, as the docs already describe.
@codecov

codecov Bot commented Oct 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@AlexeyShalaev
AlexeyShalaev merged commit b1260c1 into master Oct 1, 2026
32 checks passed
@AlexeyShalaev
AlexeyShalaev deleted the fix/backfill-attach-holds-writers branch October 1, 2026 20:23
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