Search in sources :

Example 21 with IInvokableInstance

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

the class BootstrapTest method readWriteDuringBootstrapTest.

@Test
public void readWriteDuringBootstrapTest() throws Throwable {
    int originalNodeCount = 2;
    int expandedNodeCount = originalNodeCount + 1;
    try (Cluster cluster = builder().withNodes(originalNodeCount).withTokenSupplier(TokenSupplier.evenlyDistributedTokens(expandedNodeCount)).withNodeIdTopology(NetworkTopology.singleDcNetworkTopology(expandedNodeCount, "dc0", "rack0")).withConfig(config -> config.with(NETWORK, GOSSIP)).start()) {
        IInstanceConfig config = cluster.newInstanceConfig();
        IInvokableInstance newInstance = cluster.bootstrap(config);
        withProperty("cassandra.join_ring", false, () -> newInstance.startup(cluster));
        cluster.forEach(statusToBootstrap(newInstance));
        populate(cluster, 0, 100);
        Assert.assertEquals(100, newInstance.executeInternal("SELECT *FROM " + KEYSPACE + ".tbl").length);
    }
}
Also used : IntStream(java.util.stream.IntStream) ICluster(org.apache.cassandra.distributed.api.ICluster) Test(org.junit.Test) ConsistencyLevel(org.apache.cassandra.distributed.api.ConsistencyLevel) Collectors(java.util.stream.Collectors) GossipHelper.bootstrap(org.apache.cassandra.distributed.action.GossipHelper.bootstrap) TokenSupplier(org.apache.cassandra.distributed.api.TokenSupplier) IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) GossipHelper.pullSchemaFrom(org.apache.cassandra.distributed.action.GossipHelper.pullSchemaFrom) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) TestBaseImpl(org.apache.cassandra.distributed.test.TestBaseImpl) Cluster(org.apache.cassandra.distributed.Cluster) GossipHelper.withProperty(org.apache.cassandra.distributed.action.GossipHelper.withProperty) Assert(org.junit.Assert) IInstanceConfig(org.apache.cassandra.distributed.api.IInstanceConfig) GossipHelper.statusToBootstrap(org.apache.cassandra.distributed.action.GossipHelper.statusToBootstrap) NetworkTopology(org.apache.cassandra.distributed.shared.NetworkTopology) NETWORK(org.apache.cassandra.distributed.api.Feature.NETWORK) GOSSIP(org.apache.cassandra.distributed.api.Feature.GOSSIP) IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) IInstanceConfig(org.apache.cassandra.distributed.api.IInstanceConfig) ICluster(org.apache.cassandra.distributed.api.ICluster) Cluster(org.apache.cassandra.distributed.Cluster) Test(org.junit.Test)

Example 22 with IInvokableInstance

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

the class BootstrapTest method bootstrapTest.

@Test
public void bootstrapTest() throws Throwable {
    int originalNodeCount = 2;
    int expandedNodeCount = originalNodeCount + 1;
    try (Cluster cluster = builder().withNodes(originalNodeCount).withTokenSupplier(TokenSupplier.evenlyDistributedTokens(expandedNodeCount)).withNodeIdTopology(NetworkTopology.singleDcNetworkTopology(expandedNodeCount, "dc0", "rack0")).withConfig(config -> config.with(NETWORK, GOSSIP)).start()) {
        populate(cluster, 0, 100);
        IInstanceConfig config = cluster.newInstanceConfig();
        IInvokableInstance newInstance = cluster.bootstrap(config);
        withProperty("cassandra.join_ring", false, () -> newInstance.startup(cluster));
        cluster.forEach(statusToBootstrap(newInstance));
        cluster.run(asList(pullSchemaFrom(cluster.get(1)), bootstrap()), newInstance.config().num());
        for (Map.Entry<Integer, Long> e : count(cluster).entrySet()) Assert.assertEquals("Node " + e.getKey() + " has incorrect row state", 100L, e.getValue().longValue());
    }
}
Also used : IntStream(java.util.stream.IntStream) ICluster(org.apache.cassandra.distributed.api.ICluster) Test(org.junit.Test) ConsistencyLevel(org.apache.cassandra.distributed.api.ConsistencyLevel) Collectors(java.util.stream.Collectors) GossipHelper.bootstrap(org.apache.cassandra.distributed.action.GossipHelper.bootstrap) TokenSupplier(org.apache.cassandra.distributed.api.TokenSupplier) IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) GossipHelper.pullSchemaFrom(org.apache.cassandra.distributed.action.GossipHelper.pullSchemaFrom) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) TestBaseImpl(org.apache.cassandra.distributed.test.TestBaseImpl) Cluster(org.apache.cassandra.distributed.Cluster) GossipHelper.withProperty(org.apache.cassandra.distributed.action.GossipHelper.withProperty) Assert(org.junit.Assert) IInstanceConfig(org.apache.cassandra.distributed.api.IInstanceConfig) GossipHelper.statusToBootstrap(org.apache.cassandra.distributed.action.GossipHelper.statusToBootstrap) NetworkTopology(org.apache.cassandra.distributed.shared.NetworkTopology) NETWORK(org.apache.cassandra.distributed.api.Feature.NETWORK) GOSSIP(org.apache.cassandra.distributed.api.Feature.GOSSIP) IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) IInstanceConfig(org.apache.cassandra.distributed.api.IInstanceConfig) ICluster(org.apache.cassandra.distributed.api.ICluster) Cluster(org.apache.cassandra.distributed.Cluster) Map(java.util.Map) Test(org.junit.Test)

Example 23 with IInvokableInstance

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

the class AssassinatedEmptyNodeTest method consume.

@Override
void consume(Cluster cluster, IInvokableInstance nodeToRemove) {
    IInvokableInstance seed = cluster.get(SEED_NUM);
    IInvokableInstance peer = cluster.get(PEER_NUM);
    InetSocketAddress addressToReplace = nodeToRemove.broadcastAddress();
    // now stop all nodes
    stopAll(cluster);
    // with all nodes down, now start the seed (should be first node)
    seed.startup();
    peer.startup();
    // at this point node2 should be known in gossip, but with generation/version of 0
    assertGossipInfo(seed, addressToReplace, 0, -1);
    assertGossipInfo(peer, addressToReplace, 0, -1);
}
Also used : IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) InetSocketAddress(java.net.InetSocketAddress)

Example 24 with IInvokableInstance

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

the class HostReplacementAbruptDownedInstanceTest method hostReplaceAbruptShutdown.

/**
 * Can we maybe also test with an abrupt shutdown, that is when the shutdown state is not broadcast and the node to be replaced is on NORMAL state?
 */
@Test
public void hostReplaceAbruptShutdown() throws IOException {
    int numStartNodes = 3;
    TokenSupplier even = TokenSupplier.evenlyDistributedTokens(numStartNodes);
    try (Cluster cluster = Cluster.build(numStartNodes).withConfig(c -> c.with(Feature.GOSSIP, Feature.NETWORK)).withTokenSupplier(node -> even.token(node == (numStartNodes + 1) ? 2 : node)).start()) {
        IInvokableInstance seed = cluster.get(1);
        IInvokableInstance nodeToRemove = cluster.get(2);
        IInvokableInstance peer = cluster.get(3);
        List<IInvokableInstance> peers = Arrays.asList(seed, peer);
        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);
        stopAbrupt(cluster, nodeToRemove);
        // at this point node 2 should still be NORMAL on all other nodes
        peers.forEach(p -> assertRingState(p, nodeToRemove, "Normal"));
        // node is down, but queries should still work
        // TODO failing, but shouldn't!
        // peers.forEach(p -> validateRows(p.coordinator(), expectedState));
        // now create a new node to replace the other node
        long startNanos = nanoTime();
        IInvokableInstance replacingNode = replaceHostAndStart(cluster, nodeToRemove, properties -> {
            // since node2 was killed abruptly its possible that node2's gossip state has an old schema version
            // if this happens then bootstrap will fail waiting for a schema version it will never see; to avoid
            // this, setting this property to log the warning rather than fail bootstrap
            properties.set(BOOTSTRAP_SKIP_SCHEMA_CHECK, true);
        });
        logger.info("Host replacement of {} with {} took {}", nodeToRemove, replacingNode, Duration.ofNanos(nanoTime() - startNanos));
        peers.forEach(p -> awaitRingJoin(p, replacingNode));
        // make sure all nodes are healthy
        awaitRingHealthy(seed);
        List<IInvokableInstance> expectedRing = Arrays.asList(seed, peer, replacingNode);
        expectedRing.forEach(p -> assertRingIs(p, expectedRing));
        expectedRing.forEach(p -> validateRows(p.coordinator(), expectedState));
    }
}
Also used : Arrays(java.util.Arrays) Feature(org.apache.cassandra.distributed.api.Feature) Logger(org.slf4j.Logger) ClusterUtils.stopAbrupt(org.apache.cassandra.distributed.shared.ClusterUtils.stopAbrupt) HostReplacementTest.setupCluster(org.apache.cassandra.distributed.test.hostreplacement.HostReplacementTest.setupCluster) LoggerFactory(org.slf4j.LoggerFactory) ClusterUtils.awaitRingJoin(org.apache.cassandra.distributed.shared.ClusterUtils.awaitRingJoin) HostReplacementTest.validateRows(org.apache.cassandra.distributed.test.hostreplacement.HostReplacementTest.validateRows) IOException(java.io.IOException) Test(org.junit.Test) ConsistencyLevel(org.apache.cassandra.distributed.api.ConsistencyLevel) Global.nanoTime(org.apache.cassandra.utils.Clock.Global.nanoTime) 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) List(java.util.List) IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) Duration(java.time.Duration) TestBaseImpl(org.apache.cassandra.distributed.test.TestBaseImpl) SimpleQueryResult(org.apache.cassandra.distributed.api.SimpleQueryResult) Cluster(org.apache.cassandra.distributed.Cluster) ClusterUtils.assertRingState(org.apache.cassandra.distributed.shared.ClusterUtils.assertRingState) 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) HostReplacementTest.setupCluster(org.apache.cassandra.distributed.test.hostreplacement.HostReplacementTest.setupCluster) Cluster(org.apache.cassandra.distributed.Cluster) Test(org.junit.Test)

Example 25 with IInvokableInstance

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

the class UnableToParseClientMessageFromBlockedSubnetTest method badMessageCausesProtocolExceptionFromExcludeList.

@Test
public void badMessageCausesProtocolExceptionFromExcludeList() throws IOException, TimeoutException {
    Cluster cluster = getCluster();
    // write gibberish to the native protocol
    IInvokableInstance node = cluster.get(1);
    // make sure everything is fine at the start
    Assertions.assertThat(node.metrics().getCounter("org.apache.cassandra.metrics.Client.ProtocolException")).isEqualTo(0);
    Assertions.assertThat(node.metrics().getCounter("org.apache.cassandra.metrics.Client.UnknownException")).isEqualTo(0);
    LogAction logs = node.logs();
    long mark = logs.mark();
    try (SimpleClient client = SimpleClient.builder("127.0.0.1", 9042).protocolVersion(version).useBeta().build()) {
        client.connect(false, true);
        // this should return a failed response
        // disable waiting on procol errors as that logic was reverted until we can figure out its 100% safe
        // right now ProtocolException is thrown for fatal and non-fatal issues, so closing the channel
        // on non-fatal issues could cause other issues for the cluster
        byte expectedVersion = (byte) (80 + version.asInt());
        Message.Response response = client.execute(new UnableToParseClientMessageTest.CustomHeaderMessage(new byte[] { expectedVersion, 1, 2, 3, 4, 5, 6, 7, 8, 9 }), false);
        Assertions.assertThat(response).isInstanceOf(ErrorMessage.class);
        logs.watchFor(mark, "address contained in client_error_reporting_exclusions");
        Assertions.assertThat(node.metrics().getCounter("org.apache.cassandra.metrics.Client.ProtocolException")).isEqualTo(0);
        Assertions.assertThat(node.metrics().getCounter("org.apache.cassandra.metrics.Client.UnknownException")).isEqualTo(0);
        Assertions.assertThat(logs.grep(mark, "Excluding client exception fo").getResult()).hasSize(1);
        Assertions.assertThat(logs.grep(mark, "Unexpected exception during request").getResult()).isEmpty();
    }
}
Also used : IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) LogAction(org.apache.cassandra.distributed.api.LogAction) ErrorMessage(org.apache.cassandra.transport.messages.ErrorMessage) Message(org.apache.cassandra.transport.Message) Cluster(org.apache.cassandra.distributed.Cluster) SimpleClient(org.apache.cassandra.transport.SimpleClient) 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