From 6a46bf7aef703fdf689635f64573fb4580767aed Mon Sep 17 00:00:00 2001 From: Kyle Banker Date: Sat, 12 Mar 2011 08:40:29 -0500 Subject: [PATCH] RUBY-247 Improved replica set docs. --- docs/REPLICA_SETS.md | 7 ++++--- lib/mongo/repl_set_connection.rb | 8 +++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/docs/REPLICA_SETS.md b/docs/REPLICA_SETS.md index dd5df9b..4818edd 100644 --- a/docs/REPLICA_SETS.md +++ b/docs/REPLICA_SETS.md @@ -6,12 +6,13 @@ Here follow a few considerations for those using the MongoDB Ruby driver with [r First, make sure that you've configured and initialized a replica set. -Use `ReplSetConnection.new` to connect to a replica set: +Use `ReplSetConnection.new` to connect to a replica set. This method, which accepts a variable number of arugments, +takes a list of seed nodes followed by any connection options. You'll want to specify at least two seed nodes. This gives +the driver more chances to connect in the event that any one seed node is offline. Once the driver connects, it will +cache the replica set topology as reported by the given seed node and use that information if a failover is later required. @connection = ReplSetConnection.new(['n1.mydb.net', 27017], ['n2.mydb.net', 27017], ['n3.mydb.net', 27017]) -The driver will attempt to connect to a master node and, when found, will replace all seed nodes with known members of the replica set. - ### Read slaves If you want to read from a seconday node, you can pass :read_secondary => true to ReplSetConnection#new. diff --git a/lib/mongo/repl_set_connection.rb b/lib/mongo/repl_set_connection.rb index 4b54037..fe1a40d 100644 --- a/lib/mongo/repl_set_connection.rb +++ b/lib/mongo/repl_set_connection.rb @@ -29,8 +29,8 @@ module Mongo # Connection#arbiters. This is useful if your application needs to connect manually to nodes other # than the primary. # - # @param [Array] args A list of host-port pairs ending with a hash containing any options. See - # the examples below for exactly how to use the constructor. + # @param [Array] args A list of host-port pairs to be used as seed nodes followed by a + # hash containing any options. See the examples below for exactly how to use the constructor. # # @option options [String] :rs_name (nil) The name of the replica set to connect to. You # can use this option to verify that you're connecting to the right replica set. @@ -47,7 +47,9 @@ module Mongo # this is the number of seconds to wait for a new connection to be released before throwing an exception. # Note: this setting is relevant only for multi-threaded applications. # - # @example Connect to a replica set and provide two seed nodes: + # @example Connect to a replica set and provide two seed nodes. Note that the number of seed nodes does + # not have to be equal to the number of replica set members. The purpose of seed nodes is to permit + # the driver to find at least one replica set member even if a member is down. # ReplSetConnection.new(['localhost', 30000], ['localhost', 30001]) # # @example Connect to a replica set providing two seed nodes and ensuring a connection to the replica set named 'prod':