package granary

  1. Overview
  2. Docs
Pure-OCaml SQL engine

Install

dune-project
 Dependency

Authors

Maintainers

Sources

0.0.3.tar.gz
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.

Sourcetype t
Sourceval create : unit -> t

Create a fresh lock with no readers and no active writer.

Sourceval acquire_read : t -> unit Lwt.t

acquire_read increments the reader counter and returns immediately. Never blocks.

Sourceval release_read : t -> unit

release_read decrements the counter; broadcasts when it reaches zero (used by the checkpoint coordinator).

Sourceval acquire_write : t -> unit Lwt.t

acquire_write blocks while another writer is active. Does NOT block on active readers.

Sourceval release_write : t -> unit

release_write releases the writer lock, waking the next waiter.

Sourceval with_read : t -> (unit -> 'a Lwt.t) -> 'a Lwt.t

Acquire shared (reader) access for the duration of f.

Sourceval with_write : t -> (unit -> 'a Lwt.t) -> 'a Lwt.t

Acquire exclusive (writer) access for the duration of f.

Sourceval readers : t -> int

Number of currently-held read locks.

Sourceval writer_pending : t -> bool

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.

Sourceval writer_active : t -> bool

True iff a writer is currently holding the lock.