Search in sources :

Example 86 with Cluster

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");
    }
}
Also used : Cluster(org.apache.cassandra.distributed.Cluster) NodeToolResult(org.apache.cassandra.distributed.api.NodeToolResult) Test(org.junit.Test)

Example 87 with Cluster

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));
    }
}
Also used : Uninterruptibles(com.google.common.util.concurrent.Uninterruptibles) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) Global.currentTimeMillis(org.apache.cassandra.utils.Clock.Global.currentTimeMillis) TimeoutException(java.util.concurrent.TimeoutException) StorageService(org.apache.cassandra.service.StorageService) IOException(java.io.IOException) Test(org.junit.Test) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) StorageProxy(org.apache.cassandra.service.StorageProxy) Cluster(org.apache.cassandra.distributed.Cluster) Assert(org.junit.Assert) NETWORK(org.apache.cassandra.distributed.api.Feature.NETWORK) GOSSIP(org.apache.cassandra.distributed.api.Feature.GOSSIP) Cluster(org.apache.cassandra.distributed.Cluster) Test(org.junit.Test)

Example 88 with Cluster

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());
    }
}
Also used : CompactionManager(org.apache.cassandra.db.compaction.CompactionManager) MethodDelegation(net.bytebuddy.implementation.MethodDelegation) ElementMatchers.named(net.bytebuddy.matcher.ElementMatchers.named) Collection(java.util.Collection) ByteBuddy(net.bytebuddy.ByteBuddy) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) UUID(java.util.UUID) ConsistencyLevel(org.apache.cassandra.distributed.api.ConsistencyLevel) ClassLoadingStrategy(net.bytebuddy.dynamic.loading.ClassLoadingStrategy) CompactionInterruptedException(org.apache.cassandra.db.compaction.CompactionInterruptedException) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) RangesAtEndpoint(org.apache.cassandra.locator.RangesAtEndpoint) UnfilteredRowIterator(org.apache.cassandra.db.rows.UnfilteredRowIterator) CompactionIterator(org.apache.cassandra.db.compaction.CompactionIterator) Assertions(org.assertj.core.api.Assertions) Cluster(org.apache.cassandra.distributed.Cluster) NETWORK(org.apache.cassandra.distributed.api.Feature.NETWORK) GOSSIP(org.apache.cassandra.distributed.api.Feature.GOSSIP) Cluster(org.apache.cassandra.distributed.Cluster) RangesAtEndpoint(org.apache.cassandra.locator.RangesAtEndpoint) Test(org.junit.Test)

Example 89 with Cluster

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);
    }
}
Also used : Condition.newOneTimeCondition(org.apache.cassandra.utils.concurrent.Condition.newOneTimeCondition) Condition(org.apache.cassandra.utils.concurrent.Condition) Cluster(org.apache.cassandra.distributed.Cluster) RepairResult(org.apache.cassandra.distributed.shared.RepairResult) Test(org.junit.Test)

Example 90 with Cluster

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());
    }
}
Also used : InetAddress(java.net.InetAddress) Feature(org.apache.cassandra.distributed.api.Feature) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test) Cluster(org.apache.cassandra.distributed.Cluster) Assert(org.junit.Assert) Collections(java.util.Collections) Cluster(org.apache.cassandra.distributed.Cluster) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Aggregations

Cluster (org.apache.cassandra.distributed.Cluster)161 Test (org.junit.Test)151 IInvokableInstance (org.apache.cassandra.distributed.api.IInvokableInstance)37 Assert (org.junit.Assert)37 IOException (java.io.IOException)36 Feature (org.apache.cassandra.distributed.api.Feature)34 GOSSIP (org.apache.cassandra.distributed.api.Feature.GOSSIP)30 NETWORK (org.apache.cassandra.distributed.api.Feature.NETWORK)30 ConsistencyLevel (org.apache.cassandra.distributed.api.ConsistencyLevel)29 List (java.util.List)22 ImmutableMap (com.google.common.collect.ImmutableMap)21 InetAddress (java.net.InetAddress)20 TokenSupplier (org.apache.cassandra.distributed.api.TokenSupplier)20 StorageService (org.apache.cassandra.service.StorageService)18 Arrays (java.util.Arrays)17 Collections (java.util.Collections)17 Assertions (org.assertj.core.api.Assertions)17 Map (java.util.Map)16 TestBaseImpl (org.apache.cassandra.distributed.test.TestBaseImpl)15 ICoordinator (org.apache.cassandra.distributed.api.ICoordinator)14