[JAVA-4512] Allow customization of the DNS client Created: 03/Mar/22 Updated: 28/Oct/23 Resolved: 25/Mar/22 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | Cluster Management |
| Affects Version/s: | None |
| Fix Version/s: | 4.6.0 |
| Type: | New Feature | Priority: | Major - P3 |
| Reporter: | Clement Escoffier | Assignee: | Jeffrey Yemin |
| Resolution: | Fixed | Votes: | 2 |
| Labels: | QP-priority, external-user, graalvm, quarkus | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||
| Quarter: | FY23Q2 | ||||
| Backwards Compatibility: | Fully Compatible | ||||
| Documentation Changes: | Needed | ||||
| Description |
|
Updated Description A new interface, com.mongodb.spi.dns.DnsClient will be created that defines a minimal API for a DNS provider. Additionally, a service provider interface, com.mongodb.spi.dns.DnsClientProvider will be created. The latter will be used by the driver to look up implementations of DnsClient via the mechanisms described in java.util.ServiceLoader. If no implementations are found, the driver will fallback to using JNDI for looking up SRV and TXT records (which is the current behavior). Original Description When resolving mongo+srv:// URLs, the MongoDB client (in Java) uses JNDI. However, with GraalVM, JNDI is not supported when building native executables. At the moment, in Quarkus, we have a "substitution" that replaces the default DNS client when building a native executable. It would be great to avoid substituting and instead allow the user to customize the DNS client they want to use (defaulting to the current one). There is already a DNS client interface. There are two possibilities:
|
| Comments |
| Comment by Jeffrey Yemin [ 14/Apr/23 ] |
|
Looking a bit more closely, I see that the LongObjectHashMap is used only for testing purposes, so it's thread-safety is not a real concern here. |
| Comment by Jeffrey Yemin [ 14/Apr/23 ] |
|
Initial read of the source code suggests that io.vertx.core.dns.impl.DnsClientImpl, on which io.quarkus.mongodb.runtime.dns.MongoDnsClient depends, is not thread-safe. as it has a field of type io.netty.util.collection.LongObjectHashMap that has no internal synchronization and is not synchronized externally either. |
| Comment by George Gastaldi [ 14/Apr/23 ] |
|
jeff.yemin@mongodb.com here it is: https://github.com/quarkusio/quarkus/blob/main/extensions/mongodb-client/runtime/src/main/java/io/quarkus/mongodb/runtime/dns/MongoDnsClient.java |
| Comment by Jeffrey Yemin [ 13/Apr/23 ] |
|
gegastaldi@gmail.com or cescoffi@redhat.com, can you point us to the DnsClient implementation in Quarkus? We're wondering if it's already thread-safe, since we are considering adding a requirement that it be so. Currently we don't document DnsClient one way or the other in terms of thread safety, and the driver as written currently doesn't require it to be so. See https://github.com/mongodb/mongo-java-driver/pull/1104#discussion_r1160733871 |
| Comment by Githook User [ 25/Mar/22 ] |
|
Author: {'name': 'Jeff Yemin', 'email': 'jeff.yemin@mongodb.com', 'username': 'jyemin'}Message: Lookup DnsClientProvider via ServiceLoader (#893) Default to existing JNDI-based implementation
|
| Comment by George Gastaldi [ 13/Mar/22 ] |
|
I created a PR in https://github.com/mongodb/mongo-java-driver/pull/892 with a proposed solution for this issue |