Skip to content

MongoDB: Add replica set support with automatic failover#5068

Merged
matejk merged 46 commits intomainfrom
mongodb-replica-set-support
Dec 16, 2025
Merged

MongoDB: Add replica set support with automatic failover#5068
matejk merged 46 commits intomainfrom
mongodb-replica-set-support

Conversation

@matejk
Copy link
Copy Markdown
Contributor

@matejk matejk commented Nov 27, 2025

Summary

This PR adds comprehensive MongoDB replica set support to the Poco MongoDB library, implementing automatic server discovery, topology monitoring, failover handling, and read preference-based server selection.

New Features

Replica Set Connection Management

  • ReplicaSetConnection: Wrapper around Connection that provides automatic retry and failover for replica set operations.
  • ReplicaSetPoolableConnectionFactory: Connection pooling support for replica sets.

Topology Discovery and Monitoring

  • TopologyDescription: Tracks the state of all servers in a replica set.
  • ServerDescription: Represents the state of individual MongoDB servers.
  • TopologyChangeNotification: Notification mechanism for topology changes.

Read Preference Support

  • ReadPreference: Configures read preference mode (Primary, PrimaryPreferred, Secondary, SecondaryPreferred, Nearest).
  • Support for tag sets and max staleness constraints.

MongoDB URI Parsing

  • ReplicaSetURI: Parses and generates MongoDB connection strings.

OpMsgCursor Enhancement

  • Added support for ReplicaSetConnection in OpMsgCursor.

Known Limitations

  • No RTT-based server selection: The Nearest read preference selects any available member but does not use RTT for latency-based selection.
  • See README-ReplicaSet.md for full list of SDAM specification gaps.

Improvements

  • Use C++ standard library mutex primitives instead of Poco equivalents
  • Support for IPv6 addresses in replica set configurations
  • Removed support for pre-5.1 MongoDB (legacy wire protocol)
  • Prevent duplicate entries in MongoDB::Document
  • SSL socket factory support for secure connections

Fixes

  • Fixed parsing of MongoDB replica set URIs
  • Changed heartbeatFrequency to heartbeatFrequencyMS to match MongoDB specification
  • Prevent servers from different replica sets being used in the same topology

Documentation and Samples

  • Added comprehensive README-ReplicaSet.md documentation
  • New samples: ReplicaSet.cpp, ReplicaSetMonitor.cpp, URIExample.cpp

Tests

  • New BSONTest suite with comprehensive BSON serialization tests
  • New ReplicaSetTest suite covering URI parsing, topology discovery, server selection, and failover scenarios

CI/Build

  • Speed up CI builds with cmake --build --parallel 4
  • Upgrade CodeQL from v3 to v4
  • Fix C++ modules build

@matejk matejk self-assigned this Nov 27, 2025
@matejk matejk added the feature label Nov 27, 2025
@matejk matejk changed the title Mongodb replica set support MongoDB replica set support Nov 27, 2025
@matejk matejk force-pushed the mongodb-replica-set-support branch from b572b42 to 7673ae9 Compare December 4, 2025 13:38
@matejk matejk added this to the Release 1.15.0 milestone Dec 5, 2025
@aleks-f
Copy link
Copy Markdown
Member

aleks-f commented Dec 6, 2025

@matejk you have fix for failing odbc CI in main

@matejk matejk force-pushed the mongodb-replica-set-support branch from cd8bbb1 to bd123a2 Compare December 8, 2025 15:55
@matejk matejk force-pushed the mongodb-replica-set-support branch from 3ecb2ea to fda7d81 Compare December 9, 2025 06:14
@matejk matejk added breaking A breaking change performance labels Dec 10, 2025
@matejk matejk marked this pull request as ready for review December 10, 2025 12:29
@matejk matejk requested a review from aleks-f December 10, 2025 14:43
@matejk matejk force-pushed the mongodb-replica-set-support branch from baf85a2 to 50466f4 Compare December 11, 2025 23:31
enh(MongoDB): Remove dead code and mark Message as implementation detail.

enh(CI): Fix build of C++ modules
@matejk matejk force-pushed the mongodb-replica-set-support branch from 875ffcd to 1b83973 Compare December 12, 2025 10:00
@matejk matejk merged commit 51f3749 into main Dec 16, 2025
75 checks passed
@matejk matejk deleted the mongodb-replica-set-support branch December 16, 2025 06:49
@matejk matejk changed the title MongoDB replica set support MongoDB: Add replica set support with automatic failover Dec 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants