use of org.apache.cassandra.distributed.api.ConsistencyLevel in project cassandra by apache.
the class Coordinator method executeInternal.
private SimpleQueryResult executeInternal(String query, ConsistencyLevel consistencyLevelOrigin, Object[] boundValues) {
ClientState clientState = makeFakeClientState();
CQLStatement prepared = QueryProcessor.getStatement(query, clientState);
List<ByteBuffer> boundBBValues = new ArrayList<>();
ConsistencyLevel consistencyLevel = ConsistencyLevel.valueOf(consistencyLevelOrigin.name());
for (Object boundValue : boundValues) boundBBValues.add(ByteBufferUtil.objectToBytes(boundValue));
prepared.validate(QueryState.forInternalCalls().getClientState());
// Start capturing warnings on this thread. Note that this will implicitly clear out any previous
// warnings as it sets a new State instance on the ThreadLocal.
ClientWarn.instance.captureWarnings();
CoordinatorWarnings.init();
try {
ResultMessage res = prepared.execute(QueryState.forInternalCalls(), QueryOptions.create(toCassandraCL(consistencyLevel), boundBBValues, false, Integer.MAX_VALUE, null, null, ProtocolVersion.CURRENT, null), nanoTime());
// Collect warnings reported during the query.
CoordinatorWarnings.done();
if (res != null)
res.setWarnings(ClientWarn.instance.getWarnings());
return RowUtil.toQueryResult(res);
} catch (Exception | Error e) {
CoordinatorWarnings.done();
throw e;
} finally {
CoordinatorWarnings.reset();
ClientWarn.instance.resetWarnings();
}
}
use of org.apache.cassandra.distributed.api.ConsistencyLevel in project cassandra by apache.
the class CountersTest method testUpdateCounter.
private static void testUpdateCounter(boolean droppedCompactStorage) throws Throwable {
try (Cluster cluster = Cluster.build(2).withConfig(c -> c.with(GOSSIP, NATIVE_PROTOCOL).set("drop_compact_storage_enabled", true)).start()) {
cluster.schemaChange("CREATE KEYSPACE k WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}");
String createTable = "CREATE TABLE k.t ( k int, c int, total counter, PRIMARY KEY (k, c))";
if (droppedCompactStorage) {
cluster.schemaChange(createTable + " WITH COMPACT STORAGE");
cluster.schemaChange("ALTER TABLE k.t DROP COMPACT STORAGE");
} else {
cluster.schemaChange(createTable);
}
ConsistencyLevel cl = ConsistencyLevel.ONE;
String select = "SELECT total FROM k.t WHERE k = 1 AND c = ?";
for (int i = 1; i <= cluster.size(); i++) {
ICoordinator coordinator = cluster.coordinator(i);
coordinator.execute("UPDATE k.t SET total = total + 1 WHERE k = 1 AND c = ?", cl, i);
assertRows(coordinator.execute(select, cl, i), row(1L));
coordinator.execute("UPDATE k.t SET total = total - 4 WHERE k = 1 AND c = ?", cl, i);
assertRows(coordinator.execute(select, cl, i), row(-3L));
}
}
}
Aggregations