[SLOP(claude-opus-4-8-high)] perf(universaldb): batch leader apply and fold follower commit round-trips - #5342
Conversation
PR Review: perf(universaldb): batch leader apply and fold follower commit round-tripsRe-reviewed at the current commit (a783a31, unchanged since my last pass). This PR eliminates per-row Postgres round-trips in the leader's drain loop: an in-memory Overlay folds a whole batch of winners before writing the merged write-set in O(1) statements, the lead loop splits into sibling renew_loop/drain_loop tasks so lease renewal cannot be starved by a slow drain, and the leader now encodes the commit outcome directly in the reply NOTIFY payload so followers resolve without a status SELECT. The fold_winners/Overlay logic is subtle (points-over-ranges-over-base read-through, versionstamp counters reset per winner) and apply_tests.rs covers it thoroughly against a serial oracle -- that part looks correct. The two issues from the previous review are still present and unaddressed: 1. Rolling-update protocol break -- every commit rides the 250ms backstop during upgrade Files: engine/packages/universaldb/src/driver/postgres/commit.rs:258 (parse_reply), engine/packages/universaldb/src/driver/postgres/resolver/mod.rs:571 (notify_after_commit) An old-code leader sends the bare id ("123") as the NOTIFY payload. The new parse_reply only understands "id:committed:version" / "id:conflict"; splitting "123" on the colon yields no second segment, so the verb parse returns None and the reply is silently dropped as not-for-me. A new-code follower talking to an old-code leader (or vice versa, mid rolling-deploy) then falls back to the RESULT_POLL_INTERVAL (250ms) backstop for every single commit until the upgrade completes cluster-wide. Correctness is preserved (the backstop still resolves it), but this is a real latency cliff during every deploy, and there is no version negotiation guarding it. Worth either a one-line backward-compat branch in parse_reply (bare-integer payload -> treat as committed) or an explicit documented requirement to drain the commit queue before a rolling restart. 2. RUST_LOG=universaldb::driver::postgres=debug baked into the production compose template Files: self-host/compose/template/src/docker-compose.ts:295, self-host/dev-multinode/docker-compose.yml:182,223,262 This permanently enables debug-level universaldb logging (including a log line per drain batch and per lease renewal, unbounded over process lifetime) in every deployment generated from the template, not just dev. dev-multinode is fine to have this always-on for local debugging, but the change to the shared template propagates to production-flavor configs on the next regen. Looks like a debugging aid that should either be dev-only or removed before merge. Additional notes from this pass
Minor/no-action-needed, unchanged from before: drain_loop's poll_interval is not pre-consumed before the loop (unlike renew_loop, which explicitly consumes the first tick), so the first busy-to-idle transition triggers one extra no-op drain_batch call -- harmless, just a small inconsistency in style between the two loops. |
234bfb3 to
099acee
Compare
…d fold follower commit round-trips
099acee to
a783a31
Compare
No description provided.