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
This commit is contained in:
committed by
Stephane Nicoll
parent
18353231a0
commit
851f631eac
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user