Repository navigation
fix(blob): MongoDB sweep reclaims each key only up to its newest expired version - #98
Conversation
…red version sweep_expired re-queried every expired key by filename alone and deleted all of its versions newest first. A version written after the sweep began was deleted with them, and a failure partway could leave an older, superseded version as the newest. The sweep now takes, per key, the newest version that was expired in its first pass and deletes only versions up to it, oldest first. Versions written since are newer and stay; a sweep that fails partway never exposes a superseded version. The storage-bus spec section on blob lifetimes is corrected: no driver reclaims on read, it named sweep functions that do not exist, and it now says which sweeps can still race a re-put (file, S3). Closes tinyhumansai#38
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
Tiny Sweeper reviewReviewed head: Verdict: Ready for maintainer review · Priority: none Diagnostics and supporting detailsFull summaryPull request purpose (title): fix(blob): MongoDB sweep reclaims each key only up to its newest expired version. Tiny Sweeper completed its review; deterministic results follow. Review snapshot
Completeness: Complete What changed`sweep_expired` in `MongoBlobStore` now collects the first file seen per key from the expiry query — the newest expired version, given the shared `files()` ordering of `filename` ascending and `_id` descending — instead of a bare set of expired keys. It then re-queries with both the filename and `_id <= bound` and deletes the returned versions in reverse (oldest first), so a version written since the sweep began is past the bound and survives, and a partial failure never leaves a superseded version as the newest. A `#[cfg(test)]` `sweep_pause` field on the store, set through `pause_sweep_for_test`, pauses the sweep between its two passes via a started/resume notify pair. The *Blob lifetimes* section of `docs/specs/storage-bus.md` is rewritten to state that no driver reclaims storage on the read that notices a lapsed blob, to drop the non-existent `sweep_expired_blobs` / `sweep_expired_blobs_generation` names, and to distinguish atomic (memory, SQLite), bounded (MongoDB) and check-then-delete (file, S3) sweeps. Two live-MongoDB tests cover the bounded reclaim and the between-passes rewrite. Features
TestsNo supported feature-to-test mapping was produced. Test execution is not inferred. FindingsNo active actionable findings. Before mergeNone. Agent review detailscritique
security
tests
commits
description
Evidence and run details
|
Summary
MongoBlobStore::sweep_expiredcollected expired keys in one pass, then re-queried each key by filename alone and deleted every version it found, newest first. That had two problems:The sweep now takes, per key, the newest version that was expired in its first pass, and deletes only versions up to it, oldest first. Versions written since are newer and stay. A sweep that fails partway never exposes a superseded version.
This also corrects the "Blob lifetimes" section of
docs/specs/storage-bus.md:sweep_expired_blobs/sweep_expired_blobs_generation, which don't exist.Closes #38
API or behavior changes
No API change. Behaviour: the MongoDB sweep no longer deletes versions written during the sweep.
Validation
On a Linux build host, merged onto main 05acdd9 (and merging cleanly onto v2.1.3, f5a3302):
cargo test --locked -p tinystoragedrivers-blob --features mongodbagainst a live replica set and a live standalone mongod: all pass, no skipped live tests, on both. That includes the three sweep tests.mongodb.rsand the new test, the new test fails on both servers (left: 4, right: 3, because the old sweep also deletes the newer version).cargo test --workspace --all-features --locked: 857 passed, 0 failed, 1 ignored (on v2.1.3 main).-D warnings(0 items),cargo fmt --check, rustdoc-D warnings.Tests
mongodb_sweep_keeps_a_blob_rewritten_between_its_passes(live MongoDB): The sweep pauses after its first pass, the key is written again, and the sweep resumes. The fresh blob survives.called Option::unwrap() on a None value). That fails on both a replica set and a standalone.mongodb_sweep_reclaims_only_up_to_the_newest_expired_version(live MongoDB). It plants versions directly in GridFS, the state a failed cleanup or a racing writer leaves, and checks two things: