Batch B1: #10 Mnesia indexes + #11 stale-row sweeper #51

Merged
amiryahaya merged 3 commits from fix/b1-mnesia-perf into main 2026-11-15 06:32:53 +01:00
Owner

Performance/durability batch.

  • #10 (H-6): secondary indexes (cert_serialnumber, ic_number, client_id, identifier) with index_read lookups + backfill migration for existing volumes
  • #11 (H-7): supervised StoreSweeper — expired tokens (>24h past expiry) and stale login attempts (>48h) purged every 6h

190 tests green locally (3 new sweeper tests).

Fixes #10
Fixes #11

Performance/durability batch. - **#10 (H-6)**: secondary indexes (cert_serialnumber, ic_number, client_id, identifier) with index_read lookups + backfill migration for existing volumes - **#11 (H-7)**: supervised StoreSweeper — expired tokens (>24h past expiry) and stale login attempts (>48h) purged every 6h 190 tests green locally (3 new sweeper tests). Fixes #10 Fixes #11
perf(store): Mnesia secondary indexes + stale-row sweeper
All checks were successful
Lint / lint (pull_request) Successful in 2m41s
Security / Dependency advisories (mix hex.audit) (pull_request) Successful in 31s
Security / Secret scan (gitleaks) (pull_request) Successful in 11s
Unit tests / test (pull_request) Successful in 3m7s
2b6e530a2b
#10 (H-6): certificate_request gets indexes on :cert_serialnumber and
:ic_number (created with the table and backfilled for existing volumes);
finds use :mnesia.index_read instead of full-table match_object scans —
every status check, enrollment pre-check and OCSP request was O(all
certificates ever issued). oauth_client indexed on :client_id (every JWT
verification); login_attempt uses its existing :identifier index.

#11 (H-7): new StoreSweeper GenServer (supervised, 6h interval) deletes
access tokens expired beyond a 24h grace window and login attempts older
than 48h — both tables previously grew without bound and could be
bloat-attacked anonymously.

Fixes #10, Fixes #11
perf(store): address code-review findings on #10/#11
Some checks failed
Lint / lint (pull_request) Successful in 2m52s
Security / Dependency advisories (mix hex.audit) (pull_request) Successful in 25s
Security / Secret scan (gitleaks) (pull_request) Successful in 13s
Unit tests / test (pull_request) Has been cancelled
29aa2fa5e7
- boot-race fixed: wait_for_tables runs BEFORE the index backfill —
  add_table_index aborts {:no_exists, _} during the async disc_copies
  load window, which raised at boot on large pre-existing volumes
  (review finding, reproduced at 200k rows)
- index backfill now runs once per node (:persistent_term guard) — it
  previously ran on every save/find/delete, two schema transactions
  per certificate operation
- sweeper deletes in chunked transactions with an in-transaction
  re-read + predicate re-check: concurrent rate-limiter writes can no
  longer have fresh lockouts deleted mid-sweep (TOCTOU); cadence and
  age thresholds configurable via app env; listing failures logged
- oauth_client client_id index (lost in an earlier failed batch
  script — the commit previously claimed it) now actually applied,
  with index_read lookup and backfill for existing tables
- login_attempt :identifier index backfilled for foreign/legacy
  tables (previously silently failed open without it)

Fixes #10, Fixes #11
perf(store): address code-review findings on #10/#11
All checks were successful
Lint / lint (pull_request) Successful in 2m36s
Security / Dependency advisories (mix hex.audit) (pull_request) Successful in 31s
Security / Secret scan (gitleaks) (pull_request) Successful in 10s
Unit tests / test (pull_request) Successful in 3m15s
741c8a6802
- boot-race fixed: the index backfill waits for the table to LOAD first
  (add_table_index aborts {:no_exists, _} during the async disc_copies
  load window — a boot crash loop on large pre-existing volumes)
- index backfill self-heals: a cheap :mnesia.table_info(:index) check
  replaces per-op schema transactions AND recovers when a table is
  recreated without indexes (legacy-migration path), instead of a
  sticky :persistent_term flag that broke backfill after table
  recreation (63 test failures — legacy migration test recreates the
  table without indexes)
- sweeper deletes in chunked transactions with an in-transaction
  re-read + timestamp re-check: concurrent rate-limiter writes can no
  longer have fresh lockouts deleted mid-sweep (TOCTOU); cadence/ages
  configurable via app env; listing failures logged; tuple field
  position off-by-one fixed
- oauth_client client_id index applied (a previous commit claimed it
  but the edit was lost in a failed batch script) — index_read lookup
  + backfill for existing tables
- login_attempt :identifier index backfilled for foreign/legacy
  tables (previously silently failed open without it)

Fixes #10, Fixes #11
Sign in to join this conversation.
No description provided.