Skip to content

Commit 851f631

Browse files
adutrasnicoll
authored andcommitted
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
1 parent 1835323 commit 851f631

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cassandra/CassandraHealthIndicator.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616

1717
package org.springframework.boot.actuate.cassandra;
1818

19+
import com.datastax.driver.core.ConsistencyLevel;
1920
import com.datastax.driver.core.ResultSet;
20-
import com.datastax.driver.core.querybuilder.QueryBuilder;
21-
import com.datastax.driver.core.querybuilder.Select;
21+
import com.datastax.driver.core.SimpleStatement;
22+
import com.datastax.driver.core.Statement;
2223

2324
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
2425
import org.springframework.boot.actuate.health.Health;
@@ -35,6 +36,9 @@
3536
*/
3637
public class CassandraHealthIndicator extends AbstractHealthIndicator {
3738

39+
private static final Statement SELECT = new SimpleStatement("SELECT release_version FROM system.local")
40+
.setConsistencyLevel(ConsistencyLevel.LOCAL_ONE);
41+
3842
private CassandraOperations cassandraOperations;
3943

4044
public CassandraHealthIndicator() {
@@ -53,9 +57,8 @@ public CassandraHealthIndicator(CassandraOperations cassandraOperations) {
5357

5458
@Override
5559
protected void doHealthCheck(Health.Builder builder) throws Exception {
56-
Select select = QueryBuilder.select("release_version").from("system", "local");
57-
ResultSet results = this.cassandraOperations.getCqlOperations().queryForResultSet(select);
58-
if (results.isExhausted()) {
60+
ResultSet results = this.cassandraOperations.getCqlOperations().queryForResultSet(SELECT);
61+
if (results.isFullyFetched()) {
5962
builder.up();
6063
return;
6164
}

0 commit comments

Comments
 (0)