pgstore: advisory lock hash collisions can serialize unrelated streams #160

Closed
opened 2026-03-01 12:35:29 +00:00 by ash · 0 comments
Owner

Problem

Red team found: hashtext(streamID) maps stream IDs to int32 advisory locks. Two different streams can hash to the same value, causing one to block while the other holds the lock. Under heavy load with many streams, this reduces throughput.

Options

  1. Use two advisory locks (high + low 32 bits of a 64-bit hash) — reduces collision probability to ~1 in 4 billion
  2. Use pg_advisory_xact_lock(bigint) with a 64-bit hash
  3. Accept the collision rate and document it — at 10K concurrent streams, collision probability is ~0.001%

Priority

Medium — causes throughput degradation, not data corruption

## Problem Red team found: `hashtext(streamID)` maps stream IDs to int32 advisory locks. Two different streams can hash to the same value, causing one to block while the other holds the lock. Under heavy load with many streams, this reduces throughput. ## Options 1. Use two advisory locks (high + low 32 bits of a 64-bit hash) — reduces collision probability to ~1 in 4 billion 2. Use `pg_advisory_xact_lock(bigint)` with a 64-bit hash 3. Accept the collision rate and document it — at 10K concurrent streams, collision probability is ~0.001% ## Priority Medium — causes throughput degradation, not data corruption
ash closed this issue 2026-03-03 17:23:17 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ash/eskit#160
No description provided.