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

MongoDB's connection is not a effective connection to a MongDB server where new Mongo(serverAddressList)

    • Type: Icon: Bug Bug
    • Resolution: Won't Fix
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.6.5, 2.7.2
    • Component/s: None

      Here is our code to start mongoDB:

      for (String hostName : hostNames) {
                  String tmp[] = hostName.split(":");
                  ServerAddress addr = new ServerAddress(tmp[0], Integer.parseInt(tmp[1]));
                  hosts.add(addr);
              }
              mongo = new Mongo(hosts);
              db = mongo.getDB(dbName);
              WriteConcern wc = WriteConcern.valueOf(writeConcernName);
              db.setWriteConcern(wc);
              if (this.slaveOk) {
                  db.slaveOk();
      }
      

      I find that Mongo instance does not check master;

      The code of checking master is in Upate class:

      _mongo.getConnector().checkMaster(true, false);//the second argument is failIfNoMaster
      

      The checkMaster method code is in DBTcpConnection:

      void checkMaster( boolean force , boolean failIfNoMaster )
              throws MongoException {
              
              if ( _rsStatus != null ){
                  if ( _masterPortPool == null || force ){
                      ReplicaSetStatus.Node n = _rsStatus.ensureMaster();
                      if ( n == null ){
                          if ( failIfNoMaster )
                              throw new MongoException( "can't find a master" );
                      }
                      else {
                          _set( n._addr );
                          maxBsonObjectSize = _rsStatus.getMaxBsonObjectSize();
                      }
                  }
              } else {
                  // single server, may have to obtain max bson size
                  if (maxBsonObjectSize == 0)
                          maxBsonObjectSize = fetchMaxBsonObjectSize();
              }
          }
      

      So,there are two problem:

      First is:if I want to check master in staring my web applcation,I just have no choice;

      Second is: The Mongo object instance actually represents a pool of connections to the database,this thing is not any valuable if we don't check master;

      I suggest that you can make checkMaster method publicly or get us a button is check master.

            Assignee:
            jeff.yemin@mongodb.com Jeffrey Yemin
            Reporter:
            boringkiller xfc
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: