must use Connection.paired for paired connections

This commit is contained in:
Kyle Banker 2010-04-07 17:10:28 -04:00
parent e18d2d6fbb
commit 910a82de7e
5 changed files with 11 additions and 48 deletions

View File

@ -13,6 +13,7 @@
* Removed the following deprecated items:
* GridStore class
* RegexpOfHolding class
* Paired connections must now be initialized with Connection.paired
* BSON-related code extracted into two separate gems: bson and bson_ext (thx to Chuck Remes).
* mongo_ext no longer exists.

View File

@ -886,7 +886,6 @@ void Init_cbson() {
rb_require("bson/types/min_max_keys");
MinKey = rb_const_get(bson, rb_intern("MinKey"));
MaxKey = rb_const_get(bson, rb_intern("MaxKey"));
rb_require("bson/types/regexp_of_holding");
Regexp = rb_const_get(rb_cObject, rb_intern("Regexp"));
rb_require("bson/exceptions");
InvalidKeyName = rb_const_get(bson, rb_intern("InvalidKeyName"));

View File

@ -44,27 +44,21 @@ module Mongo
# If connecting to just one server, you may specify whether connection to slave is permitted.
# In all cases, the default host is "localhost" and the default port is 27017.
#
# When specifying a pair, +pair_or_host+, is a hash with two keys: :left and :right. Each key maps to either
# * a server name, in which case port is 27017,
# * a port number, in which case the server is "localhost", or
# * an array containing [server_name, port_number]
# To specify a pair, use Connection.paired.
#
# Note that there are a few issues when using connection pooling with Ruby 1.9 on Windows. These
# should be resolved in the next release.
#
# @param [String, Hash] pair_or_host See explanation above.
# @param [Integer] port specify a port number here if only one host is being specified. Leave nil if
# specifying a pair of servers in +pair_or_host+.
# @param [String, Hash] host.
# @param [Integer] port specify a port number here if only one host is being specified.
#
# @option options [Boolean] :slave_ok (false) Must be set to +true+ when connecting
# to a single, slave node.
# @option options [Logger, #debug] :logger (nil) Logger instance to receive driver operation log.
# @option options [Boolean] :auto_reconnect DEPRECATED. See http://www.mongodb.org/display/DOCS/Replica+Pairs+in+Ruby
# @option options [Integer] :pool_size (1) The maximum number of socket connections that can be opened to the database.
# @option options [Float] :timeout (5.0) When all of the connections to the pool are checked out,
# this is the number of seconds to wait for a new connection to be released before throwing an exception.
#
#
# @example localhost, 27017
# Connection.new
#
@ -77,25 +71,16 @@ module Mongo
# @example localhost, 3000, where this node may be a slave
# Connection.new("localhost", 3000, :slave_ok => true)
#
# @example DEPRECATED. To initialize a paired connection, use Connection.paired instead.
# Connection.new({:left => ["db1.example.com", 27017],
# :right => ["db2.example.com", 27017]})
#
# @example DEPRECATED. To initialize a paired connection, use Connection.paired instead.
# Connection.new({:left => ["db1.example.com", 27017],
# :right => ["db2.example.com", 27017]}, nil,
# :pool_size => 20, :timeout => 5)
#
# @see http://www.mongodb.org/display/DOCS/Replica+Pairs+in+Ruby Replica pairs in Ruby
#
# @core connections
def initialize(pair_or_host=nil, port=nil, options={})
def initialize(host=nil, port=nil, options={})
@auths = []
if block_given?
@nodes = yield self
else
@nodes = format_pair(pair_or_host, port)
@nodes = format_pair(host, port)
end
# Host and port of current master.
@ -118,10 +103,6 @@ module Mongo
@sockets = []
@checked_out = []
if options[:auto_reconnect]
warn(":auto_reconnect is deprecated. see http://www.mongodb.org/display/DOCS/Replica+Pairs+in+Ruby")
end
# slave_ok can be true only if one node is specified
@slave_ok = options[:slave_ok] && @nodes.length == 1
@logger = options[:logger] || nil
@ -479,12 +460,6 @@ module Mongo
case pair_or_host
when String
[[pair_or_host, port ? port.to_i : DEFAULT_PORT]]
when Hash
warn "Initializing a paired connection with Connection.new is deprecated. Use Connection.pair instead."
connections = []
connections << pair_val_to_connection(pair_or_host[:left])
connections << pair_val_to_connection(pair_or_host[:right])
connections
when nil
[['localhost', DEFAULT_PORT]]
end

View File

@ -121,23 +121,11 @@ class TestConnection < Test::Unit::TestCase
end
def test_nodes
db = Connection.new({:left => ['foo', 123]}, nil, :connect => false)
nodes = db.nodes
assert_equal 2, db.nodes.length
assert_equal ['foo', 123], nodes[0]
assert_equal ['localhost', Connection::DEFAULT_PORT], nodes[1]
db = Connection.new({:right => 'bar'}, nil, :connect => false)
db = Connection.paired([['foo', 27017], ['bar', 27018]], :connect => false)
nodes = db.nodes
assert_equal 2, nodes.length
assert_equal ['localhost', Connection::DEFAULT_PORT], nodes[0]
assert_equal ['bar', Connection::DEFAULT_PORT], nodes[1]
db = Connection.new({:right => ['foo', 123], :left => 'bar'}, nil, :connect => false)
nodes = db.nodes
assert_equal 2, nodes.length
assert_equal ['bar', Connection::DEFAULT_PORT], nodes[0]
assert_equal ['foo', 123], nodes[1]
assert_equal ['foo', 27017], nodes[0]
assert_equal ['bar', 27018], nodes[1]
end
context "Saved authentications" do

View File

@ -79,12 +79,12 @@ class DBTest < Test::Unit::TestCase
def test_pair
@@conn.close
@@users = nil
@@conn = Connection.new({:left => "this-should-fail", :right => [@@host, @@port]})
@@conn = Connection.paired([["this-should-fail", 27017], [@@host, @@port]])
@@db = @@conn[MONGO_TEST_DB]
assert @@conn.connected?
ensure
unless @@conn.connected?
@@conn = Connection.new(@@host, @@port)
@@conn = Connection.new(@@host, @@port)
@@db = @@conn.db(MONGO_TEST_DB)
end
@@users = @@db.collection('system.users')