feat: session cache, explored bitmap and lock-free tile gate (#65)

The tile gate no longer takes dbLock or runs a SQL session JOIN per tile: a published
in-memory view (server/sessions.nim) holds token hashes -> player/role and one explored
bitmap per player. Sessions load from the DB at startup and are updated by join, key
replacement and player removal in the same lock as the write; refreshed cells publish
before the ack. The gate is one snapshot read (parse + session + bit test + redirect)
over scalar data only, so a tile burst is answered while a mutation holds dbLock.

Evidence: tests/tsessions.nim pins the cache/bitmap lifecycle and gate rule; tiles.test
adds the lock-held burst and the revocation/restart seam; auth.test adds the
LEAK_FAULT=sessioncache negative control (a stale entry makes the auth group fail);
mutation c5 keeps the cache drop load-bearing. Explored wire and persistence untouched.

Bench (devbox run bench, in-process): tile gate old 0.006 ms -> new 0.001 ms per
request; incremental explored mark 0.001 ms; snapshot build 2.0 ms at 262144 cells
(startup only).
This commit is contained in:
2026-11-21 00:10:39 +01:00
parent 3c0258ea31
commit 2727617db9
12 changed files with 664 additions and 56 deletions
+2 -2
View File
@@ -118,8 +118,8 @@ suite "tile access rule":
suite "one scene record per request (#31)":
test "a request built from one record stays internally consistent when the scene is swapped":
# What main.tileGate does: read the scene once under the lock, then parse, gate and build the
# redirect from that one local. A `scene.set` landing afterwards must not change the answer.
# The gate's one-record rule (#31, #65): parse, gate and build the redirect from one scalar
# `TileScene`; a `scene.set` landing afterwards must not change the answer.
var live = testScene()
let sc = live # the one read (`withLock` in main)
let parsed = parseOk(sc, "1", "v1", "9_9.png")