Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

RUBY-457 Multiple mongos connection support

Initial ShardedConnection interface specification
  • Loading branch information...
commit b0a3772f32d3f42bb53aaa7abea270471ca55198 1 parent ba30ba6
Gary J. Murakami, Ph.D. gjmurakami-10gen authored
9 lib/mongo/repl_set_connection.rb
@@ -41,8 +41,8 @@ class ReplSetConnection < Connection
41 41 # @option opts [String] :name (nil) The name of the replica set to connect to. You
42 42 # can use this option to verify that you're connecting to the right replica set.
43 43 # @option opts [Boolean, Hash] :safe (false) Set the default safe-mode options
44   - # propogated to DB objects instantiated off of this Connection. This
45   - # default can be overridden upon instantiation of any DB by explicity setting a :safe value
  44 + # propagated to DB objects instantiated off of this Connection. This
  45 + # default can be overridden upon instantiation of any DB by explicitly setting a :safe value
46 46 # on initialization.
47 47 # @option opts [:primary, :secondary] :read (:primary) The default read preference for Mongo::DB
48 48 # objects created from this connection object. If +:secondary+ is chosen, reads will be sent
@@ -80,10 +80,9 @@ class ReplSetConnection < Connection
80 80 #
81 81 # @see http://api.mongodb.org/ruby/current/file.REPLICA_SETS.html Replica sets in Ruby
82 82 #
83   - # @raise [MongoArgumentError] If called with no arguments and <code>ENV["MONGODB_URI"]</code> implies a direct connection.
  83 + # @raise [MongoArgumentError] This is raised for usage errors.
84 84 #
85   - # @raise [ReplicaSetConnectionError] This is raised if a replica set name is specified and the
86   - # driver fails to connect to a replica set with that name.
  85 + # @raise [ConnectionFailure] This is raised for the various connection failures.
87 86 def initialize(*args)
88 87 if args.last.is_a?(Hash)
89 88 opts = args.pop
70 lib/mongo/sharded_connection.rb
... ... @@ -0,0 +1,70 @@
  1 +# encoding: UTF-8
  2 +
  3 +# --
  4 +# Copyright (C) 2008-2011 10gen Inc.
  5 +#
  6 +# Licensed under the Apache License, Version 2.0 (the "License");
  7 +# you may not use this file except in compliance with the License.
  8 +# You may obtain a copy of the License at
  9 +#
  10 +# http://www.apache.org/licenses/LICENSE-2.0
  11 +#
  12 +# Unless required by applicable law or agreed to in writing, software
  13 +# distributed under the License is distributed on an "AS IS" BASIS,
  14 +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 +# See the License for the specific language governing permissions and
  16 +# limitations under the License.
  17 +# ++
  18 +
  19 +module Mongo
  20 +
  21 + # Instantiates and manages connections to a MongoDB sharded cluster for high availability.
  22 + class ShardedConnection < Connection
  23 +
  24 + SHAREDED_CLUSTER_OPTS = [:read, :refresh_mode, :refresh_interval, :name]
  25 +
  26 + attr_reader :sharded_cluster_name, :seeds, :refresh_interval, :refresh_mode,
  27 + :refresh_version, :manager
  28 +
  29 + # Create a connection to a MongoDB sharded cluster.
  30 + #
  31 + # If no args are provided, it will check <code>ENV["MONGODB_URI"]</code>.
  32 + #
  33 + # @param [Array] seeds "host:port" strings
  34 + #
  35 + # @option opts [String] :name (nil) The name of the sharded cluster to connect to. You
  36 + # can use this option to verify that you're connecting to the right sharded cluster.
  37 + # @option opts [Boolean, Hash] :safe (false) Set the default safe-mode options
  38 + # propagated to DB objects instantiated off of this Connection. This
  39 + # default can be overridden upon instantiation of any DB by explicitly setting a :safe value
  40 + # on initialization.
  41 + # @option opts [Logger] :logger (nil) Logger instance to receive driver operation log.
  42 + # @option opts [Integer] :pool_size (1) The maximum number of socket connections allowed per
  43 + # connection pool. Note: this setting is relevant only for multi-threaded applications.
  44 + # @option opts [Float] :pool_timeout (5.0) When all of the connections a pool are checked out,
  45 + # this is the number of seconds to wait for a new connection to be released before throwing an exception.
  46 + # Note: this setting is relevant only for multi-threaded applications.
  47 + # @option opts [Float] :op_timeout (nil) The number of seconds to wait for a read operation to time out.
  48 + # @option opts [Float] :connect_timeout (30) The number of seconds to wait before timing out a
  49 + # connection attempt.
  50 + # @option opts [Boolean] :ssl (false) If true, create the connection to the server using SSL.
  51 + # @option opts [Boolean] :refresh_mode (false) Set this to :sync to periodically update the
  52 + # state of the connection every :refresh_interval seconds. Sharded cluster connection failures
  53 + # will always trigger a complete refresh. This option is useful when you want to add new nodes
  54 + # or remove sharded cluster nodes not currently in use by the driver.
  55 + # @option opts [Integer] :refresh_interval (90) If :refresh_mode is enabled, this is the number of seconds
  56 + # between calls to check the sharded cluster's state.
  57 + # Note: that the number of seed nodes does not have to be equal to the number of sharded cluster members.
  58 + # The purpose of seed nodes is to permit the driver to find at least one sharded cluster member even if a member is down.
  59 + #
  60 + # @example Connect to a sharded cluster and provide two seed nodes.
  61 + # Mongo::ShardedConnection.new(['localhost:30000', 'localhost:30001'])
  62 + #
  63 + # @example Connect to a sharded cluster providing two seed nodes and ensuring a connection to the sharded cluster named 'prod':
  64 + # Mongo::ShardedConnection.new(['localhost:30000', 'localhost:30001'], :name => 'prod')
  65 + #
  66 + # @raise [MongoArgumentError] This is raised for usage errors.
  67 + #
  68 + # @raise [ConnectionFailure] This is raised for the various connection failures.
  69 + end
  70 +end

0 comments on commit b0a3772

Please sign in to comment.
Something went wrong with that request. Please try again.