Skip to content

Stores: lock(key), an exclusive named lock (#70) - #74

Merged
thorwhalen merged 1 commit into
mainfrom
feat/store-lock-70
Oct 14, 2026
Merged

thorwhalen merged 1 commit into
mainfrom
feat/store-lock-70

Conversation

@thorwhalen

Copy link
Copy Markdown
Collaborator

Adds store.lock(key): an exclusive, named context manager scoped to the store's data (for PostgresStore, its owner and project). Needed by reeleehq/reelee#632.

  • IntervalAnnotationStore.lock(key) in the protocol, with the semantics documented there: same key excludes, different keys do not, a dead holder releases it, not re-entrant.
  • PostgresStore: session-level pg_advisory_lock keyed on a 64-bit blake2b hash of owner + project + key (length-prefixed parts, so no concatenation collisions), on a dedicated connection and released in finally; a crashed holder frees it when its connection drops.
  • SqliteStore: a file lock (flock, msvcrt on Windows) on a sidecar file per key beside the .annot; excludes threads and other processes on the host. :memory: falls back to a process-local lock.
  • MemoryStore / MappingStore: process-local named locks; copies and pickles get fresh locks.
  • Mechanisms live in the new lacing/store/locking.py.

Tests: tests/test_store_lock.py (all in-process backends, plus a cross-process SQLite case) and TestLock in tests/test_store_postgres.py, run against a real PostgreSQL server: two connections contend for one key (second blocks until the first releases), different keys and different projects do not contend, release on exception. Full suite: 906 passed.

Closes #70

🤖 Generated with Claude Code

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@thorwhalen
thorwhalen merged commit 1eddbb5 into main Oct 14, 2026
12 checks passed
@thorwhalen
thorwhalen deleted the feat/store-lock-70 branch October 14, 2026 13:00
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.

Store lock(key): an exclusive lock held in the shared store

1 participant