use of org.apache.cassandra.distributed.api.Feature.NATIVE_PROTOCOL in project cassandra by apache.
the class ReprepareTestBase method testReprepare.
public void testReprepare(BiConsumer<ClassLoader, Integer> instanceInitializer, ReprepareTestConfiguration... configs) throws Throwable {
try (ICluster<IInvokableInstance> c = init(builder().withNodes(2).withConfig(config -> config.with(GOSSIP, NETWORK, NATIVE_PROTOCOL)).withInstanceInitializer(instanceInitializer).start())) {
ForceHostLoadBalancingPolicy lbp = new ForceHostLoadBalancingPolicy();
c.schemaChange(withKeyspace("CREATE TABLE %s.tbl (pk int, ck int, v int, PRIMARY KEY (pk, ck));"));
for (ReprepareTestConfiguration config : configs) {
// 1 has old behaviour
for (int firstContact : new int[] { 1, 2 }) {
try (com.datastax.driver.core.Cluster cluster = com.datastax.driver.core.Cluster.builder().addContactPoint("127.0.0.1").addContactPoint("127.0.0.2").withLoadBalancingPolicy(lbp).build();
Session session = cluster.connect()) {
lbp.setPrimary(firstContact);
final PreparedStatement select = session.prepare(withKeyspace("SELECT * FROM %s.tbl"));
session.execute(select.bind());
c.stream().forEach((i) -> i.runOnInstance(QueryProcessor::clearPreparedStatementsCache));
lbp.setPrimary(firstContact == 1 ? 2 : 1);
if (config.withUse)
session.execute(withKeyspace("USE %s"));
// Re-preparing on the node
if (!config.skipBrokenBehaviours && firstContact == 1)
session.execute(select.bind());
c.stream().forEach((i) -> i.runOnInstance(QueryProcessor::clearPreparedStatementsCache));
lbp.setPrimary(firstContact);
// Re-preparing on the node with old behaviour will break no matter where the statement was initially prepared
if (!config.skipBrokenBehaviours)
session.execute(select.bind());
c.stream().forEach((i) -> i.runOnInstance(QueryProcessor::clearPreparedStatementsCache));
}
}
}
}
}
use of org.apache.cassandra.distributed.api.Feature.NATIVE_PROTOCOL in project cassandra by apache.
the class NetstatsRepairStreamingTest method executeTest.
private void executeTest(boolean compressionEnabled) throws Exception {
final ExecutorService executorService = Executors.newFixedThreadPool(1);
try (final Cluster cluster = Cluster.build().withNodeIdTopology(NetworkTopology.singleDcNetworkTopology(2, "dc0", "rack0")).withConfig(config -> config.with(NETWORK, GOSSIP, NATIVE_PROTOCOL).set("stream_throughput_outbound", "122KiB/s").set("compaction_throughput", "1MiB/s").set("stream_entire_sstables", false)).start()) {
final IInvokableInstance node1 = cluster.get(1);
final IInvokableInstance node2 = cluster.get(2);
createTable(cluster, 1, compressionEnabled);
node1.nodetoolResult("disableautocompaction", "netstats_test").asserts().success();
node2.nodetoolResult("disableautocompaction", "netstats_test").asserts().success();
populateData(compressionEnabled);
node1.flush("netstats_test");
node2.flush("netstats_test");
// change RF from 1 to 2 so we need to repair it, repairing will causes streaming shown in netstats
changeReplicationFactor();
final Future<NetstatResults> resultsFuture1 = executorService.submit(new NetstatsCallable(node1));
node1.nodetoolResult("repair", "netstats_test").asserts().success();
final NetstatResults results = resultsFuture1.get(1, MINUTES);
results.assertSuccessful();
NetstatsOutputParser.validate(NetstatsOutputParser.parse(results));
}
}
use of org.apache.cassandra.distributed.api.Feature.NATIVE_PROTOCOL in project cassandra by apache.
the class PrepareBatchStatementsTest method testPreparedBatch.
@Test
public void testPreparedBatch() throws Exception {
try (ICluster<IInvokableInstance> c = init(builder().withNodes(1).withConfig(config -> config.with(GOSSIP, NETWORK, NATIVE_PROTOCOL)).start())) {
try (com.datastax.driver.core.Cluster cluster = com.datastax.driver.core.Cluster.builder().addContactPoint("127.0.0.1").build();
Session s = cluster.connect()) {
c.schemaChange(withKeyspace("CREATE KEYSPACE ks1 WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};"));
c.schemaChange(withKeyspace("CREATE TABLE ks1.tbl (pk int, ck int, v int, PRIMARY KEY (pk, ck));"));
c.schemaChange(withKeyspace("CREATE KEYSPACE ks2 WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};"));
c.schemaChange(withKeyspace("CREATE TABLE ks2.tbl (pk int, ck int, v int, PRIMARY KEY (pk, ck));"));
String batch1 = "BEGIN BATCH\n" + "UPDATE ks1.tbl SET v = ? where pk = ? and ck = ?;\n" + "UPDATE ks2.tbl SET v = ? where pk = ? and ck = ?;\n" + "APPLY BATCH;";
String batch2 = "BEGIN BATCH\n" + "INSERT INTO ks1.tbl (pk, ck, v) VALUES (?, ?, ?);\n" + "INSERT INTO tbl (pk, ck, v) VALUES (?, ?, ?);\n" + "APPLY BATCH;";
PreparedStatement prepared;
prepared = s.prepare(batch1);
s.execute(prepared.bind(1, 1, 1, 1, 1, 1));
c.get(1).runOnInstance(() -> {
// no USE here, only a fully qualified batch - should get stored ONCE
List<String> stmts = StorageService.instance.getPreparedStatements().stream().map(p -> p.right).collect(Collectors.toList());
assertEquals(Lists.newArrayList(batch1), stmts);
QueryProcessor.clearPreparedStatements(false);
});
s.execute("use ks2");
prepared = s.prepare(batch1);
s.execute(prepared.bind(1, 1, 1, 1, 1, 1));
c.get(1).runOnInstance(() -> {
// after USE, fully qualified - should get stored twice! Once with null keyspace (new behaviour) once with ks2 keyspace (old behaviour)
List<String> stmts = StorageService.instance.getPreparedStatements().stream().map(p -> p.right).collect(Collectors.toList());
assertEquals(Lists.newArrayList(batch1, batch1), stmts);
QueryProcessor.clearPreparedStatements(false);
});
prepared = s.prepare(batch2);
s.execute(prepared.bind(1, 1, 1, 1, 1, 1));
c.get(1).runOnInstance(() -> {
// after USE, should get stored twice, once with keyspace, once without
List<String> stmts = StorageService.instance.getPreparedStatements().stream().map(p -> p.right).collect(Collectors.toList());
assertEquals(Lists.newArrayList(batch2, batch2), stmts);
QueryProcessor.clearPreparedStatements(false);
});
}
}
}
use of org.apache.cassandra.distributed.api.Feature.NATIVE_PROTOCOL 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