Health check for Cassandra connection (using hector)?
Asked Answered
Z

4

15

For operations monitoring of my application, I am looking for something similar to the commonly used "SQL connection validation" query

SELECT 1;

in Cassandra, using the Hector driver. I have tried things like looking at Cluster.getKnownPoolHosts() and .getConnectionManager().getActivePools(). But it seems that their status is not continuously updated, only when I actually try to access Cassandra with a query.

I'd like my health check to be independent of any keyspaces or user CFs that need to exist, so just running a "dummy" query seems difficult (against what?). And of course it shouldn't take a lot of memory or generate any significant load.

Can I force Hector somehow to update its connection pool status without running a real query?

(BTW: CQL doesn't even accept "SELECT 1" as a valid query.)

Zohara answered 20/4, 2012 at 12:31 Comment(2)
did you find an answer to this? I'm trying to do the sameAnamorphoscope
Yes, I found an approach that seems to work well for me. See answer below.Zohara
Z
4

The solution I'm currently using, and which seems to be the most robust so far (tested with Cassandra 1.1 and 1.2) is a simple query on "system":

Query<String> query = Query.selectQuery("*", "system", null, 1, consistencyLevel, StringSerializer.get());

It's not exactly what I wanted since it's a "real" query, but on the other hand it doesn't give any false positives.

Zohara answered 11/4, 2013 at 5:40 Comment(6)
I could be wrong but I think this approach will always call the same node(s) -- depending on consistencyLevel you will call always 1, Q or All nodes of your RF. If you want monitor if the connection is active you can do it, if you want monitor the ring status I'd use nodetool inside your java applicationLeveller
This is intended as a connection check, not as an operations check of the Cassandra cluster.Zohara
@HansMari, How actually you do this check? Do you check some query properties?Niles
If the query works OK, the connection is up. The actual query results don't matter.Zohara
So if there is no exception, we think that connection is up. correct?Niles
@Zohara what does this look like in real cql query?Foot
I
20

With CQL3, I'm using the following query:

SELECT now() FROM system.local;

It would be nice to get rid of the FROM clause altogther to make this generic, in case the user does not have access to the system keyspace or local column family for some reason. But as with the other answers, at least this should not give false positives.

Illusionist answered 3/12, 2013 at 12:0 Comment(4)
How actually you do this check? Do you catch some exception or examine QuerryResult object?Niles
Yes, just checking that this one does not throw an exception. One could also verify that the query actually returns something, but I found that unnecessary.Illusionist
do we have any better solution for this because it's very old commentsAutonomic
This query returns a timestamp, which I couldn't get converted to any Java type. The alternative query that works for me and returns a string is SELECT release_version FROM system.local;Despinadespise
Z
4

The solution I'm currently using, and which seems to be the most robust so far (tested with Cassandra 1.1 and 1.2) is a simple query on "system":

Query<String> query = Query.selectQuery("*", "system", null, 1, consistencyLevel, StringSerializer.get());

It's not exactly what I wanted since it's a "real" query, but on the other hand it doesn't give any false positives.

Zohara answered 11/4, 2013 at 5:40 Comment(6)
I could be wrong but I think this approach will always call the same node(s) -- depending on consistencyLevel you will call always 1, Q or All nodes of your RF. If you want monitor if the connection is active you can do it, if you want monitor the ring status I'd use nodetool inside your java applicationLeveller
This is intended as a connection check, not as an operations check of the Cassandra cluster.Zohara
@HansMari, How actually you do this check? Do you check some query properties?Niles
If the query works OK, the connection is up. The actual query results don't matter.Zohara
So if there is no exception, we think that connection is up. correct?Niles
@Zohara what does this look like in real cql query?Foot
D
0

Eemeli Kantola's query returns a timestamp, which I couldn't get converted to any Java type. The alternative query that works for me and returns a string is SELECT release_version FROM system.local;

Despinadespise answered 1/9, 2020 at 4:23 Comment(0)
S
0

You can try to check cassandra status next way:

CqlSession session = ...;
Collection<Node> nodes = session.getMetadata().getNodes().values();
Optional<Node> nodeUp = nodes.stream().filter((node) -> node.getState() == NodeState.UP).findAny();
bool isNodeUp = nodeUp.isPresent();

Source: CassandraDriverHealthIndicator.

Senatorial answered 23/3, 2022 at 17:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.