Search in sources :

Example 6 with IInvokableInstance

use of org.apache.cassandra.distributed.api.IInvokableInstance in project cassandra by apache.

the class HostReplacementTest method replaceDownedHost.

/**
 * Attempt to do a host replacement on a down host
 */
@Test
public void replaceDownedHost() throws IOException {
    // start with 2 nodes, stop both nodes, start the seed, host replace the down node)
    TokenSupplier even = TokenSupplier.evenlyDistributedTokens(2);
    try (Cluster cluster = Cluster.build(2).withConfig(c -> c.with(Feature.GOSSIP, Feature.NETWORK)).withTokenSupplier(node -> even.token(node == 3 ? 2 : node)).start()) {
        IInvokableInstance seed = cluster.get(1);
        IInvokableInstance nodeToRemove = cluster.get(2);
        setupCluster(cluster);
        // collect rows to detect issues later on if the state doesn't match
        SimpleQueryResult expectedState = nodeToRemove.coordinator().executeWithResult("SELECT * FROM " + KEYSPACE + ".tbl", ConsistencyLevel.ALL);
        stopUnchecked(nodeToRemove);
        // now create a new node to replace the other node
        IInvokableInstance replacingNode = replaceHostAndStart(cluster, nodeToRemove, props -> {
            // since we have a downed host there might be a schema version which is old show up but
            // can't be fetched since the host is down...
            props.set(BOOTSTRAP_SKIP_SCHEMA_CHECK, true);
        });
        // wait till the replacing node is in the ring
        awaitRingJoin(seed, replacingNode);
        awaitRingJoin(replacingNode, seed);
        // make sure all nodes are healthy
        awaitRingHealthy(seed);
        assertRingIs(seed, seed, replacingNode);
        logger.info("Current ring is {}", assertRingIs(replacingNode, seed, replacingNode));
        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 7 with IInvokableInstance

use of org.apache.cassandra.distributed.api.IInvokableInstance in project cassandra by apache.

the class HostReplacementTest method replaceAliveHost.

/**
 * Attempt to do a host replacement on a alive host
 */
@Test
public void replaceAliveHost() throws IOException {
    // start with 2 nodes, stop both nodes, start the seed, host replace the down node)
    TokenSupplier even = TokenSupplier.evenlyDistributedTokens(2);
    try (Cluster cluster = Cluster.build(2).withConfig(c -> c.with(Feature.GOSSIP, Feature.NETWORK).set(Constants.KEY_DTEST_API_STARTUP_FAILURE_AS_SHUTDOWN, false)).withTokenSupplier(node -> even.token(node == 3 ? 2 : node)).start()) {
        IInvokableInstance seed = cluster.get(1);
        IInvokableInstance nodeToRemove = cluster.get(2);
        setupCluster(cluster);
        // collect rows to detect issues later on if the state doesn't match
        SimpleQueryResult expectedState = nodeToRemove.coordinator().executeWithResult("SELECT * FROM " + KEYSPACE + ".tbl", ConsistencyLevel.ALL);
        // now create a new node to replace the other node
        Assertions.assertThatThrownBy(() -> replaceHostAndStart(cluster, nodeToRemove)).as("Startup of instance should have failed as you can not replace a alive node").hasMessageContaining("Cannot replace a live node").isInstanceOf(UnsupportedOperationException.class);
        // make sure all nodes are healthy
        awaitRingHealthy(seed);
        assertRingIs(seed, seed, nodeToRemove);
        logger.info("Current ring is {}", assertRingIs(nodeToRemove, seed, nodeToRemove));
        validateRows(seed.coordinator(), expectedState);
        validateRows(nodeToRemove.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 8 with IInvokableInstance

use of org.apache.cassandra.distributed.api.IInvokableInstance in project cassandra by apache.

the class RepairOperationalTest method mainDC.

@Test
public void mainDC() 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(1);
        Assertions.assertThat(node.config().localDatacenter()).isEqualTo("datacenter1");
        node.nodetoolResult("repair", "-full", "--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 9 with IInvokableInstance

use of org.apache.cassandra.distributed.api.IInvokableInstance 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 10 with IInvokableInstance

use of org.apache.cassandra.distributed.api.IInvokableInstance 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)

Aggregations

IInvokableInstance (org.apache.cassandra.distributed.api.IInvokableInstance)55 Test (org.junit.Test)36 Cluster (org.apache.cassandra.distributed.Cluster)31 List (java.util.List)16 IOException (java.io.IOException)15 ConsistencyLevel (org.apache.cassandra.distributed.api.ConsistencyLevel)14 Feature (org.apache.cassandra.distributed.api.Feature)13 GOSSIP (org.apache.cassandra.distributed.api.Feature.GOSSIP)13 NETWORK (org.apache.cassandra.distributed.api.Feature.NETWORK)13 ICluster (org.apache.cassandra.distributed.api.ICluster)13 TestBaseImpl (org.apache.cassandra.distributed.test.TestBaseImpl)13 TokenSupplier (org.apache.cassandra.distributed.api.TokenSupplier)12 Session (com.datastax.driver.core.Session)11 Arrays (java.util.Arrays)11 Assertions (org.assertj.core.api.Assertions)10 Set (java.util.Set)9 NATIVE_PROTOCOL (org.apache.cassandra.distributed.api.Feature.NATIVE_PROTOCOL)9 Assert (org.junit.Assert)9 PreparedStatement (com.datastax.driver.core.PreparedStatement)8 Map (java.util.Map)8