[JAVA-2611] Implement Initial DNS Seedlist discovery spec Created: 22/Sep/17  Updated: 29/Oct/23  Resolved: 28/Nov/17

Status: Closed
Project: Java Driver
Component/s: Cluster Management
Affects Version/s: None
Fix Version/s: 3.6.0

Type: New Feature Priority: Major - P3
Reporter: Rathi Gnanasekaran Assignee: Jeffrey Yemin
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by DRIVERS-404 Implement Initial DNS Seedlist discov... Closed
Epic Link: Java MongoDB 3.6 Support

 Description   

Implementation note: While the specification allows a driver to block on I/O in a MongoClient or MongoClientURI constructor, that's likely not a good option for the Java driver. Blocking in constructors or factory methods is unfriendly to IOC containers like Spring and should be avoided. However, it's not clear exactly how the Java driver should do this. The problem is that MongoClientURI has a method #getClientOptions which is supposed to provide the final immutable options for a MongoClient. But the spec requires that options are also read from a DNS TXT record, which is blocking.



 Comments   
Comment by Githook User [ 28/Nov/17 ]

Author:

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

Message: JAVA-2611: Lookup SRV and TXT records in DNS when connection string protocol is mongodb+srv
Default ssl to true for this protocol, and restrict TXT record to only
authSource and replicaSet options
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/7addf8da23bb87bbf962f1a4d012ae2e1f6bee91

Comment by Jeffrey Yemin [ 27/Nov/17 ]

Next pull request: https://github.com/jyemin/mongo-java-driver/pull/80

Comment by Jeffrey Yemin [ 25/Oct/17 ]

Pull request: https://github.com/jyemin/mongo-java-driver/pull/64

Comment by Jeffrey Yemin [ 18/Oct/17 ]

One possible solution:

class MongoClient {
     private final CountDownLatch clusterLatch = new CountDownLatch(1)
     private Cluster cluster
     
     public MongoClient(MongoClientURI uri) {
           if (uri.getProtocol().equals("mongodb+srv") {
                new Thread( {
                         List<ServerAddress> srvRecord = lookupSRVRecord(uri.getHostName())
                         String txtRecordQueryParameters = lookupTXTRecord(uri.getHostName())
                         uri =  createNewURI(uri, srvRecord, txtRecordQueryParameters)
                         cluster = createCluster(uri)
                         clusterLatch.countDown()
                 }).start()
          } else {
             cluster = createCluster(uri)
             clusterLatch.countDown()
          }
     }

Then in Mongo's OperationExecutor always first await the clusterLatch (with the server selection timeout)

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