Search in sources :

Example 26 with PreparedStatement

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());
}
Also used : Collection(java.util.Collection) PreparedStatement(com.datastax.driver.core.PreparedStatement) Row(com.datastax.driver.core.Row) UUID(java.util.UUID) InetAddress(java.net.InetAddress)

Example 27 with PreparedStatement

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;
}
Also used : PreparedStatement(com.datastax.driver.core.PreparedStatement) Row(com.datastax.driver.core.Row)

Example 28 with PreparedStatement

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");
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) PreparedStatement(com.datastax.driver.core.PreparedStatement) Row(com.datastax.driver.core.Row) Test(org.testng.annotations.Test)

Example 29 with PreparedStatement

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");
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) PreparedStatement(com.datastax.driver.core.PreparedStatement) Row(com.datastax.driver.core.Row) Test(org.testng.annotations.Test)

Example 30 with PreparedStatement

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");
    }
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) PreparedStatement(com.datastax.driver.core.PreparedStatement) Row(com.datastax.driver.core.Row) Test(org.testng.annotations.Test)

Aggregations

PreparedStatement (com.datastax.driver.core.PreparedStatement)113 ResultSet (com.datastax.driver.core.ResultSet)60 BoundStatement (com.datastax.driver.core.BoundStatement)59 Session (com.datastax.driver.core.Session)39 Test (org.junit.Test)30 Row (com.datastax.driver.core.Row)27 InvalidQueryException (com.datastax.driver.core.exceptions.InvalidQueryException)27 XMLStreamException (javolution.xml.stream.XMLStreamException)25 PersistenceException (org.mobicents.smsc.cassandra.PersistenceException)15 Cluster (com.datastax.driver.core.Cluster)9 Date (java.util.Date)9 IInvokableInstance (org.apache.cassandra.distributed.api.IInvokableInstance)8 ArrayList (java.util.ArrayList)7 List (java.util.List)7 Map (java.util.Map)7 QueryProcessor (org.apache.cassandra.cql3.QueryProcessor)7 GOSSIP (org.apache.cassandra.distributed.api.Feature.GOSSIP)7 NATIVE_PROTOCOL (org.apache.cassandra.distributed.api.Feature.NATIVE_PROTOCOL)7 NETWORK (org.apache.cassandra.distributed.api.Feature.NETWORK)7 ICluster (org.apache.cassandra.distributed.api.ICluster)7