Skip to content

storage: is_vanished takes the single LMDB writer, and commits, on every EVENT #1312

Done

Description

@chappie-daemon

Found by job 045's code lens (row 5 of #868) at 8488bf13.

users::is_vanished returns the stored flag at crates/nostream-storage/src/lmdb/users.rs:113 without writing, but crates/nostream-storage/src/lmdb/mod.rs:886 takes self.write(...), which opens an RwTxn and commits it (the helper at crates/nostream-storage/src/lmdb/mod.rs:470-485), and LMDB admits one writer at a time. The relay asks per event at crates/nostream-relay/src/handlers/event.rs:478. The Postgres arm reads on master and takes a write only when hydrating (crates/nostream-storage/src/postgres/repository.rs:217-226).

Evidence

grep -n 'self.write(move |txn, databases| users::is_vanished' crates/nostream-storage/src/lmdb/mod.rs → 886: self.write(move |txn, databases| users::is_vanished(txn, databases, &pubkey, now))

What a fix changes

Read with find_by_pubkey and take the write only on the hydration branch. Today every event from a non-relay pubkey serialises all writers behind a transaction that usually writes nothing.

Acceptance

  • A store-wide concurrent-write case shows EVENT admission no longer queues behind the banned-user read.
  • The read path opens env.read_txn() for a pubkey that is present.

Record: docs/rewrite/reviews/2026-11-30-relay-storage.md — finding F4, lens code, tree 8488bf13.

Activity

  1. added
    bug
    rewrite
    rust
    factory
    on Nov 30, 2026
  2. chappie-daemon commented on Dec 4, 2026

    @chappie-daemon
    CollaboratorAuthor

    Closed by a70e1085688b01427bf950b76133b59a5e7620fb (#1389).

    is_vanished reads first (self.read + users::find_by_pubkey) and takes the LMDB writer only when no user row exists — the hydration branch, whose body still re-loads before scanning and upserting. The common path no longer opens a write transaction per event, so EVENT admission stops queueing behind a banned-user read.

    Measured: before, is_vanished held me_wmutex from begin to commit even though the empty commit wrote nothing (last_txn_id did not move) and did not return within 800/785/786 ms with a writer held, 3 of 3 runs. After: one RoTxn, no RwTxn, and readers take me_rmutex while writers take me_wmutex, so the read holds nothing a writer needs.

    The held-writer case is the deterministic form of the acceptance line: one create future blocked against a held writer, is_vanished on a present pubkey answering within the bound, then the writer dropped and the same future re-polled and succeeding. Red with the base body restored (Elapsed(()) after 10.21 s). parity_lmdb 52 passing unchanged, lib 151.

    Accepted and stated in the spec: the read is a snapshot, so one event can slip past a racing set_vanished — the same window the Postgres arm already has. The throughput figure (p50/p95 writer wait with and without the read) remains unmeasured for lack of a bench shape.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugfactoryrewriterust

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions