use of com.datastax.driver.core.PreparedStatement in project atlasdb by palantir.
the class CqlKeyValueServices method waitForSchemaVersionsToCoalesce.
public static void waitForSchemaVersionsToCoalesce(String encapsulatingOperationDescription, CqlKeyValueService kvs) {
PreparedStatement peerInfoQuery = kvs.getPreparedStatement(CassandraConstants.NO_TABLE, "select peer, schema_version from system.peers;", kvs.session);
peerInfoQuery.setConsistencyLevel(ConsistencyLevel.ALL);
Multimap<UUID, InetAddress> peerInfo = ArrayListMultimap.create();
long start = System.currentTimeMillis();
long sleepTime = 100;
do {
peerInfo.clear();
for (Row row : kvs.session.execute(peerInfoQuery.bind()).all()) {
peerInfo.put(row.getUUID("schema_version"), row.getInet("peer"));
}
if (peerInfo.keySet().size() <= 1) {
// full schema agreement
return;
}
sleepTime = Math.min(sleepTime * 2, 5000);
} while (System.currentTimeMillis() < start + CassandraConstants.SECONDS_WAIT_FOR_VERSIONS * 1000);
StringBuilder sb = new StringBuilder();
sb.append(String.format("Cassandra cluster cannot come to agreement on schema versions," + " during operation: %s.", encapsulatingOperationDescription));
for (Entry<UUID, Collection<InetAddress>> versionToPeer : peerInfo.asMap().entrySet()) {
sb.append(String.format("%nAt schema version %s:", versionToPeer.getKey()));
for (InetAddress peer : versionToPeer.getValue()) {
sb.append(String.format("%n\tNode: %s", peer));
}
}
sb.append("\nFind the nodes above that diverge from the majority schema" + " (or have schema 'UNKNOWN', which likely means they are down/unresponsive)" + " and examine their logs to determine the issue. Fixing the underlying issue and restarting Cassandra" + " should resolve the problem. You can quick-check this with 'nodetool describecluster'.");
throw new IllegalStateException(sb.toString());
}
use of com.datastax.driver.core.PreparedStatement in project atlasdb by palantir.
the class CqlKeyValueServices method getLocal.
public static Local getLocal(Session session) {
PreparedStatement selectLocalInfo = session.prepare("select data_center, rack from system.local;");
Row localRow = session.execute(selectLocalInfo.bind()).one();
Local local = new Local();
local.dataCenter = localRow.getString("data_center");
local.rack = localRow.getString("rack");
return local;
}
use of com.datastax.driver.core.PreparedStatement in project java-driver by datastax.
the class QueryBuilder21ExecutionTest method should_handle_contains_key_on_map_with_index.
@Test(groups = "short")
public void should_handle_contains_key_on_map_with_index() {
PreparedStatement byFeatures = session().prepare(select("id", "description", "features_keys").from("products").where(containsKey("features_keys", bindMarker("feature"))));
ResultSet results = session().execute(byFeatures.bind().setString("feature", "refresh-rate"));
Row row = results.one();
assertThat(row).isNotNull();
assertThat(row.getInt("id")).isEqualTo(34134);
assertThat(row.getMap("features_keys", String.class, String.class)).containsEntry("refresh-rate", "400hz");
}
use of com.datastax.driver.core.PreparedStatement in project java-driver by datastax.
the class QueryBuilder21ExecutionTest method should_handle_contains_on_map_with_index.
@Test(groups = "short")
public void should_handle_contains_on_map_with_index() {
PreparedStatement byFeatures = session().prepare(select("id", "description", "features_values").from("products").where(contains("features_values", bindMarker("feature"))));
ResultSet results = session().execute(byFeatures.bind().setString("feature", "LED"));
Row row = results.one();
assertThat(row).isNotNull();
assertThat(row.getInt("id")).isEqualTo(29412);
assertThat(row.getMap("features_values", String.class, String.class)).containsEntry("techno", "LED");
}
use of com.datastax.driver.core.PreparedStatement in project java-driver by datastax.
the class QueryBuilder21ExecutionTest method should_handle_contains_on_set_with_index.
@Test(groups = "short")
public void should_handle_contains_on_set_with_index() {
PreparedStatement byCategory = session().prepare(select("id", "description", "categories").from("products").where(contains("categories", bindMarker("category"))));
ResultSet results = session().execute(byCategory.bind().setString("category", "hdtv"));
assertThat(results.getAvailableWithoutFetching()).isEqualTo(2);
for (Row row : results) {
assertThat(row.getSet("categories", String.class)).contains("hdtv");
}
}
Aggregations