minor: documentation and test updates for RUBY-378

This commit is contained in:
Tyler Brock 2012-02-16 14:20:31 -05:00
parent b79d408a11
commit 79105f6c98
4 changed files with 10 additions and 10 deletions

View File

@ -17,7 +17,7 @@ The Ruby driver allows you to set read preference on each of four levels: the co
Objects will inherit the default read preference from their parents. Thus, if you set a read preference of `{:read => :secondary}` when creating
a new connection, then all databases and collections created from that connection will inherit the same setting. See this code example:
@con = Mongo::ReplSetConnection.new([['localhost', 27017], ['localhost', 27018]], :read => :secondary)
@con = Mongo::ReplSetConnection.new(['localhost:27017','localhost:27018'], :read => :secondary)
@db = @con['test']
@collection = @db['foo']
@collection.find({:name => 'foo'})

View File

@ -11,13 +11,13 @@ takes a list of seed nodes followed by any connection options. You'll want to sp
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])
@connection = ReplSetConnection.new(['n1.mydb.net:27017', 'n2.mydb.net:27017', 'n3.mydb.net:27017'])
### Read slaves
If you want to read from a secondary node, you can pass :read => :secondary to ReplSetConnection#new.
@connection = ReplSetConnection.new(['n1.mydb.net', 27017], ['n2.mydb.net', 27017], ['n3.mydb.net', 27017],
@connection = ReplSetConnection.new(['n1.mydb.net:27017', 'n2.mydb.net:27017', 'n3.mydb.net:27017'],
:read => :secondary)
A random secondary will be chosen to be read from. In a typical multi-process Ruby application, you'll have a good distribution of reads across secondary nodes.
@ -48,18 +48,18 @@ having to manually restart your app server, then you should enable it. You can e
synchronously, which will refresh the replica set data in a synchronous fashion (which may
ocassionally slow down your queries):
@connection = ReplSetConnection.new(['n1.mydb.net', 27017], :refresh_mode => :sync)
@connection = ReplSetConnection.new(['n1.mydb.net:27017'], :refresh_mode => :sync)
If you want to change the default refresh interval of 90 seconds, you can do so like this:
@connection = ReplSetConnection.new(['n1.mydb.net', 27017], :refresh_mode => :sync,
@connection = ReplSetConnection.new(['n1.mydb.net:27017'], :refresh_mode => :sync,
:refresh_interval => 60)
Do not set this value to anything lower than 30, or you may start to experience performance issues.
You can also disable refresh mode altogether:
@connection = ReplSetConnection.new(['n1.mydb.net', 27017], :refresh_mode => false)
@connection = ReplSetConnection.new(['n1.mydb.net:27017'], :refresh_mode => false)
And you can call `refresh` manually on any replica set connection:

View File

@ -67,13 +67,13 @@ module Mongo
# @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])
# 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':
# ReplSetConnection.new(['localhost', 30000], ['localhost', 30001], :name => 'prod')
# ReplSetConnection.new(['localhost:30000', 'localhost:30001'], :name => 'prod')
#
# @example Connect to a replica set providing two seed nodes and allowing reads from a secondary node:
# ReplSetConnection.new(['localhost', 30000], ['localhost', 30001], :read => :secondary)
# ReplSetConnection.new(['localhost:30000', 'localhost:30001'], :read => :secondary)
#
# @see http://api.mongodb.org/ruby/current/file.REPLICA_SETS.html Replica sets in Ruby
#

View File

@ -13,7 +13,7 @@ class ReadTest < Test::Unit::TestCase
context "Read mode on replica set connection: " do
setup do
@read_preference = :secondary
@con = Mongo::ReplSetConnection.new(['localhost', 27017], :read => @read_preference, :connect => false)
@con = Mongo::ReplSetConnection.new(['localhost:27017'], :read => @read_preference, :connect => false)
end
should "store read preference on Connection" do