Skip to content

Commit 58ced60

Browse files
authored
DRILL-8021: Add the srv protocol support for the mongo storage (#2352)
1 parent b6da35e commit 58ced60

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

contrib/storage-mongo/src/main/java/org/apache/drill/exec/store/mongo/MongoStoragePlugin.java

+12-7
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,19 @@ public synchronized MongoClient getClient(List<ServerAddress> addresses) {
202202
String userName = credential == null ? null : credential.getUserName();
203203
MongoCnxnKey key = new MongoCnxnKey(serverAddress, userName);
204204
try {
205-
return addressClientMap.get(key, () -> {
206-
logger.info("Created connection to {}.", key);
207-
logger.info("Number of open connections {}.", addressClientMap.size());
208-
MongoClientSettings.Builder settings = MongoClientSettings.builder()
209-
.applyToClusterSettings(builder -> builder.hosts(addresses));
210-
if (credential != null) {
211-
settings.credential(credential);
205+
return addressClientMap.get(key, () -> {
206+
MongoClientSettings.Builder settings;
207+
if (clientURI.isSrvProtocol()) {
208+
settings = MongoClientSettings.builder().applyConnectionString(clientURI);
209+
logger.info("Created srv protocol connection to {}.", key);
210+
} else {
211+
settings = MongoClientSettings.builder().applyToClusterSettings(builder -> builder.hosts(addresses));
212+
if (credential != null) {
213+
settings.credential(credential);
214+
}
215+
logger.info("Created connection to {}.", key);
212216
}
217+
logger.info("Number of open connections {}.", addressClientMap.size() + 1); // include this created
213218
return MongoClients.create(settings.build());
214219
});
215220
} catch (ExecutionException e) {

0 commit comments

Comments
 (0)