How can we use a DNS Server ip and a Service name to talk to Cassandra using the Java Driver

381 views
Skip to first unread message

Kant Kodali

unread,
Oct 17, 2016, 2:31:06 PM10/17/16
to DataStax Java Driver for Apache Cassandra User Mailing List
Hi Guys,

I am able to do the following

dig A @dns-server-ip cassandra-service 

This resulted in bunch of ip's where cassandra is running. Now, how can I use this along with the java driver where I can pass in dns-server-ip and cassandra-service so I can finally talk to cassandra?

Thanks!

Andrew Tolbert

unread,
Oct 17, 2016, 2:40:48 PM10/17/16
to DataStax Java Driver for Apache Cassandra User Mailing List
Hi Kant,

Since driver 3.0.0, the driver does work when an address that resolves to a class A DNS record is provided as a contact point (change was in this PR) .  It will resolve all IP addresses and choose from those to try to establish a control connection which will discover the rest of the hosts.

Thanks,
Andy

Kant Kodali

unread,
Oct 17, 2016, 2:45:01 PM10/17/16
to DataStax Java Driver for Apache Cassandra User Mailing List
Hi Andrew,

In my case, The address doesn't resolve to class A DNS record unless I point to a custom dns server so I am trying to figure out how to pass in custom dns server ip ?

Thanks,
kant

--
You received this message because you are subscribed to the Google Groups "DataStax Java Driver for Apache Cassandra User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to java-driver-user+unsubscribe@lists.datastax.com.

Andrew Tolbert

unread,
Oct 17, 2016, 2:52:56 PM10/17/16
to DataStax Java Driver for Apache Cassandra User Mailing List
If i'm understanding your question correctly, are you asking how to specify which DNS server to use to resolve the A record?

As far as I understand it, java uses the underlying operating system to determine what DNS server to use so it depends on your host environment.  It looks like you can specify a system property (see this stack overflow post for how to do that), although it looks specific to the oracle JDK.

Thanks,
Andy
To unsubscribe from this group and stop receiving emails from it, send an email to java-driver-us...@lists.datastax.com.

Kant Kodali

unread,
Oct 17, 2016, 2:58:18 PM10/17/16
to DataStax Java Driver for Apache Cassandra User Mailing List
yes and I am using open-jdk. I guess no luck for me!

To unsubscribe from this group and stop receiving emails from it, send an email to java-driver-user+unsubscribe@lists.datastax.com.

Andrew Tolbert

unread,
Oct 17, 2016, 3:09:10 PM10/17/16
to DataStax Java Driver for Apache Cassandra User Mailing List
There might be an OpenJDK analog to those system properties, but I think pushing that configuration responsibility to the DNS resolver on the system is probably the right choice anyways.  I think the system property route should only be used when you don't really have the choice or want to override the environment behavior for some explicit reason.

Thanks,
Andy
To unsubscribe from this group and stop receiving emails from it, send an email to java-driver-us...@lists.datastax.com.

Kant Kodali

unread,
Oct 17, 2016, 3:16:52 PM10/17/16
to DataStax Java Driver for Apache Cassandra User Mailing List
In containerized deployments it is becoming increasingly important to pass in a custom dns server ip instead of using the native host DNS. It is just another parameter not sure why there isn't a easy way to make that configurable.

Thanks!


To unsubscribe from this group and stop receiving emails from it, send an email to java-driver-user+unsubscribe@lists.datastax.com.

Andrew Tolbert

unread,
Oct 17, 2016, 3:22:25 PM10/17/16
to DataStax Java Driver for Apache Cassandra User Mailing List
Configuring DNS in a container should be pretty reasonable.   For example, in docker, the create/run commands allow you to specify the DNS server the container uses (docs):

--dns value                   Set custom DNS servers (default [])
--dns-opt value               Set DNS options (default [])
--dns-search value            Set custom DNS search domains (default [])


Thanks,
Andy
To unsubscribe from this group and stop receiving emails from it, send an email to java-driver-us...@lists.datastax.com.

Kant Kodali

unread,
Oct 17, 2016, 3:48:34 PM10/17/16
to DataStax Java Driver for Apache Cassandra User Mailing List
Hi Andrew,

I am just trying to add more details to this thread thinking that other users with a similar problem may benefit from this discussion. I have to give more and more context but in short the best way for me would be to be able to pass the dns server ip programatically.  The longer version would be I have 4 containers (3 containers for Cassandra cluster and 1 container for a DNS server) and I have VM(not container) where my client program needs to run and it should ask the DNS server to give the ip's of Cassandra given the service name. I do understand it is feasible by making environment or architectural changes but the easiest for now would be passing it in programmatically. 

Thanks,
kant

To unsubscribe from this group and stop receiving emails from it, send an email to java-driver-user+unsubscribe@lists.datastax.com.

Reply all
Reply to author
Forward
0 new messages