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: * Removed the following deprecated items:
* GridStore class * GridStore class
* RegexpOfHolding 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). * BSON-related code extracted into two separate gems: bson and bson_ext (thx to Chuck Remes).
* mongo_ext no longer exists. * mongo_ext no longer exists.

View File

@ -886,7 +886,6 @@ void Init_cbson() {
rb_require("bson/types/min_max_keys"); rb_require("bson/types/min_max_keys");
MinKey = rb_const_get(bson, rb_intern("MinKey")); MinKey = rb_const_get(bson, rb_intern("MinKey"));
MaxKey = rb_const_get(bson, rb_intern("MaxKey")); MaxKey = rb_const_get(bson, rb_intern("MaxKey"));
rb_require("bson/types/regexp_of_holding");
Regexp = rb_const_get(rb_cObject, rb_intern("Regexp")); Regexp = rb_const_get(rb_cObject, rb_intern("Regexp"));
rb_require("bson/exceptions"); rb_require("bson/exceptions");
InvalidKeyName = rb_const_get(bson, rb_intern("InvalidKeyName")); 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. # 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. # 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 # To specify a pair, use Connection.paired.
# * 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]
# #
# Note that there are a few issues when using connection pooling with Ruby 1.9 on Windows. These # 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. # should be resolved in the next release.
# #
# @param [String, Hash] pair_or_host See explanation above. # @param [String, Hash] host.
# @param [Integer] port specify a port number here if only one host is being specified. Leave nil if # @param [Integer] port specify a port number here if only one host is being specified.
# specifying a pair of servers in +pair_or_host+.
# #
# @option options [Boolean] :slave_ok (false) Must be set to +true+ when connecting # @option options [Boolean] :slave_ok (false) Must be set to +true+ when connecting
# to a single, slave node. # to a single, slave node.
# @option options [Logger, #debug] :logger (nil) Logger instance to receive driver operation log. # @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 [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, # @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. # this is the number of seconds to wait for a new connection to be released before throwing an exception.
# #
#
# @example localhost, 27017 # @example localhost, 27017
# Connection.new # Connection.new
# #
@ -77,25 +71,16 @@ module Mongo
# @example localhost, 3000, where this node may be a slave # @example localhost, 3000, where this node may be a slave
# Connection.new("localhost", 3000, :slave_ok => true) # 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 # @see http://www.mongodb.org/display/DOCS/Replica+Pairs+in+Ruby Replica pairs in Ruby
# #
# @core connections # @core connections
def initialize(pair_or_host=nil, port=nil, options={}) def initialize(host=nil, port=nil, options={})
@auths = [] @auths = []
if block_given? if block_given?
@nodes = yield self @nodes = yield self
else else
@nodes = format_pair(pair_or_host, port) @nodes = format_pair(host, port)
end end
# Host and port of current master. # Host and port of current master.
@ -118,10 +103,6 @@ module Mongo
@sockets = [] @sockets = []
@checked_out = [] @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 can be true only if one node is specified
@slave_ok = options[:slave_ok] && @nodes.length == 1 @slave_ok = options[:slave_ok] && @nodes.length == 1
@logger = options[:logger] || nil @logger = options[:logger] || nil
@ -479,12 +460,6 @@ module Mongo
case pair_or_host case pair_or_host
when String when String
[[pair_or_host, port ? port.to_i : DEFAULT_PORT]] [[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 when nil
[['localhost', DEFAULT_PORT]] [['localhost', DEFAULT_PORT]]
end end

View File

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

View File

@ -79,7 +79,7 @@ class DBTest < Test::Unit::TestCase
def test_pair def test_pair
@@conn.close @@conn.close
@@users = nil @@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] @@db = @@conn[MONGO_TEST_DB]
assert @@conn.connected? assert @@conn.connected?
ensure ensure