[slopfix] fix(universaldb,util,pegboard-envoy): index dedup gc, fix fixed-window acquire, refund rate-limit tokens on cancel - #5551
Conversation
ReviewReviewed the 3 changed files (postgres/database.rs, throttle.rs, tests/throttle.rs). This is a clean, well-scoped fix. throttle.rs — FixedWindow acquire() fix Correct bug fix, two real problems addressed:
Both are exercised by the two new tests (fixed_window_acquire_waits_only_for_the_remainder_of_the_window, fixed_window_acquire_debits_the_window_it_waited_for), which clearly assert the previously-buggy behavior. Good regression coverage. Minor/non-blocking: after waking, *reset_time = Instant::now() + *period is based on actual wake time rather than the scheduled *reset_time + *period, so windows can drift slightly long under scheduler delay. This matches the existing behavior in the reset branch of try_acquire/acquire, so its a pre-existing pattern, not a new issue, just flagging in case its worth a follow-up for tightening window bounds. tests/throttle.rs Moving the inline #[cfg(test)] mod tests out of src/throttle.rs into tests/throttle.rs matches the repo convention in CLAUDE.md ("Rust tests live under tests/, not inline ... in src/"). All items used (RateLimiter, RateLimitMethod, try_acquire, acquire) are already pub, so no visibility changes were needed. test-util is already a dev-dependency in Cargo.toml, so start_paused = true / tokio::time::advance continue to work as an integration test. postgres/database.rs — new index udb_applied_created_at_idx on created_at directly targets the GC query in spawn_gc (DELETE FROM udb_applied WHERE created_at < now() - ...), which previously had no usable index (PK is (client_node_id, client_seq)) and would have been a full table scan every GC_INTERVAL tick. Good performance fix, and CREATE INDEX IF NOT EXISTS keeps init_schema idempotent across restarts. Minor/non-blocking: this is not CONCURRENTLY, so on the first deploy after this change, index creation will briefly hold a lock that blocks writes to udb_applied while it builds against existing rows. Given the table is continuously GCd down to DEDUP_ROW_MAX_AGE_SECS, it is likely small in practice, so this is probably fine, just noting it in case any deployment has an unusually large backlog. Other notes
Overall: solid, well-tested fix. No blocking issues found. |
…ixed-window acquire, refund rate-limit tokens on cancel
42d8359 to
2e17d96
Compare
No description provided.