The MongoDB replica health check measures lag correctly on an idle replica set #313

Merged
claude merged 3 commits from feature/61-mongo-idle-replica-lag into develop 2026-11-05 14:09:24 -05:00
Owner

The MongoDB replica health check no longer refuses a healthy secondary of an idle replica set, and never reports a lagging secondary below its lag.

Measured on the pinned mongo:8 image: an idle set writes a no-op about every 20 s; a secondary's lastAppliedWallTime (ms) matches the primary's at once, while its optime/optimeDate in replSetGetStatus trail by up to one heartbeat (~2 s), which produced a false "17 s behind" (red test on develop: Check 3 found the idle replica not eligible: The replica is 17 s behind, more than the limit of 5 s.).

Rule (MongoReplicaLag, stateless, called by MongoReplicaHealthProbe):

  • Current (lag 0): the secondary's full optime {ts, t} or its lastAppliedWallTime equals the primary's, however old that operation is.
  • Behind: the status date (the primary's clock) minus the secondary's last applied wall time (optimeDate as fallback). This is an upper bound of how long it may have been missing data, on every check, including the first after a start. The gap between the two members' last operations is not a bound (a write followed by an idle pause leaves a millisecond gap while the secondary misses data), so it is not used.
  • Cost: a secondary a few ms late right after an idle no-op reads behind for that one check.
  • Unchanged: worst healthy secondary decides; 5 s limit; no primary / no healthy secondary is unknown.

Tests: MongoDbReplicaHealthTests.Monitor_OnAnIdleReplicaSet_KeepsTheReplicaEligible (Docker; 15 s idle then 30 s of checks; red on develop); the paused-replication test still falls back to the primary; MongoReplicaLagTests (9 unit tests on crafted status documents, including a secondary far behind at its first check and a missed write before an idle pause). MongoDbReplicaRoutingTests 10/10 runs on the first version and 3/3 after the final rule change; Integration Mongo filter, Data.Tests 133 pass; build 0 warnings; csharpier clean. README read-replica bullet updated.

Closes #61

🤖 Generated with Claude Code

https://claude.ai/code/session_01T33E3pmQvqkTriyQUMNUTK

The MongoDB replica health check no longer refuses a healthy secondary of an idle replica set, and never reports a lagging secondary below its lag. Measured on the pinned `mongo:8` image: an idle set writes a no-op about every 20 s; a secondary's `lastAppliedWallTime` (ms) matches the primary's at once, while its `optime`/`optimeDate` in `replSetGetStatus` trail by up to one heartbeat (~2 s), which produced a false "17 s behind" (red test on develop: `Check 3 found the idle replica not eligible: The replica is 17 s behind, more than the limit of 5 s.`). Rule (`MongoReplicaLag`, stateless, called by `MongoReplicaHealthProbe`): - Current (lag 0): the secondary's full optime {ts, t} or its `lastAppliedWallTime` equals the primary's, however old that operation is. - Behind: the status `date` (the primary's clock) minus the secondary's last applied wall time (`optimeDate` as fallback). This is an upper bound of how long it may have been missing data, on every check, including the first after a start. The gap between the two members' last operations is not a bound (a write followed by an idle pause leaves a millisecond gap while the secondary misses data), so it is not used. - Cost: a secondary a few ms late right after an idle no-op reads behind for that one check. - Unchanged: worst healthy secondary decides; 5 s limit; no primary / no healthy secondary is unknown. Tests: `MongoDbReplicaHealthTests.Monitor_OnAnIdleReplicaSet_KeepsTheReplicaEligible` (Docker; 15 s idle then 30 s of checks; red on develop); the paused-replication test still falls back to the primary; `MongoReplicaLagTests` (9 unit tests on crafted status documents, including a secondary far behind at its first check and a missed write before an idle pause). `MongoDbReplicaRoutingTests` 10/10 runs on the first version and 3/3 after the final rule change; Integration Mongo filter, Data.Tests 133 pass; build 0 warnings; csharpier clean. README read-replica bullet updated. Closes #61 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01T33E3pmQvqkTriyQUMNUTK
The lag is the time since the secondary was last current, not the difference of two optime dates, so a quiet replica set is no longer refused.

Refs #61

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01T33E3pmQvqkTriyQUMNUTK
Refs #61

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01T33E3pmQvqkTriyQUMNUTK
The MongoDB replica health check charges a lagging secondary the time since its own last operation, so a missed write before an idle pause still counts
Some checks failed
Build / Pack and Push NuGet Packages (dhcp) (pull_request) Successful in 1m45s
Build / Pack and Push NuGet Packages (dns-core) (pull_request) Successful in 1m55s
Build / Build Binary (linux-arm64) (pull_request) Successful in -9s
Build / Build Binary (linux-amd64) (pull_request) Successful in -9s
Build / Build Binary (macos-amd64) (pull_request) Successful in -9s
Build / Build Binary (windows-amd64) (pull_request) Successful in 3m25s
Build / Build Binary (macos-arm64) (pull_request) Successful in 15m29s
Build / Smoke Test the Windows Binary (pull_request) Successful in 21s
Build / Build and Push Image (pull_request) Successful in 39s
Build / Build Arch Linux Packages (pull_request) Successful in -1m25s
Build / Build and Test Deb and RPM Packages (pull_request) Successful in 1m19s
Build / Publish Release (pull_request) Successful in -2m39s
Build / Pipeline (pull_request) Successful in 0s
Build / Test .NET (push) Failing after 33m56s
Build / Stage Draft Release (push) Has been skipped
Build / Pack and Push NuGet Packages (dns-core) (push) Has been skipped
Build / Pack and Push NuGet Packages (dhcp) (push) Has been skipped
Build / Pack and Push NuGet Packages (common) (push) Has been skipped
Build / Build Binary (linux-arm64) (push) Has been skipped
Build / Pack and Push NuGet Packages (dns-server) (push) Has been skipped
Build / Build Binary (macos-arm64) (push) Has been skipped
Build / Build Binary (linux-amd64) (push) Has been skipped
Build / Build Binary (macos-amd64) (push) Has been skipped
Build / Build Binary (windows-amd64) (push) Has been skipped
Build / Build Arch Linux Packages (push) Has been skipped
Build / Build and Test Deb and RPM Packages (push) Has been skipped
Build / Build and Push Image (push) Has been skipped
Build / Smoke Test the Windows Binary (push) Has been skipped
Build / Publish Release (push) Has been skipped
Build / Pipeline (push) Failing after 0s
bd5a2990d8
Refs #61

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01T33E3pmQvqkTriyQUMNUTK
claude merged commit c8c4a2c32d into develop 2026-11-05 14:09:24 -05:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
lantea-one/ninlil!313
No description provided.