Skip to content

Add opt-in safe checkpoint polling for MongoDB (#118) - #121

Open
AGiorgetti wants to merge 14 commits into
developfrom
fix/118-safe-checkpoint-polling
Open

AGiorgetti wants to merge 14 commits into
developfrom
fix/118-safe-checkpoint-polling

Conversation

@AGiorgetti

@AGiorgetti AGiorgetti commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

Part of #118 and NEventStore/NEventStore#425. Draft dependency: the dependencies/NEventStore gitlink points temporarily to d06da7c from core PR #555. Before merging this PR, pin the merged core revision and rerun CI. Before publishing, set the adapter’s NuGet minimum to the released core version containing ISafeCheckpointPolling and verify a clean package-only consumer. No package is published here.

Behavior

  • Both polling paths capture the global tip and read active commits in (after, tip]. No new write operations, transactions, locks, stored fields, or changes to legacy reads.

  • Safe polling is opt-in on standalone MongoDB and replica sets with an unsharded Commits collection. Every writer must use the built-in generator, and cleanup must retain the Prevent EmptyRecycleBin from allowing checkpoint ID reuse #117 markers. Replica-set polling requires normal discovery, primary majority reads, and journaled majority writes. Set EnableSafeCheckpointPolling = true on either topology. The engine discovers the topology during index initialization and fills only the missing replica-set defaults before constructing the allocator. Explicit settings and virtual overrides are preserved; incompatible settings disable safe polling rather than falling back. The engine now caches eligibility after successful initialization; replica-set elections do not invalidate it, while a deployment-type or settings change requires a new engine. A single causally consistent session binds the replica-set tip to the read cursor. Sharded Commits stays on standby in Shard commits collection? #57; sharded topologies and recycle-bin reads remain unqualified. Standalone reads still do not wait for journal durability.

  • The regression pauses a writer after allocation and before insert. The incrementing generator reproduces the legacy miss (2 before 1); the built-in generator competes for the same ID and retries beyond the saved checkpoint. Tests cover sync and async, all-bucket and bucket-scoped reads, fresh-reader resume, and advancement past retired IDs. See the configuration notes.

  • When explicitly enabled but unsupported, the adapter logs the first incompatible setting once at initialization. Direct safe reads include the same reason in NotSupportedException.

  • The replica-set CI jobs and local developers use the same Docker Compose fixture.

Verification

  • Latest diagnostics revision: 13 focused tests passed per topology, including exact rejection reasons; the .NET Framework 4.7.2 build also passed. Compose config validated; all 17 focused tests passed using the same bootstrap and health check outside Docker.
  • Before the Docker and diagnostics follow-ups: 2,122 passed on a three-member MongoDB 7.0.45 replica set and 2,118 passed on standalone (.NET 10 / Driver 3.14.0; zero skipped), including actual elections and rollback/reuse. The new guard regression observed no commit collection inspections after initialization. The .NET Framework 4.7.2 provider and tests compiled.
  • Replica-set qualification: .NET 10 / Driver 3.14.0 on three MongoDB 7.0.45 members, 2,118 passed, zero skipped. This includes sync and async resume after forced elections plus verified rollback/reuse cases. The new GitHub Actions replica-set jobs run the full suite with both supported driver pins.
  • .NET Framework 4.7.2 provider and tests compiled; the runtime suite was not run on .NET Framework.
  • Standalone MongoDB 7.0.45, .NET 10, Driver 3.14.0: 2,114 passed, zero skipped.
  • Six initial regressions were red before the capability was implemented. The raw read assertions reached the expected checkpoint miss before the capability check failed.

Co-authored by Alessandro Giorgetti and Codex (OpenAI).

AGiorgetti and others added 4 commits December 2, 2026 13:00
Co-authored-by: Codex <codex@openai.com>
Co-authored-by: Codex <codex@openai.com>
Co-authored-by: Codex <codex@openai.com>
Co-authored-by: Codex <codex@openai.com>
@AGiorgetti AGiorgetti changed the title Add opt-in safe checkpoint polling for standalone MongoDB (#118) Add opt-in safe checkpoint polling for MongoDB (#118) Dec 2, 2026
AGiorgetti and others added 5 commits December 2, 2026 17:21
Co-authored-by: Codex <codex@openai.com>
Co-authored-by: Codex <codex@openai.com>
Co-authored-by: Codex <codex@openai.com>
@AGiorgetti
AGiorgetti marked this pull request as ready for review December 2, 2026 17:37
@AGiorgetti
AGiorgetti requested a balanced review from Copilot December 2, 2026 17:37

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Safe polling accepts a generator bound to another collection, risking permanently missed commits, and new CI action references remain vulnerable to mutable version tags.

4 open issues
What changed in this PR

Adds opt-in safe checkpoint polling to the MongoDB adapter, addressing late-visible commits in #118 while preserving legacy polling defaults.

Changes:

  • Adds bounded sync and async polling with topology-specific safety checks and diagnostics.
  • Adds delayed-write, checkpoint-gap, election, and rollback regressions.
  • Adds replica-set CI coverage, a shared Docker fixture, and configuration documentation.
File Description
src/​NEventStore.Persistence.MongoDB/​MongoPersistenceOptions.cs Adds polling opt-in and commit concern overrides.
src/​NEventStore.Persistence.MongoDB/​MongoPersistenceEngine.Logging.cs Adds unsupported-configuration warnings.
src/​NEventStore.Persistence.MongoDB/​MongoPersistenceEngine.cs Implements eligibility checks and bounded synchronous polling.
src/​NEventStore.Persistence.MongoDB/​MongoPersistenceEngine.Async.cs Implements equivalent asynchronous polling.
src/​NEventStore.Persistence.MongoDB.Tests/​AcceptanceTests/​MongoPersistenceOptionsTests.cs Tests mismatched connection seeds.
src/​NEventStore.Persistence.MongoDB.Tests/​AcceptanceTests/​Issues/​Issue118SafePolling.cs Tests polling safety, configuration, and checkpoint gaps.
src/​NEventStore.Persistence.MongoDB.Tests/​AcceptanceTests/​Issues/​Issue118ReplicaSetFailover.cs Tests resume behavior across elections and rollback.
README.md Links replica-set testing instructions.
docs/​Safe-Checkpoint-Polling.md Documents configuration, guarantees, and limitations.
docker/​Readme.md Documents local replica-set testing.
docker/​docker-compose.replica-set.yml Provides an isolated three-member test cluster.
Changelog.md Records the new polling capability.
.github/​workflows/​ci.yml Adds replica-set driver lanes and verifies failover execution.

Review effort: Balanced

Comment thread .github/workflows/ci.yml Resolved
Comment thread .github/workflows/ci.yml Resolved
Comment thread .github/workflows/ci.yml Resolved
A caller-supplied generator of the built-in type can read a different collection or use different concerns. Keep it available for legacy operations, but never advertise safe polling with it.

Co-authored-by: Codex <codex@openai.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unacknowledged commit writes can report rejected inserts as successful, while mutable CI action tags expose the workflow to unreviewed code changes.

1 open issue
1 previously missed issue

In code that hasn't changed since last review

Medium severity Test write-concern rejection through both polling paths

src/​NEventStore.Persistence.MongoDB/​MongoPersistenceEngine.cs:461

The new tests do not exercise this write-concern rejection: the explicit-settings case fails earlier on read preference, and the virtual-override case fails on read concern. Add replica-set cases with primary/majority reads and either unjournaled majority writes or journaled w:1 writes. Assert false capability and rejection through both polling paths so these rollback-safety guards cannot regress unnoticed.

4 resolved since last review

Review effort: Balanced

Validate the effective insert write concern before creating any collection handles, even if safe polling is disabled. Optimistic concurrency and checkpoint retries require the server's duplicate-key response. Keep the existing virtual extension point and acknowledged defaults.

Co-authored-by: Codex <codex@openai.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The new checkout, setup-dotnet, and upload-artifact actions use mutable tags rather than immutable commit SHAs, allowing CI code to change without review.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

AGiorgetti and others added 3 commits December 3, 2026 10:06
Assert the configuration exception without requiring the driver to echo the URI. Select rollback participants from the live replica set, so seed aliases cannot misidentify the primary.

Co-authored-by: Codex <codex@openai.com>
The preceding failover case can leave a former primary recovering. Wait for one primary and two secondaries before pausing replication.

Co-authored-by: Codex <codex@openai.com>
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