enh(MongoDB): ReplicaSet remove redundant function, update documentation.

This commit is contained in:
Matej Kenda
2025-12-04 11:55:20 +01:00
parent c4f0eb14c1
commit ec29da1815
5 changed files with 16 additions and 37 deletions

View File

@@ -28,9 +28,13 @@ namespace MongoDB {
class ReplicaSetConnection;
class MongoDB_API OpMsgCursor: public Document
/// OpMsgCursor is an helper class for querying multiple documents using OpMsgMessage.
/// OpMsgCursor is a helper class for querying multiple documents using OpMsgMessage.
/// Once all of the data is read with the cursor (see isActive()) it can't be reused.
///
/// USAGE:
/// Supports both Connection and ReplicaSetConnection. When using ReplicaSetConnection,
/// cursor operations benefit from automatic retry and failover on retriable errors.
///
/// RESOURCE MANAGEMENT:
/// When a cursor is no longer needed, you should call kill() to release server-side
/// resources. If kill() is not called explicitly, the server will keep the cursor
@@ -82,10 +86,12 @@ public:
/// Returns the associated query.
void kill(Connection& connection);
/// Kills the cursor and reset it so that it can be reused.
/// Kills the cursor and resets its internal state.
/// Call this method when you don't need all documents to release server resources.
void kill(ReplicaSetConnection& connection);
/// Kills the cursor and reset it so that it can be reused.
/// Kills the cursor and resets its internal state.
/// Call this method when you don't need all documents to release server resources.
///
/// This overload provides automatic retry and failover for replica set deployments.

View File

@@ -186,9 +186,6 @@ public:
/// Returns true if a primary server is known.
private:
void discover();
/// Performs initial topology discovery from seed servers.
void monitor() noexcept;
/// Background monitoring thread function.

View File

@@ -122,7 +122,10 @@ private:
/// Marks the current server as failed in the topology.
void logInfo(const std::string& message);
/// Logs an informational message using the replica set's logger if configured.
void logDebug(const std::string& message);
/// Logs a debug message using the replica set's logger if configured.
ReplicaSet& _replicaSet;
ReadPreference _readPreference;

View File

@@ -34,7 +34,7 @@ class MongoDB_API ServerDescription
/// Represents the state of a single MongoDB server in a replica set.
///
/// This class stores metadata about a MongoDB server obtained from
/// the 'hello' or legacy 'isMaster' command response, including:
/// the 'hello' command response (requires MongoDB 5.1 or later), including:
/// - Server type (primary, secondary, arbiter, etc.)
/// - Replica set membership information
/// - Round-trip time for server selection

View File

@@ -48,7 +48,7 @@ ReplicaSet::ReplicaSet(const Config& config):
}
// Perform initial discovery
discover();
updateTopologyFromAllServers();
// Start monitoring if enabled
if (_config.enableMonitoring)
@@ -75,7 +75,7 @@ ReplicaSet::ReplicaSet(const std::vector<Net::SocketAddress>& seeds):
}
// Perform initial discovery
discover();
updateTopologyFromAllServers();
// Start monitoring if enabled
if (_config.enableMonitoring)
@@ -105,7 +105,7 @@ ReplicaSet::ReplicaSet(const std::string& uri)
}
// Perform initial discovery
discover();
updateTopologyFromAllServers();
// Start monitoring if enabled
if (_config.enableMonitoring)
@@ -224,33 +224,6 @@ bool ReplicaSet::hasPrimary() const
}
void ReplicaSet::discover()
{
// Try to discover topology from seed servers
bool discovered = false;
const auto servers = _topology.servers();
for (const auto& server : servers)
{
try
{
updateTopologyFromHello(server.address());
discovered = true;
break; // Successfully discovered from at least one server
}
catch (...)
{
// Continue to next server
}
}
if (!discovered)
{
throw Poco::IOException("Failed to discover replica set topology from any seed server");
}
}
void ReplicaSet::monitor() noexcept
{
while (!_stopMonitoring.load())