Files
FFF_vtt_frozen/docs/adr/0021-one-global-lock-v1.md
T
SirStone 8aaf03be04 docs: add ADRs for the durable design decisions
22 ADRs: server-authoritative sight and single egress, per-recipient views/diffs, uniform
nack, opaque ids, 32 px tile unit, wall switches/presets, see-over, thick walls, open-door
gap, typed wall columns, proto 2, build order, zoom clamp, accepted status leak, player
marker, chunked explored, slow-client policy, session/key split, closing message, character
records, global lock, synchronous choice. Each links its tickets and its spec section.
2026-11-17 23:12:04 +01:00

1.6 KiB

One global lock in v1, with persistence inside it

Intent handling, vision recomputation, the SQLite commit and the enqueue into per-connection outboxes all happen under one global lock; network sends happen outside it. We keep this in v1 because a table of at most ten clients is two orders of magnitude below the measured single-core limit (server total per mutation avg 0.70 ms), and because moving persistence out of the lock would break ack-after-commit and mutation order. The cost is a measured ~20 ms SQLite COMMIT tail that every other mutation queues behind.

Status

proposed (may be revisited on a measured p99 > 50 ms in production logs)

Alternatives

  • Per-scene or per-player locks: rejected for v1, no measured need and more deadlock surface.
  • Persist outside the lock: rejected, breaks ack-after-commit and order.
  • Group commit / world thread: considered, deferred as a post-v1 option with the JsonNode race fix.

Consequences

The egress borrows the live tables through a context of pointers rather than copying them, because a per-mutation copy of a large explored set costs milliseconds; nothing borrowed may outlive the lock. Every reader takes one scene snapshot under the lock. Hot-path code must not do blocking I/O, large formatting or per-cell work under it; logging and metrics are O(1) updates. A 583 ms outlier was observed once and not reproduced; production SLOW lines must make a recurrence diagnosable.

Tickets

#13 (slices), #28 (borrowed context), #31 (scene snapshot); docs/ANALYSIS-review.md adoption list.

Spec

Current §4.2, §4.3, §11.3.