use of org.apache.cassandra.distributed.Cluster in project cassandra by apache.
the class OptimiseStreamsRepairTest method testBasic.
@Test
public void testBasic() throws Exception {
try (Cluster cluster = init(Cluster.build(3).withInstanceInitializer(BBHelper::install).withConfig(config -> config.set("hinted_handoff_enabled", false).with(GOSSIP).with(NETWORK)).start())) {
cluster.schemaChange("create table " + KEYSPACE + ".tbl (id int primary key, t int) with compaction={'class': 'SizeTieredCompactionStrategy'}");
for (int i = 0; i < 10000; i++) cluster.coordinator(1).execute("INSERT INTO " + KEYSPACE + ".tbl (id, t) values (?,?)", ConsistencyLevel.ALL, i, i);
cluster.forEach((i) -> i.flush(KEYSPACE));
cluster.get(2).shutdown().get();
for (int i = 0; i < 2000; i++) cluster.coordinator(1).execute("INSERT INTO " + KEYSPACE + ".tbl (id, t) values (?,?)", ConsistencyLevel.QUORUM, i, i * 2 + 2);
cluster.get(2).startup();
Thread.sleep(1000);
cluster.forEach(c -> c.flush(KEYSPACE));
cluster.forEach(c -> c.forceCompact(KEYSPACE, "tbl"));
long[] marks = PreviewRepairTest.logMark(cluster);
NodeToolResult res = cluster.get(1).nodetoolResult("repair", KEYSPACE, "-os");
res.asserts().success();
PreviewRepairTest.waitLogsRepairFullyFinished(cluster, marks);
res = cluster.get(1).nodetoolResult("repair", KEYSPACE, "-vd");
res.asserts().success();
res.asserts().notificationContains("Repaired data is in sync");
res = cluster.get(1).nodetoolResult("repair", KEYSPACE, "--preview", "--full");
res.asserts().success();
res.asserts().notificationContains("Previewed data was in sync");
}
}
use of org.apache.cassandra.distributed.Cluster in project cassandra by apache.
the class PartitionDenylistTest method checkStartupWithoutTriggeringUnavailable.
// Create a four node cluster, populate with some denylist entries, stop all
// the nodes, then bring them up one by one, waiting for each node to complete
// startup before starting the next.
//
// On startup each node runs a SELECT * query on the partition denylist table
// to populate the cache. The whole keyspace is unlikely to be available until
// three of the four nodes are started, so the early nodes will go through several
// cycles of failing to retrieve the partition denylist before succeeding.
//
// with({NETWORK,GOSSIP} is currently required for in-JVM dtests to create
// the distributed system tables.
@Test
public void checkStartupWithoutTriggeringUnavailable() throws IOException, InterruptedException, ExecutionException, TimeoutException {
int nodeCount = 4;
// down from 30s default
System.setProperty("cassandra.ring_delay_ms", "5000");
System.setProperty("cassandra.consistent.rangemovement", "false");
System.setProperty("cassandra.consistent.simultaneousmoves.allow", "true");
try (Cluster cluster = Cluster.build(nodeCount).withConfig(config -> config.with(NETWORK).with(GOSSIP).set("partition_denylist_enabled", true).set("denylist_initial_load_retry", "1s")).createWithoutStarting()) {
cluster.forEach(i -> {
i.startup();
i.runOnInstance(PartitionDenylistTest::waitUntilStarted);
});
// Do a cluster-wide no unavailables were recorded while the denylist was loaded.
cluster.forEach(i -> i.runOnInstance(PartitionDenylistTest::checkNoUnavailables));
}
}
use of org.apache.cassandra.distributed.Cluster in project cassandra by apache.
the class RepairErrorsTest method testNoSuchRepairSessionAnticompaction.
@Test
public void testNoSuchRepairSessionAnticompaction() throws IOException {
try (Cluster cluster = init(Cluster.build(2).withConfig(config -> config.with(GOSSIP).with(NETWORK)).withInstanceInitializer(ByteBuddyHelper::installACNoSuchRepairSession).start())) {
cluster.schemaChange("create table " + KEYSPACE + ".tbl (id int primary key, x int)");
for (int i = 0; i < 10; i++) cluster.coordinator(1).execute("insert into " + KEYSPACE + ".tbl (id, x) VALUES (?,?)", ConsistencyLevel.ALL, i, i);
cluster.forEach(i -> i.flush(KEYSPACE));
long mark = cluster.get(1).logs().mark();
cluster.forEach(i -> i.nodetoolResult("repair", KEYSPACE).asserts().failure());
assertTrue(cluster.get(1).logs().grep(mark, "^ERROR").getResult().isEmpty());
}
}
use of org.apache.cassandra.distributed.Cluster in project cassandra by apache.
the class PreviewRepairTest method testConcurrentIncRepairDuringPreview.
/**
* Tests that a IR is running, but not completed before validation compaction starts
*/
@Test
public void testConcurrentIncRepairDuringPreview() throws IOException, InterruptedException, ExecutionException {
try (Cluster cluster = init(Cluster.build(2).withConfig(config -> config.with(GOSSIP).with(NETWORK)).start())) {
cluster.schemaChange("create table " + KEYSPACE + ".tbl (id int primary key, t int)");
insert(cluster.coordinator(1), 0, 100);
cluster.forEach((node) -> node.flush(KEYSPACE));
cluster.get(1).callOnInstance(repair(options(false, false)));
insert(cluster.coordinator(1), 100, 100);
cluster.forEach((node) -> node.flush(KEYSPACE));
Condition previewRepairStarted = newOneTimeCondition();
Condition continuePreviewRepair = newOneTimeCondition();
// this pauses the validation request sent from node1 to node2 until the inc repair below has run
cluster.filters().outbound().verbs(VALIDATION_REQ.id).from(1).to(2).messagesMatching(validationRequest(previewRepairStarted, continuePreviewRepair)).drop();
Condition irRepairStarted = newOneTimeCondition();
Condition continueIrRepair = newOneTimeCondition();
// this blocks the IR from committing, so we can reenable the preview
cluster.filters().outbound().verbs(FINALIZE_PROPOSE_MSG.id).from(1).to(2).messagesMatching(finalizePropose(irRepairStarted, continueIrRepair)).drop();
Future<RepairResult> previewResult = cluster.get(1).asyncCallsOnInstance(repair(options(true, false))).call();
previewRepairStarted.await();
// trigger IR and wait till its ready to commit
Future<RepairResult> irResult = cluster.get(1).asyncCallsOnInstance(repair(options(false, false))).call();
irRepairStarted.await();
// unblock preview repair and wait for it to complete
continuePreviewRepair.signalAll();
RepairResult rs = previewResult.get();
// preview repair should have failed
assertFalse(rs.success);
// and no mismatches should have been reported
assertFalse(rs.wasInconsistent);
continueIrRepair.signalAll();
RepairResult ir = irResult.get();
assertTrue(ir.success);
// not preview, so we don't care about preview notification
assertFalse(ir.wasInconsistent);
}
}
use of org.apache.cassandra.distributed.Cluster in project cassandra by apache.
the class InternodeEncryptionOptionsTest method optionalTlsConnectionDisabledWithoutKeystoreTest.
@Test
public void optionalTlsConnectionDisabledWithoutKeystoreTest() throws Throwable {
try (Cluster cluster = builder().withNodes(1).withConfig(c -> c.with(Feature.NETWORK)).createWithoutStarting()) {
InetAddress address = cluster.get(1).config().broadcastAddress().getAddress();
int port = cluster.get(1).config().broadcastAddress().getPort();
TlsConnection tlsConnection = new TlsConnection(address.getHostAddress(), port);
tlsConnection.assertCannotConnect();
cluster.startup();
Assert.assertEquals("TLS connection should not be possible without keystore", ConnectResult.FAILED_TO_NEGOTIATE, tlsConnection.connect());
}
}
Aggregations