[JAVA-3573] ClusterConnectionMode must get defaulted to MULTIPLE when setting srvHost in builder Created: 01/Jan/20  Updated: 28/Oct/23  Resolved: 08/Jan/20

Status: Closed
Project: Java Driver
Component/s: Builders
Affects Version/s: 3.11.0
Fix Version/s: 3.12.1

Type: Bug Priority: Major - P3
Reporter: Raghu c Assignee: Jeffrey Yemin
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

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));
     }

 



 Comments   
Comment by Githook User [ 08/Jan/20 ]

Author:

{'name': 'Jeff Yemin', 'email': 'jeff.yemin@10gen.com', 'username': 'jyemin'}

Message: Add note about TXT records to Javadoc of ClusterSettings.Builder#srvHost

JAVA-3573
Branch: 3.12.x
https://github.com/mongodb/mongo-java-driver/commit/95b27cfed698df4d70f12a7cbbd771d25562ce21

Comment by Githook User [ 08/Jan/20 ]

Author:

{'name': 'Jeff Yemin', 'email': 'jeff.yemin@10gen.com', 'username': 'jyemin'}

Message: Set connection mode to MULTIPLE when srvHost is specified in ClusterSettings

Also:

  • Fix the check that the srvHost has three parts
  • Throw exception if the mode is not compatible with SRV
  • Beef up the unit tests for SRV in ClusterSettings

JAVA-3573
Branch: 3.12.x
https://github.com/mongodb/mongo-java-driver/commit/ff55404068bfdf1943e2e6114d4086404c5bc79e

Comment by Githook User [ 08/Jan/20 ]

Author:

{'name': 'Jeff Yemin', 'email': 'jeff.yemin@10gen.com', 'username': 'jyemin'}

Message: Add note about TXT records to Javadoc of ClusterSettings.Builder#srvHost

JAVA-3573
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/869c538197902f8a35c8dc70868ade3a5235182f

Comment by Githook User [ 08/Jan/20 ]

Author:

{'name': 'Jeff Yemin', 'email': 'jeff.yemin@10gen.com', 'username': 'jyemin'}

Message: Set connection mode to MULTIPLE when srvHost is specified in ClusterSettings

Also:

  • Fix the check that the srvHost has three parts
  • Throw exception if the mode is not compatible with SRV
  • Beef up the unit tests for SRV in ClusterSettings

JAVA-3573
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/90ec0aaf447e8ef9559728811644e2beebfdd808

Comment by Jeffrey Yemin [ 07/Jan/20 ]

Decided that the TXT record application is not really possible to address properly, so instead will add a Javadoc comment noting the difference in behavior when using ClusterSettings.Builder#srvHost directly.

Comment by Jeffrey Yemin [ 07/Jan/20 ]

Another related problem: when using a connection string, the driver applies the contents of any TXT record found for the SRV host. When using MongoClientSettings, that step is skipped.

Generated at Thu Feb 08 08:59:55 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.