Commit 851f631e authored by Alexandre Dutra's avatar Alexandre Dutra Committed by Stephane Nicoll

Use LOCAL_ONE when querying system.local

The system keyspace has a replication factor of 1 and is local to each
node; it is therefore recommended to query system.local with a
consistency level of ONE or LOCAL_ONE.

Stronger consistency levels may result in an Unavailable error, but this
does not mean that the node is down.

See gh-20709
parent 18353231
......@@ -16,9 +16,10 @@
package org.springframework.boot.actuate.cassandra;
import com.datastax.driver.core.ConsistencyLevel;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.querybuilder.QueryBuilder;
import com.datastax.driver.core.querybuilder.Select;
import com.datastax.driver.core.SimpleStatement;
import com.datastax.driver.core.Statement;
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health;
......@@ -35,6 +36,9 @@ import org.springframework.util.Assert;
*/
public class CassandraHealthIndicator extends AbstractHealthIndicator {
private static final Statement SELECT = new SimpleStatement("SELECT release_version FROM system.local")
.setConsistencyLevel(ConsistencyLevel.LOCAL_ONE);
private CassandraOperations cassandraOperations;
public CassandraHealthIndicator() {
......@@ -53,9 +57,8 @@ public class CassandraHealthIndicator extends AbstractHealthIndicator {
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
Select select = QueryBuilder.select("release_version").from("system", "local");
ResultSet results = this.cassandraOperations.getCqlOperations().queryForResultSet(select);
if (results.isExhausted()) {
ResultSet results = this.cassandraOperations.getCqlOperations().queryForResultSet(SELECT);
if (results.isFullyFetched()) {
builder.up();
return;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment