The tracker-mapping worker runs many Process calls in parallel. In Phase 4 a single transaction locked the worker's own claimed pattern row via UpdateMapping and then locked sibling rows on the same banner via the re-enqueue. Two workers mapping sibling patterns on one banner each held their own row and waited on the other's, forming a lock cycle that Postgres aborted with deadlock detected (40P01). Split the sibling re-enqueue into its own short transaction that runs after the mapping commits, so the claimed-row lock is released before any sibling row is locked. Also take the sibling UPDATE row locks in a deterministic id order through an ORDER BY id ... FOR UPDATE subquery, so overlapping re-enqueues can no longer invert lock order between themselves. The re-enqueue only flags siblings, so deferring it past the commit is safe and lets reprocessed siblings observe committed data. Signed-off-by: Émile Ré <emile@probo.com>
42 KiB
42 KiB