M4: session cache, explored bitmap and lock-free tile gate #65
Notifications
Due Date
No due date set.
Blocks
Depends on
#69 M4: map tiles, grid and pan/zoom
SirStone/FFF_vtt_frozen
#70 M4: fog: explored bitmap, vision cut-out and player markers
SirStone/FFF_vtt_frozen
#75 M4: GM characters, reveals and who-sees-it
SirStone/FFF_vtt_frozen
#64 M4: sector-limited circle-segment ray test
SirStone/FFF_vtt_frozen
Reference: SirStone/FFF_vtt_frozen#65
Reference in New Issue
Block a user
Part of #63
Goal
Tile requests stop taking the global lock and stop hashing/selecting in SQLite; sessions come from an in-memory table, explored from a bitmap snapshot.
Acceptance criteria
dbLockdevbox run testgreen on a clean checkout, no test weakened or skipped, and the behaviour above proven at the seam(s) listed under "Proven at".User stories covered
Proven at
server auth/session, explored, tile gate; Nim unit + HTTP suites
Notes
Implemented in
2727617(rebased on3c0258e; fulldevbox run testgreen on the rebased tree: 157 node tests + Nim suite, evidence 19/19).What changed
server/sessions.nim(new): the tile gate's published read-side view — token hash →(playerId, isGm)loaded fromsession/playerat startup, plus one exploredBitMapper player. All reads are scalar/borrowed (TileScene,openArray[byte]), no ORC refcount traffic across workers.main.nim:tileGateis one snapshot read (gateTile: parse → session → bit → redirect), nodbLock, no SQL, one SHA-256.refreshPlayerpublishes the cells a refresh added before the ack.POST /joinadds;key.replaceandplayer.removedrop in the samedbLockas the write; startup reloads sessions + bitmaps.explored.nim:BitMap/bitMapOf/setBit/bitSet;tiles.nim:TileScene+tileCoveredByBits. Explored wire (views) and chunk persistence untouched.AC evidence
dbLock:tools/tiles.test.mjsstatic check (noapp.scene/dbLockintileGate, exactly onegateTile) +tile gate: a burst is answered while a mutation holds the global lock(LEAK_FAULT=lockholdsleeps 1.2 s insidetoken.moveunder the lock; 32 concurrent tiles answer in <700 ms).tile gate: revocation is immediate and sessions survive a restart(old cookie 403 at the gate and 401 at upgrade on the next request; new key allowed; restart keeps live sessions, does not resurrect revoked ones);tests/tsessions.nimpins drop/restore and the bitmap lifecycle.fault sessioncache: a revoked session kept alive fails the authentication group(LEAK_FAULT=sessioncacheskips the cache drop → old cookie upgrades 101 instead of 401; the cleankey.replacegroup assertion is the other half).mutation.sh c5(drop the cache delete) failstsessions"a revocation drops every cached session" — verified against a mutated copy.Bench (
devbox run bench, in-process, release): tile gate old (parse + SHA-256 +session JOIN+ HashSet) 0.006 ms/request → new (parse + SHA-256 + cache lookup + bitmap) 0.001 ms; incremental explored mark (16 cells) 0.001 ms; full snapshot build 2.0 ms at 262 144 cells (startup/restore only). The old 0.006 ms is an in-memory SQLite lower bound and still paiddbLock; the gate's win is structural, not just these numbers.Results scratch files were reverted; no test was weakened or skipped (the #31 static test was strengthened for the new architecture).
Review: no race (TSAN/ASAN stress clean, negative control races); gate uses a private mutex, dbLock-free; DESIGN §4.3 corrected in
e254a0e. GateCache.setScene has no production caller — kept for scene.set when tile fields become patchable.