[PM-38324] Optimize DeleteSendsJob - #8282
Conversation
🤖 Bitwarden Claude Code ReviewOverall Assessment: APPROVE Reviewed the chunked Findings from earlier review rounds were re-verified at |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #8282 +/- ##
==========================================
+ Coverage 63.66% 69.40% +5.73%
==========================================
Files 2430 2467 +37
Lines 104962 105801 +839
Branches 9506 9560 +54
==========================================
+ Hits 66822 73429 +6607
+ Misses 35844 29936 -5908
- Partials 2296 2436 +140 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…:bitwarden/server into tools/PM-38324-optimize-delete-sends-job merge main
| // queue and are re-fetched every iteration. Tracking distinct skipped ids bounds how much of | ||
| // a run can be wasted re-retrying the same stuck rows: once this set reaches BatchSize, every | ||
| // row in the next fetch is guaranteed to already be a known-stuck one. | ||
| var skippedIds = new HashSet<Guid>(); |
There was a problem hiding this comment.
❓If skippedIds reaches the batch size, does that mean that new expired Sends will not get deleted until someone intervenes to handle the stuck Sends? If that happens, do we have something monitoring this?
There was a problem hiding this comment.
If skippedIds reaches the batch size, does that mean that new expired Sends will not get deleted until someone intervenes to handle the stuck Sends?
Yes but keep in mind currently a single bad Send can cause this situation, and this happened earlier this year in our US Prod environment. This PR will improve resilience up until the batch size is met, this PR proposes 2,000 Sends per batch.
If that happens, do we have something monitoring this?
The job will log at a warning level. Can you propose a strategy more likely to raise an alarm? I am not certain how or whom is monitoring our logs at given levels. Would an error level log be more appropriate?
🎟️ Tracking
https://bitwarden.atlassian.net/browse/PM-38324
📔 Objective
During resolution of bitwarden/clients#16965 DbOps suggested a few improvements to the
DeleteSendsJob.Chunked fetch — add to Send_ReadByDeletionDateBefore and loop in the job so one run can't pull an unbounded backlog into memory + a tight delete loop.
Set-based Send_DeleteMany — delete the batch in one statement and bump each affected user once (collapsing N bumps ~distinct-user count), instead of N separate Send_DeleteById calls.
Optionally throttle between batches so a backlog drain spreads out rather than saturating the Hyperscale log.