package granary
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=8b18780ea373be48301d9f333925860a2f9110fc0ac28684295118d72b65a67e
sha512=25ca3c9c5e2b528704a542502e0f37dc33ba003f65622d969b8c2b800778585f8ef0cf89b36e6679832e3993e8303aecddfc662742baf7044d6afe4a796b8f11
doc/granary.store/Granary_store/Rwlock/index.html
Module Granary_store.RwlockSource
Writer-mutex + reader-counter for Lwt.
Semantics (intentionally NOT a classic shared/exclusive RwLock):
- Many readers run concurrently and never block.
- Writers serialise against other writers (one at a time).
- Readers do NOT block writers. Writers do NOT block readers.
Rationale: under snapshot isolation (see Store.ro_snapshot and Pager.read ~snapshot_frames) a reader's view at WAL frame N is invariant under a concurrent writer's appends, so reader/writer mutual exclusion is not needed for correctness. This module only serialises writers and tracks active readers for the checkpoint coordinator.
Re-entrancy is NOT supported — a fiber that holds the writer lock must not call acquire_write again.
acquire_read increments the reader counter and returns immediately. Never blocks.
release_read decrements the counter; broadcasts when it reaches zero (used by the checkpoint coordinator).
acquire_write blocks while another writer is active. Does NOT block on active readers.
Acquire shared (reader) access for the duration of f.
Acquire exclusive (writer) access for the duration of f.
True iff a writer is currently holding (or queued for) the lock. Diagnostic only — not used by Store for any control flow now that readers and writers don't mutually exclude.