Skip to content

feat(mongodb-reactive): add audit compaction capability - #977

Merged
davidfrigolet merged 4 commits into
masterfrom
feat/audit-compaction-mongodb-reactive
Oct 14, 2026
Merged

davidfrigolet merged 4 commits into
masterfrom
feat/audit-compaction-mongodb-reactive

Conversation

@davidfrigolet

Copy link
Copy Markdown
Contributor

Summary

  • Implements AuditCompactor for the MongoDB reactive audit store, mirroring the MongoDB sync implementation (fix(mongodb-sync): audit compaction capability #967).
  • No rekey needed: current-state and ledger forms share the same auto _id, filtered by changeId, so compaction only deletes superseded documents.
  • Survivor is addressed by its stored _id, not by attribute matching.
  • Bridges the reactive driver's Publisher-based find()/deleteMany() to the synchronous compact() contract via the existing PublisherSync idiom.

Test plan

  • Unit tests against a mocked reactive MongoCollection
  • MongoDBReactiveAuditCompactionConformanceTest against a real MongoDB container, plus a store-specific assertion that the survivor keeps its original _id
  • All compaction test classes (SQL, Couchbase, DynamoDB, MongoDB sync, MongoDB reactive) run green in isolation
  • Smoke-tested against the published artifact (publishToMavenLocal) in a standalone lab project running a real Flamingock pipeline end to end

davidfrigolet and others added 3 commits October 12, 2026 16:00
- 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 dieppa left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() == 1 early 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.
  • PublisherSync on every driver call, matching MongoDBReactiveAuditRepository.
  • 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.

@davidfrigolet
davidfrigolet merged commit b653cd5 into master Oct 14, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants