Uploaded image for project: 'Ruby Driver'
  1. Ruby Driver
  2. RUBY-931

Fail fast when the cluster you connect to doesn't expose the requested replica set

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 12_01_17
    • Affects Version/s: 2.0.4
    • Component/s: Replica Set
    • Labels:
      None

      When connecting in replica set mode, passing the wrong replica set name to Client#initialize results in an empty cluster (naturally), but doesn't tell the user that they've connected to a cluster with zero active servers.

      In such a scenario, it doesn't make sense to allow the user to continue, since nodes cannot join a replica set which do not share that replica set's name, so the topology will never change to include the non-existent replica set.

      The result of any operation will be that "no servers are available", but the reason that they aren't available (no servers matched the replica set name, and the cluster is empty) is not immediately apparent to the user.

      Instead, I propose that during topology discovery, if a replica set name is given and no nodes in the RS match the given replica set name, the driver should fast-fail with an exception.

       > m = Mongo::Client.new ["localhost:27019"], replica_set: "foobar", read: {mode: :secondary_preferred}
       => #<Mongo::Client:0x2380 cluster=localhost:27019, luna:27019>
      > m["test"].find().first
      
      Mongo::Error::NoServerAvailable: No server is available matching preference: #<Mongo::ServerSelector::SecondaryPreferred:0x38af1bf6 @tag_sets=[], @options={:database=>"admin", :replica_set=>"foobar", :read=>{:mode=>:secondary_preferred}}, @server_selection_timeout=30>
              from /usr/local/rvm/gems/jruby-head/gems/mongo-2.0.4/lib/mongo/server_selector/selectable.rb:99:in `select_server'
              from /usr/local/rvm/gems/jruby-head/gems/mongo-2.0.4/lib/mongo/collection/view/iterable.rb:38:in `each'
              from org/jruby/RubyEnumerable.java:397:in `first'
      

            Assignee:
            emily.stolfo Emily Stolfo
            Reporter:
            cheald Chris Heald
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: