1

I would like to make sure that I can connect to the db from Java service from time to time (like ping). This answer suggests to use show version.

My Java service is using the Cassandra thrift client (which is deprecated) and I couldn't find an example how to execute such a query.

I have a client of type org.apache.cassandra.thrift.Cassandra.Client. Those are the methods I found that are similar:

System.out.println("describe_schema_versions: " + nativeClient.describe_schema_versions());
System.out.println("describe_version: " + nativeClient.describe_version());
System.out.println("describe_snitch: " + nativeClient.describe_snitch());
System.out.println("describe_cluster_name: " + nativeClient.describe_cluster_name());
System.out.println("describe_keyspaces: " + nativeClient.describe_keyspaces());
System.out.println("describe_partitioner: " + nativeClient.describe_partitioner());
System.out.println("describe_token_map: " + nativeClient.describe_token_map());

How can I execute query to get Cassandra server version like this?

cqlsh> show version;
[cqlsh 3.1.8 | Cassandra 1.2.19 | CQL spec 3.0.5 | Thrift protocol 19.36.2]

Or is there an alternative query preferred as "ping"?

oshai
  • 14,865
  • 26
  • 84
  • 140
  • This answer might help: https://stackoverflow.com/questions/10246287/health-check-for-cassandra-connection-using-hector – Aaron Jan 28 '21 at 14:13

2 Answers2

2

if you just want make a health check, i think run a simple query is a good choice.

 SELECT now() FROM system.local

here is the doc about how thrift client run query.
Cassandra.Client (apache-cassandra API) - Javadoc Extreme

Rand Chen
  • 101
  • 4
1

Worth noting, but some folks have had a hard time with system.now() due to the integer format with Thrift. This is largely due to the fact that system.local is a cql3 table, and not a Thrift column family.

To that end, this returns a string, which may be easier to deal with:

aploetz@cqlsh> SELECT release_version FROM system.local;

 release_version 
-----------------
          3.11.6 

(1 rows)

Or via the Cassandra CLI:

[default@system] get local['local']['release_version']

You can also pull thrift_version, if you'd rather do that (which is also a string).

Aaron
  • 55,518
  • 11
  • 116
  • 132