Search in sources :

Example 31 with Cluster

use of org.apache.cassandra.distributed.Cluster in project cassandra by apache.

the class RepairOperationalTest method hostFilterDifferentDC.

@Test
public void hostFilterDifferentDC() throws IOException {
    try (Cluster cluster = Cluster.build().withRacks(2, 1, 2).start()) {
        // 1-2 : datacenter1
        // 3-4 : datacenter2
        cluster.schemaChange("CREATE KEYSPACE " + KEYSPACE + " WITH replication = {'class': 'NetworkTopologyStrategy', 'datacenter1':2, 'datacenter2':0}");
        cluster.schemaChange("CREATE TABLE " + KEYSPACE + ".tbl (id int PRIMARY KEY, i int)");
        for (int i = 0; i < 10; i++) cluster.coordinator(1).execute("INSERT INTO " + KEYSPACE + ".tbl (id, i) VALUES (?, ?)", ConsistencyLevel.ALL, i, i);
        cluster.forEach(i -> i.flush(KEYSPACE));
        // choose a node in the DC that doesn't have any replicas
        IInvokableInstance node = cluster.get(3);
        Assertions.assertThat(node.config().localDatacenter()).isEqualTo("datacenter2");
        // fails with "Specified hosts [127.0.0.3, 127.0.0.1] do not share range (0,1000] needed for repair. Either restrict repair ranges with -st/-et options, or specify one of the neighbors that share this range with this node: [].. Check the logs on the repair participants for further details"
        node.nodetoolResult("repair", "-full", "-hosts", cluster.get(1).broadcastAddress().getAddress().getHostAddress(), "-hosts", node.broadcastAddress().getAddress().getHostAddress(), "--ignore-unreplicated-keyspaces", "-st", "0", "-et", "1000", KEYSPACE, "tbl").asserts().success();
    }
}
Also used : IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) Cluster(org.apache.cassandra.distributed.Cluster) Test(org.junit.Test)

Example 32 with Cluster

use of org.apache.cassandra.distributed.Cluster in project cassandra by apache.

the class RepairOperationalTest method dcFilterOnEmptyDC.

@Test
public void dcFilterOnEmptyDC() throws IOException {
    try (Cluster cluster = Cluster.build().withRacks(2, 1, 2).start()) {
        // 1-2 : datacenter1
        // 3-4 : datacenter2
        cluster.schemaChange("CREATE KEYSPACE " + KEYSPACE + " WITH replication = {'class': 'NetworkTopologyStrategy', 'datacenter1':2, 'datacenter2':0}");
        cluster.schemaChange("CREATE TABLE " + KEYSPACE + ".tbl (id int PRIMARY KEY, i int)");
        for (int i = 0; i < 10; i++) cluster.coordinator(1).execute("INSERT INTO " + KEYSPACE + ".tbl (id, i) VALUES (?, ?)", ConsistencyLevel.ALL, i, i);
        cluster.forEach(i -> i.flush(KEYSPACE));
        // choose a node in the DC that doesn't have any replicas
        IInvokableInstance node = cluster.get(3);
        Assertions.assertThat(node.config().localDatacenter()).isEqualTo("datacenter2");
        // fails with "the local data center must be part of the repair"
        node.nodetoolResult("repair", "-full", "-dc", "datacenter1", "-dc", "datacenter2", "--ignore-unreplicated-keyspaces", "-st", "0", "-et", "1000", KEYSPACE, "tbl").asserts().success();
    }
}
Also used : IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) Cluster(org.apache.cassandra.distributed.Cluster) Test(org.junit.Test)

Example 33 with Cluster

use of org.apache.cassandra.distributed.Cluster in project cassandra by apache.

the class HostReplacementTest method seedGoesDownBeforeDownHost.

/**
 * If the seed goes down, then another node, once the seed comes back, make sure host replacements still work.
 */
@Test
public void seedGoesDownBeforeDownHost() throws IOException {
    // start with 3 nodes, stop both nodes, start the seed, host replace the down node)
    TokenSupplier even = TokenSupplier.evenlyDistributedTokens(3);
    try (Cluster cluster = Cluster.build(3).withConfig(c -> c.with(Feature.GOSSIP, Feature.NETWORK)).withTokenSupplier(node -> even.token(node == 4 ? 2 : node)).start()) {
        // call early as this can't be touched on a down node
        IInvokableInstance seed = cluster.get(1);
        IInvokableInstance nodeToRemove = cluster.get(2);
        IInvokableInstance nodeToStayAlive = cluster.get(3);
        setupCluster(cluster);
        // collect rows/tokens to detect issues later on if the state doesn't match
        SimpleQueryResult expectedState = nodeToRemove.coordinator().executeWithResult("SELECT * FROM " + KEYSPACE + ".tbl", ConsistencyLevel.ALL);
        List<String> beforeCrashTokens = getTokenMetadataTokens(seed);
        // shutdown the seed, then the node to remove
        stopUnchecked(seed);
        stopUnchecked(nodeToRemove);
        // restart the seed
        seed.startup();
        // make sure the node to remove is still in the ring
        assertInRing(seed, nodeToRemove);
        // make sure node1 still has node2's tokens
        List<String> currentTokens = getTokenMetadataTokens(seed);
        Assertions.assertThat(currentTokens).as("Tokens no longer match after restarting").isEqualTo(beforeCrashTokens);
        // now create a new node to replace the other node
        IInvokableInstance replacingNode = replaceHostAndStart(cluster, nodeToRemove);
        List<IInvokableInstance> expectedRing = Arrays.asList(seed, replacingNode, nodeToStayAlive);
        // wait till the replacing node is in the ring
        awaitRingJoin(seed, replacingNode);
        awaitRingJoin(replacingNode, seed);
        awaitRingJoin(nodeToStayAlive, replacingNode);
        // make sure all nodes are healthy
        logger.info("Current ring is {}", awaitRingHealthy(seed));
        expectedRing.forEach(i -> assertRingIs(i, expectedRing));
        validateRows(seed.coordinator(), expectedState);
        validateRows(replacingNode.coordinator(), expectedState);
    }
}
Also used : Arrays(java.util.Arrays) ClusterUtils.getTokenMetadataTokens(org.apache.cassandra.distributed.shared.ClusterUtils.getTokenMetadataTokens) LoggerFactory(org.slf4j.LoggerFactory) ClusterUtils.stopUnchecked(org.apache.cassandra.distributed.shared.ClusterUtils.stopUnchecked) BOOTSTRAP_SKIP_SCHEMA_CHECK(org.apache.cassandra.config.CassandraRelevantProperties.BOOTSTRAP_SKIP_SCHEMA_CHECK) TokenSupplier(org.apache.cassandra.distributed.api.TokenSupplier) ClusterUtils.replaceHostAndStart(org.apache.cassandra.distributed.shared.ClusterUtils.replaceHostAndStart) ICoordinator(org.apache.cassandra.distributed.api.ICoordinator) ClusterUtils.assertInRing(org.apache.cassandra.distributed.shared.ClusterUtils.assertInRing) TestBaseImpl(org.apache.cassandra.distributed.test.TestBaseImpl) SimpleQueryResult(org.apache.cassandra.distributed.api.SimpleQueryResult) Assertions(org.assertj.core.api.Assertions) Constants(org.apache.cassandra.distributed.Constants) AssertUtils(org.apache.cassandra.distributed.shared.AssertUtils) Feature(org.apache.cassandra.distributed.api.Feature) Logger(org.slf4j.Logger) GOSSIPER_QUARANTINE_DELAY(org.apache.cassandra.config.CassandraRelevantProperties.GOSSIPER_QUARANTINE_DELAY) ClusterUtils.awaitRingJoin(org.apache.cassandra.distributed.shared.ClusterUtils.awaitRingJoin) IOException(java.io.IOException) Test(org.junit.Test) ConsistencyLevel(org.apache.cassandra.distributed.api.ConsistencyLevel) List(java.util.List) IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) Cluster(org.apache.cassandra.distributed.Cluster) ClusterUtils.assertRingIs(org.apache.cassandra.distributed.shared.ClusterUtils.assertRingIs) ClusterUtils.awaitRingHealthy(org.apache.cassandra.distributed.shared.ClusterUtils.awaitRingHealthy) IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) SimpleQueryResult(org.apache.cassandra.distributed.api.SimpleQueryResult) TokenSupplier(org.apache.cassandra.distributed.api.TokenSupplier) Cluster(org.apache.cassandra.distributed.Cluster) Test(org.junit.Test)

Example 34 with Cluster

use of org.apache.cassandra.distributed.Cluster in project cassandra by apache.

the class TableMetricTest method systemTables.

/**
 * Makes sure that all system tables have the expected metrics
 * @throws IOException
 */
@Test
public void systemTables() throws IOException {
    try (Cluster cluster = Cluster.build(1).start()) {
        loadSystemTables(cluster);
        assertSystemTableMetrics(cluster);
    }
}
Also used : Cluster(org.apache.cassandra.distributed.Cluster) Test(org.junit.Test)

Example 35 with Cluster

use of org.apache.cassandra.distributed.Cluster in project cassandra by apache.

the class StreamingMetricsTest method testMetricsWithStreamingFromTwoNodes.

public void testMetricsWithStreamingFromTwoNodes(boolean useRepair) throws Exception {
    try (Cluster cluster = init(Cluster.build(3).withDataDirCount(1).withConfig(config -> config.with(NETWORK).set("stream_entire_sstables", false).set("hinted_handoff_enabled", false)).start(), 2)) {
        cluster.schemaChange(String.format("CREATE TABLE %s.cf (k text, c1 text, c2 text, PRIMARY KEY (k)) WITH compaction = {'class': '%s', 'enabled': 'false'}", KEYSPACE, "LeveledCompactionStrategy"));
        IMessageFilters.Filter drop1to3 = cluster.filters().verbs(MUTATION_REQ.id).from(1).to(3).drop();
        final int rowsPerFile = 500;
        final int files = 5;
        for (int k = 0; k < files; k++) {
            for (int i = k * rowsPerFile; i < k * rowsPerFile + rowsPerFile; ++i) {
                cluster.coordinator(1).execute(withKeyspace("INSERT INTO %s.cf (k, c1, c2) VALUES (?, 'value1', 'value2');"), ConsistencyLevel.ONE, Integer.toString(i));
            }
            cluster.get(1).flush(KEYSPACE);
            cluster.get(2).flush(KEYSPACE);
        }
        drop1to3.off();
        // Checks that the table is empty on node 3
        Object[][] results = cluster.get(3).executeInternal(withKeyspace("SELECT k, c1, c2 FROM %s.cf;"));
        assertThat(results.length).isEqualTo(0);
        checkThatNoStreamingOccuredBetweenTheThreeNodes(cluster);
        // Trigger streaming from node 3
        if (useRepair)
            cluster.get(3).nodetool("repair", "--full");
        else
            cluster.get(3).nodetool("rebuild", "--keyspace", KEYSPACE);
        // Check streaming metrics on node 1
        checkThatNoStreamingOccured(cluster, 1, 2);
        long bytesFrom1 = checkDataSent(cluster, 1, 3);
        checkDataReceived(cluster, 1, 3, 0, 0);
        if (useRepair)
            checkTotalDataSent(cluster, 1, bytesFrom1, bytesFrom1, files);
        else
            checkTotalDataSent(cluster, 1, bytesFrom1, 0, 0);
        checkTotalDataReceived(cluster, 1, 0);
        // Check streaming metrics on node 2
        checkThatNoStreamingOccured(cluster, 2, 1);
        long bytesFrom2 = checkDataSent(cluster, 2, 3);
        checkDataReceived(cluster, 1, 2, 0, 0);
        if (useRepair)
            checkTotalDataSent(cluster, 2, bytesFrom2, bytesFrom2, files);
        else
            checkTotalDataSent(cluster, 2, bytesFrom2, 0, 0);
        checkTotalDataReceived(cluster, 2, 0);
        // Check streaming metrics on node 3
        checkDataReceived(cluster, 3, 1, bytesFrom1, files);
        checkDataReceived(cluster, 3, 2, bytesFrom2, files);
        checkTotalDataSent(cluster, 3, 0, 0, 0);
        checkTotalDataReceived(cluster, 3, bytesFrom1 + bytesFrom2);
    }
}
Also used : IMessageFilters(org.apache.cassandra.distributed.api.IMessageFilters) Cluster(org.apache.cassandra.distributed.Cluster)

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