Skip to content

fix(partition-keys): make claims nonblocking - #321

Draft
NikolayS wants to merge 3 commits into
agent/fix-partition-lease-boundaryfrom
agent/fix-claim-slot-nonblocking
Draft

fix(partition-keys): make claims nonblocking#321
NikolayS wants to merge 3 commits into
agent/fix-partition-lease-boundaryfrom
agent/fix-claim-slot-nonblocking

Conversation

@NikolayS

Copy link
Copy Markdown
Owner

Stack

This PR is intentionally stacked on #311 because both changes touch the partition lease implementation. Review only the commit above agent/fix-partition-lease-boundary.

What changed

  • use a non-blocking row lock in claim_slot;
  • return NULL when another transaction currently owns the slot row, allowing a first-free scan to continue;
  • keep the distinct “slot is not subscribed” error when no row exists;
  • reject non-finite lease TTLs;
  • extend the real two-session lease harness with an uncommitted-row-lock contender;
  • run that harness in every PostgreSQL matrix lane;
  • add PostgreSQL 19 infinite-lease coverage and regenerate development artifacts.

Why

The API contract says a busy claim returns NULL; it previously blocked on SELECT ... FOR UPDATE. A slow claim/renew/receive transaction could therefore head-of-line-block a worker scanning for any free slot.

Fixes #309.

Validation

Red evidence on the parent/current behavior:

ERROR: canceling statement due to statement timeout
CONTEXT: while locking tuple ... in relation "partition_slot"

Green checks:

  • real two-session harness: contender returns NULL behind an uncommitted lease row, existing lease-expiry/epoch recovery still passes;
  • PostgreSQL 14: complete partition regression;
  • PostgreSQL 18: complete partition regression + two-session harness;
  • PostgreSQL 19 beta 1: complete partition regression including infinite-TTL rejection;
  • bash build/transform.sh;
  • workflow YAML parse, shell syntax, and git diff --check.

This is intentionally a draft and has not been merged.

@NikolayS
NikolayS changed the base branch from agent/fix-partition-lease-boundary to main July 11, 2026 13:56
@NikolayS
NikolayS changed the base branch from main to agent/fix-partition-lease-boundary July 11, 2026 13:58
@NikolayS
NikolayS changed the base branch from agent/fix-partition-lease-boundary to main July 11, 2026 13:58
@NikolayS NikolayS closed this Jul 11, 2026
@NikolayS NikolayS reopened this Jul 11, 2026
@NikolayS
NikolayS changed the base branch from main to agent/fix-partition-lease-boundary July 11, 2026 14:00
@NikolayS
NikolayS changed the base branch from agent/fix-partition-lease-boundary to main July 11, 2026 14:12
@NikolayS NikolayS closed this Jul 11, 2026
@NikolayS NikolayS reopened this Jul 11, 2026
@NikolayS
NikolayS changed the base branch from main to agent/fix-partition-lease-boundary July 11, 2026 14:15

@NikolayS NikolayS left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

REV rubric review

This is a manual execution of the repository's five applicable REV rubrics because the automated ultrareview quota was unavailable. It is not bot output. SOC2 was omitted.

  • Bug/security: SKIP LOCKED plus the existence check distinguishes busy from absent slots without blocking; no additional defect found.
  • Tests: the real two-session contender, expiry, epoch, and finite-TTL paths are adequate; CI is 17/17 green. Initial RED is retrospective.
  • Docs/guidelines: final shell hardening adds the required safe IFS and reproducible psql form. The historical style: commit conflicts with the repo-specific type list.

Blocking patch findings: none. Merge-order constraint: this PR is stacked on #311 and must merge after it; rerun combined checks if the parent head changes. Exact real-user two-session evidence remains required. This COMMENT review is not an approval.

@NikolayS

Copy link
Copy Markdown
Owner Author

Real-user verification evidence for head 66dc74a6077367e994016a39fddcaa9b6eca591a, tested with its #311 parent.

I installed the stacked head into a fresh disposable database, then ran the real multi-backend harness:

PAGER=cat psql --no-psqlrc "$PGQUE_TEST_DSN" --set=ON_ERROR_STOP=1 \
  --file=devel/sql/pgque.sql
PGQUE_TEST_DSN="$PGQUE_TEST_DSN" tests/two_session_slot_claim.sh
bash -n tests/two_session_slot_claim.sh
shellcheck tests/two_session_slot_claim.sh
bash build/transform.sh
git diff --check

Against the parent behavior, the contender hit the harness timeout while waiting on an uncommitted slot-row lock:

FAIL: claim_slot blocked behind an uncommitted lease row
ERROR: canceling statement due to statement timeout
CONTEXT: while locking tuple ... in relation "partition_slot"

Against this head, the contender returned NULL promptly and the rest of the cross-backend lease lifecycle passed:

PASS: lease is exclusive across backends (outlives a dead one for its TTL); dead worker's slot recovered after TTL expiry; epoch bumped on takeover (fencing)

The harness uses distinct psql backends, including one holding uncommitted row DML, a contender, and a post-TTL successor. Focused partition tests passed on PostgreSQL 14, 18, and 19beta1, including the PG19beta1 infinite-TTL rejection. Shell syntax and ShellCheck also passed after the harness hardening.

RED/GREEN chronology: retrospective for the SQL behavior. The nonblocking implementation and regression were not published as separate test-first RED and GREEN commits. I independently replayed the harness on the parent to confirm RED and on this head to confirm GREEN. The later harness-only hardening did not alter the SQL behavior.

Full CI: 17/17 checks passed.

This comment records test evidence only; it is not a review or merge decision.

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.

fix(partition-keys): make claim_slot non-blocking under concurrent lease DML

1 participant