Adding a tier locks pools in creation order, while other paths sort them by pool id #194

Open
opened 2026-10-07 08:00:29 +00:00 by cgalo5758 · 0 comments
Owner

CreatePlanLadderTier (internal/server/operator_plan_ladders.go) aligns every live provision of the new tier's product inside one transaction, in the order GetLivePoolProvisionsByProductID returns them, which is creation order. Each core.align_conferral_shape call locks that provision's pool row, so the transaction locks several pools in creation order. The rule-change commit and tier removal lock the pools they touch in ascending pool_id order, and docs/database-locks.md states that order as the rule.

Two transactions that lock an overlapping set of pools in different orders can deadlock: a tier add and a tier removal, for example, when two organizations hold both tiers' products. Postgres then aborts one of them, and the operator's act fails for a reason they cannot act on. No row is left half written.

Done when: tier add locks the pools it will touch in ascending pool_id order before it aligns any of them, as tier removal does, and the tier-add entry under "Where the paths differ" in docs/database-locks.md is gone. #186 moves the pool lock into one helper; this issue is only about the order.

`CreatePlanLadderTier` (`internal/server/operator_plan_ladders.go`) aligns every live provision of the new tier's product inside one transaction, in the order `GetLivePoolProvisionsByProductID` returns them, which is creation order. Each `core.align_conferral_shape` call locks that provision's pool row, so the transaction locks several pools in creation order. The rule-change commit and tier removal lock the pools they touch in ascending `pool_id` order, and `docs/database-locks.md` states that order as the rule. Two transactions that lock an overlapping set of pools in different orders can deadlock: a tier add and a tier removal, for example, when two organizations hold both tiers' products. Postgres then aborts one of them, and the operator's act fails for a reason they cannot act on. No row is left half written. Done when: tier add locks the pools it will touch in ascending `pool_id` order before it aligns any of them, as tier removal does, and the tier-add entry under "Where the paths differ" in `docs/database-locks.md` is gone. #186 moves the pool lock into one helper; this issue is only about the order.
cgalo5758 added the
kind
bug
area/entitlementsarea/catalog
labels 2026-10-07 08:00:29 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: wiki-cafe/member-console#194