relay: batch audit-log appends per community (T2a write-amp)#2126
relay: batch audit-log appends per community (T2a write-amp)#2126tlongwell-block wants to merge 1 commit into
Conversation
Amortize the per-message audit cost: the worker now drains up to BUZZ_AUDIT_BATCH_MAX entries (default 100) per BUZZ_AUDIT_BATCH_INTERVAL_MS window (default 50ms) instead of one txn + advisory lock round trip per entry. - AuditService::log_batch: single-community atomic multi-row append. Head re-read inside the txn under the same per-community advisory lock; entries chain in input order; log() delegates to a batch of one so there is exactly one chain-append implementation. Mixed-community batches are rejected (MixedBatch) before any lock is taken. - Worker flush partitions FIFO-per-community, appends each community's run atomically. Cross-community order carries no chain meaning. - Failure classification (AuditError::is_deterministic): SQLSTATE 22/23 are entry-dependent; everything else is infrastructure and retried with backoff (3 attempts) — an outage never marks healthy entries as poison. Deterministic failures bisect the slice so a poisoned batch of N drops exactly 1 entry, never the other N-1. - Shutdown drain reuses the same batched flush path. Postgres-gated tests: batch chain linkage + verify, mixed-batch rejection without writes, poisoned-batch atomicity + deterministic classification, bisection drops exactly the poison with chain intact, cross-tenant poison isolation in one drained batch. Co-authored-by: Tyler Longwell <tlongwell@block.xyz> Signed-off-by: Tyler Longwell <tlongwell@block.xyz>
|
Not ready at
Hardening while touching config: Verified exact head |
What
Batch audit-log appends per community instead of one transaction + advisory-lock round trip per entry. T2a of the write-amplification workstream — the audit path is one commit per message today; batching amortizes it to ~1/N under load.
Design
AuditService::log_batch— single-community atomic multi-row append. Head re-read inside the txn under the same per-community advisory lock; entries chain in input order.log()delegates to a batch of one, so there is exactly one chain-append implementation. Mixed-community batches are rejected (MixedBatch) before any lock is taken.BUZZ_AUDIT_BATCH_MAXentries (default 100) perBUZZ_AUDIT_BATCH_INTERVAL_MSwindow (default 50 ms), partitioned FIFO-per-community; each community's run appends atomically. Cross-community order carries no chain meaning.AuditError::is_deterministic) — SQLSTATE 22/23 are entry-dependent; everything else is infrastructure, retried with backoff (3 attempts). An outage never marks healthy entries as poison.Testing
cargo test -p buzz-relay: 687 pass / 1 fail — the 1 is the knownmesh_demofailure that is also red on untouched main.Part of the write-amp series; sibling PR: #2125 (T1a TTL skip, measured 11→10 commits/msg).