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

ClusterConnectionMode must get defaulted to MULTIPLE when setting srvHost in builder

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.12.1
    • Affects Version/s: 3.11.0
    • Component/s: Builders
    • Labels:
      None

      If srvHost is set using the ClusterSettings builder then ClusterConnectionMode must also be set to Multiple. If srvHost is set then hosts will be populated to the default host and default port and ClusterConnectionMode gets defaulted to Single. 

      When creating a connection to cluster if  ClusterConnectionMode is not set to Multiple then it's assumed as a SingleServerCluster and the srvHost value is ignored. 

      if (clusterSettings.getMode() == ClusterConnectionMode.SINGLE) {
       return new SingleServerCluster(clusterId, clusterSettings, serverFactory);
      } else if (clusterSettings.getMode() == ClusterConnectionMode.MULTIPLE) {
        if (clusterSettings.getSrvHost() == null) {
          return new MultiServerCluster(clusterId, clusterSettings, serverFactory);
         } else {
          return new DnsMultiServerCluster(clusterId, clusterSettings,     serverFactory, dnsSrvRecordMonitorFactory);
         }
       }

      When using a ConnectionString with the mongodb+srv this is already being done.

      public Builder applyConnectionString(final ConnectionString connectionString) {
          if (connectionString.isSrvProtocol()){
             mode(ClusterConnectionMode.MULTIPLE); 
             srvHost(connectionString.getHosts().get(0));
           }
      

       

            Assignee:
            jeff.yemin@mongodb.com Jeffrey Yemin
            Reporter:
            raghu.9208@gmail.com Raghu c
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: