Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-665

Connection configuration allows to specify independent nodes as replica set

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 2.9.0, 2.9.1
    • Component/s: Cluster Management
    • Labels:
      None
    • Environment:
      Windows 7 x64
      mongodb 2.0.4

      I have faced with possibility to specify two (or more) independent nodes as replica set via MongoURI(...) parameter.

      E.g. I started two independent nodes...

      mongod.exe --dbpath .\1\db\ --rest --logappend --logpath .\1\mongo\log --port=1234
      mongod.exe --dbpath .\2\db\ --rest --logappend --logpath .\2\mongo\log --port=5678
      

      ... and configured connection like following:

      Mongo con = new Mongo(new MongoURI("mongodb://127.0.0.1:1234,127.0.0.1:5678"));
      

      There are no warnings or errors and following code behaves with illusion of correctly passed replica set configuration:

      ReplicaSetStatus status = con.getReplicaSetStatus();
      status.isMaster(new ServerAddress("127.0.0.1", 1234)); // true
      status.isMaster(new ServerAddress("127.0.0.1", 5678)); // false
      status.getMaster().toString(); // 127.0.0.1:1234
      WriteResult r = con.getDB("x").getCollection("y").save(new BasicDBObject("a", "b"));
      r.getLastError().throwOnError(); // there are no errors
      

      The only way to detect that configuration is incorrect - specify REPLICA_SAFE write concern:

      con.getDB("x").getCollection("y").save(new BasicDBObject("a", "b"), WriteConcern.REPLICAS_SAFE); // com.mongodb.MongoException: norepl
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            raman_yushkou@epam.com Raman Yushkou
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: