use of org.apache.cassandra.distributed.Cluster in project cassandra by apache.
the class CASTest method testIncompleteWriteFollowedBySuccessfulWriteWithStaleRingDuringRangeMovementFollowedByWrite.
/**
* During a range movement, a CAS may fail leaving side effects that are not witnessed by another operation
* being performed with stale ring information.
* This is a particular special case of stale ring information sequencing, which probably would be resolved
* by fixing each of the more isolated cases (but is unique, so deserving of its own test case).
* See CASSANDRA-15745
*
* - Range moves from {1, 2, 3} to {2, 3, 4}; witnessed by X (not by !X)
* - X: Prepare to {2, 3, 4}
* - X: Propose to {4}
* - !X: Prepare and Propose to {1, 2}
* - Range move visible by !X
* - Any: Prepare and Propose to {3, 4}
*/
@Ignore
@Test
public void testIncompleteWriteFollowedBySuccessfulWriteWithStaleRingDuringRangeMovementFollowedByWrite() throws Throwable {
try (Cluster cluster = Cluster.create(4, config -> config.set("write_request_timeout", REQUEST_TIMEOUT).set("cas_contention_timeout", CONTENTION_TIMEOUT))) {
cluster.schemaChange("CREATE KEYSPACE " + KEYSPACE + " WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 3};");
cluster.schemaChange("CREATE TABLE " + KEYSPACE + ".tbl (pk int, ck int, v1 int, v2 int, PRIMARY KEY (pk, ck))");
// make it so {4} is bootstrapping, and this has not propagated to other nodes yet
for (int i = 1; i <= 4; ++i) cluster.get(1).acceptsOnInstance(UnsafeGossipHelper::removeFromRing).accept(cluster.get(4));
cluster.get(4).acceptsOnInstance(UnsafeGossipHelper::addToRingBootstrapping).accept(cluster.get(4));
int pk = pk(cluster, 1, 2);
// {4} promises and accepts on !{1} => {2, 3, 4}; commits on !{1, 2, 3} => {4}
cluster.filters().verbs(PAXOS_PREPARE_REQ.id, READ_REQ.id).from(4).to(1).drop();
cluster.filters().verbs(PAXOS_PROPOSE_REQ.id).from(4).to(1, 2, 3).drop();
try {
cluster.coordinator(4).execute("INSERT INTO " + KEYSPACE + ".tbl (pk, ck, v1) VALUES (?, 1, 1) IF NOT EXISTS", ConsistencyLevel.QUORUM, pk);
Assert.assertTrue(false);
} catch (RuntimeException wrapped) {
Assert.assertEquals("Operation timed out - received only 1 responses.", wrapped.getCause().getMessage());
}
// {1} promises and accepts on !{3} => {1, 2}; commits on !{2, 3} => {1}
cluster.filters().verbs(PAXOS_PREPARE_REQ.id, READ_REQ.id).from(1).to(3).drop();
cluster.filters().verbs(PAXOS_PROPOSE_REQ.id).from(1).to(3).drop();
cluster.filters().verbs(PAXOS_COMMIT_REQ.id).from(1).to(2, 3).drop();
assertRows(cluster.coordinator(1).execute("INSERT INTO " + KEYSPACE + ".tbl (pk, ck, v2) VALUES (?, 1, 2) IF NOT EXISTS", ConsistencyLevel.ONE, pk), row(true));
// finish topology change
for (int i = 1; i <= 4; ++i) cluster.get(i).acceptsOnInstance(UnsafeGossipHelper::addToRingNormal).accept(cluster.get(4));
// {3} reads from !{2} => {3, 4}
cluster.filters().verbs(PAXOS_PREPARE_REQ.id, READ_REQ.id).from(3).to(2).drop();
cluster.filters().verbs(PAXOS_PROPOSE_REQ.id).from(3).to(2).drop();
assertRows(cluster.coordinator(3).execute("INSERT INTO " + KEYSPACE + ".tbl (pk, ck, v2) VALUES (?, 1, 2) IF NOT EXISTS", ConsistencyLevel.ONE, pk), row(false, 5, 1, null, 2));
}
}
use of org.apache.cassandra.distributed.Cluster in project cassandra by apache.
the class ClearSnapshotTest method testSeqClearsSnapshot.
@Test
public void testSeqClearsSnapshot() throws IOException, TimeoutException {
try (Cluster cluster = init(Cluster.build(3).withConfig(config -> config.with(GOSSIP).with(NETWORK)).withInstanceInitializer(BB::install).start())) {
cluster.schemaChange(withKeyspace("create table %s.tbl (id int primary key, x int)"));
for (int i = 0; i < 10; i++) cluster.get(1).executeInternal(withKeyspace("insert into %s.tbl (id, x) values (?, ?)"), i, i);
cluster.get(1).nodetoolResult("repair", "-seq", "-full", KEYSPACE).asserts().success();
cluster.get(1).logs().watchFor("Clearing snapshot");
}
}
use of org.apache.cassandra.distributed.Cluster in project cassandra by apache.
the class ClearSnapshotTest method clearSnapshotSlowTest.
@Test
public void clearSnapshotSlowTest() throws IOException, InterruptedException, ExecutionException {
try (Cluster cluster = init(Cluster.build(3).withConfig(config -> config.with(GOSSIP).with(NETWORK)).withInstanceInitializer(BB::install).start())) {
int tableCount = 50;
for (int i = 0; i < tableCount; i++) {
String ksname = "ks" + i;
cluster.schemaChange("create keyspace " + ksname + " with replication = {'class': 'SimpleStrategy', 'replication_factor': 3}");
cluster.schemaChange("create table " + ksname + ".tbl (id int primary key, t int)");
cluster.get(1).executeInternal("insert into " + ksname + ".tbl (id , t) values (?, ?)", i, i);
cluster.forEach((node) -> node.flush(ksname));
}
List<Thread> repairThreads = new ArrayList<>();
for (int i = 0; i < tableCount; i++) {
String ksname = "ks" + i;
Thread t = new Thread(() -> cluster.get(1).nodetoolResult("repair", "-full", ksname).asserts().success());
t.start();
repairThreads.add(t);
}
AtomicBoolean gotExc = new AtomicBoolean(false);
AtomicBoolean exit = new AtomicBoolean(false);
Thread reads = new Thread(() -> {
while (!exit.get()) {
try {
cluster.coordinator(1).execute("select * from ks1.tbl where id = 5", ConsistencyLevel.QUORUM);
Uninterruptibles.sleepUninterruptibly(10, TimeUnit.MILLISECONDS);
} catch (Exception e) {
if (!gotExc.get())
logger.error("Unexpected exception querying table ks1.tbl", e);
gotExc.set(true);
}
}
});
reads.start();
long activeRepairs;
do {
activeRepairs = cluster.get(1).callOnInstance(() -> ActiveRepairService.instance.parentRepairSessionCount());
Thread.sleep(50);
} while (activeRepairs < 35);
cluster.setUncaughtExceptionsFilter((t) -> t.getMessage() != null && t.getMessage().contains("Parent repair session with id"));
cluster.get(2).shutdown().get();
repairThreads.forEach(t -> {
try {
t.join();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
});
exit.set(true);
reads.join();
assertFalse(gotExc.get());
}
}
use of org.apache.cassandra.distributed.Cluster in project cassandra by apache.
the class FailingResponseDoesNotLogTest method dispatcherErrorDoesNotLock.
@Test
public void dispatcherErrorDoesNotLock() throws IOException {
System.setProperty("cassandra.custom_query_handler_class", AlwaysRejectErrorQueryHandler.class.getName());
try (Cluster cluster = Cluster.build(1).withConfig(c -> c.with(Feature.NATIVE_PROTOCOL, Feature.GOSSIP).set("client_error_reporting_exclusions", ImmutableMap.of("subnets", Collections.singletonList("127.0.0.1")))).start()) {
try (SimpleClient client = SimpleClient.builder("127.0.0.1", 9042).build().connect(false)) {
client.execute("SELECT * FROM system.peers", ConsistencyLevel.ONE);
Assert.fail("Query should have failed");
} catch (Exception e) {
// ignore; expected
}
// logs happen before client response; so grep is enough
LogAction logs = cluster.get(1).logs();
LogResult<List<String>> matches = logs.grep("address contained in client_error_reporting_exclusions");
Assertions.assertThat(matches.getResult()).hasSize(1);
matches = logs.grep("Unexpected exception during request");
Assertions.assertThat(matches.getResult()).isEmpty();
} finally {
System.clearProperty("cassandra.custom_query_handler_class");
}
}
use of org.apache.cassandra.distributed.Cluster in project cassandra by apache.
the class FrozenUDTTest method testEmptyValue.
@Test
public void testEmptyValue() throws IOException {
try (Cluster cluster = init(Cluster.build(1).start())) {
cluster.schemaChange("create type " + KEYSPACE + ".a (foo text)");
cluster.schemaChange("create table " + KEYSPACE + ".x (id int, ck frozen<a>, i int, primary key (id, ck))");
cluster.coordinator(1).execute("insert into " + KEYSPACE + ".x (id, ck, i) VALUES (1, system.fromjson('{\"foo\":\"\"}'), 1)", ConsistencyLevel.ALL);
cluster.coordinator(1).execute("insert into " + KEYSPACE + ".x (id, ck, i) VALUES (1, system.fromjson('{\"foo\":\"a\"}'), 2)", ConsistencyLevel.ALL);
cluster.forEach(i -> i.flush(KEYSPACE));
Runnable check = () -> {
assertRows(cluster.coordinator(1).execute("select i from " + KEYSPACE + ".x WHERE id = 1 and ck = system.fromjson('{\"foo\":\"\"}')", ConsistencyLevel.ALL), row(1));
assertRows(cluster.coordinator(1).execute("select i from " + KEYSPACE + ".x WHERE id = 1 and ck = system.fromjson('{\"foo\":\"a\"}')", ConsistencyLevel.ALL), row(2));
};
check.run();
cluster.schemaChange("alter type " + KEYSPACE + ".a add bar text");
check.run();
assertRows(cluster.coordinator(1).execute("select i from " + KEYSPACE + ".x WHERE id = 1 and ck = system.fromjson('{\"foo\":\"\",\"bar\":\"\"}')", ConsistencyLevel.ALL));
cluster.coordinator(1).execute("insert into " + KEYSPACE + ".x (id, ck, i) VALUES (1, system.fromjson('{\"foo\":\"\",\"bar\":\"\"}'), 3)", ConsistencyLevel.ALL);
check.run();
assertRows(cluster.coordinator(1).execute("select i from " + KEYSPACE + ".x WHERE id = 1 and ck = system.fromjson('{\"foo\":\"\",\"bar\":\"\"}')", ConsistencyLevel.ALL), row(3));
}
}
Aggregations