Repository navigation
feat(mongodb-reactive): add audit compaction capability - #977
Conversation
- Implements AuditCompactor for the MongoDB reactive audit store, mirroring the MongoDB sync implementation (#967): no rekey needed since the current and ledger forms share the same auto _id, filtered by changeId, so compaction only deletes superseded documents. - Survivor is addressed by its stored _id (never by attribute matching), avoiding the bug class that bit the original sync attempt - a document's physical identity is tracked alongside its mapped AuditEntry via an IdentityHashMap, since AuditEntry declares no equals(). - Bridges the reactive driver's Publisher-based find()/deleteMany() to the synchronous AuditCompactor#compact() contract via the existing PublisherSync idiom already used throughout this module. - Adds unit tests against a mocked reactive MongoCollection (Publisher driven via a small hand-rolled Subscriber) and the shared AuditCompactionConformance suite wired against a real MongoDB container, plus store-specific assertions that the surviving document keeps its original _id.
dieppa
left a comment
There was a problem hiding this comment.
Ran the tests and mutation-tested the filter. LGTM — a faithful mirror of the sync implementation, with the reactive plumbing done the way the rest of the module does it.
What's right:
- Survivor identified by
_id, not by attribute matching — the lesson from #967 carried over rather than re-derived. entries.size() == 1early return is correct here. Unlike Couchbase, MongoDB doesn't rekey, so a single document genuinely needs no work. Good that the Couchbase shape wasn't copied.- Nothing is written, so clause 5 holds trivially and the survivor keeps its
_id— with a test asserting it. PublisherSyncon every driver call, matchingMongoDBReactiveAuditRepository.- The javadoc points at the sync version instead of duplicating the reasoning. Right call.
24 tests pass (9 unit + 15 conformance). I inverted the _id exclusion and dropped the changeId scope — both caught.
Two non-blocking comments inline.
One thing worth knowing but not this PR's problem: PublisherSync.await has no timeout, so a publisher that never completes blocks forever. That's pre-existing and applies to every reactive read/write in the module — but compaction runs inside the stage lock, so a hang would hold the lock.
For the record, a gap inherited from the sync PR: no test covers two documents with the same winning state across different executions (exec-1/APPLIED + exec-2/APPLIED). With _id-based identification that's structurally safe, so not a bug — and the shared seed can't express it today. If it ever gains that scenario, both Mongo stores benefit.
Summary
AuditCompactorfor the MongoDB reactive audit store, mirroring the MongoDB sync implementation (fix(mongodb-sync): audit compaction capability #967)._id, filtered bychangeId, so compaction only deletes superseded documents._id, not by attribute matching.Publisher-basedfind()/deleteMany()to the synchronouscompact()contract via the existingPublisherSyncidiom.Test plan
MongoCollectionMongoDBReactiveAuditCompactionConformanceTestagainst a real MongoDB container, plus a store-specific assertion that the survivor keeps its original_idpublishToMavenLocal) in a standalone lab project running a real Flamingock pipeline end to end