Search in sources :

Example 36 with IInvokableInstance

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

the class TestBaseImpl method bootstrapAndJoinNode.

protected void bootstrapAndJoinNode(Cluster cluster) {
    IInstanceConfig config = cluster.newInstanceConfig();
    config.set("auto_bootstrap", true);
    IInvokableInstance newInstance = cluster.bootstrap(config);
    withProperty(BOOTSTRAP_SCHEMA_DELAY_MS.getKey(), Integer.toString(90 * 1000), () -> withProperty("cassandra.join_ring", false, () -> newInstance.startup(cluster)));
    newInstance.nodetoolResult("join").asserts().success();
}
Also used : IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) IInstanceConfig(org.apache.cassandra.distributed.api.IInstanceConfig)

Example 37 with IInvokableInstance

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

the class PendingWritesTest method testPendingWrites.

@Test
public void testPendingWrites() 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()) {
        BootstrapTest.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(bootstrap(false, Duration.ofSeconds(60), Duration.ofSeconds(60)), newInstance.config().num());
        cluster.get(1).acceptsOnInstance((InetSocketAddress ip) -> {
            Set<InetAddressAndPort> set = new HashSet<>();
            for (Map.Entry<Range<Token>, EndpointsForRange.Builder> e : StorageService.instance.getTokenMetadata().getPendingRanges(KEYSPACE)) {
                set.addAll(e.getValue().build().endpoints());
            }
            Assert.assertEquals(set.size(), 1);
            Assert.assertTrue(String.format("%s should contain %s", set, ip), set.contains(DistributedTestSnitch.toCassandraInetAddressAndPort(ip)));
        }).accept(cluster.get(3).broadcastAddress());
        BootstrapTest.populate(cluster, 100, 150);
        newInstance.nodetoolResult("join").asserts().success();
        cluster.run(disseminateGossipState(newInstance), 1, 2);
        cluster.run((instance) -> {
            instance.runOnInstance(() -> {
                PendingRangeCalculatorService.instance.update();
                PendingRangeCalculatorService.instance.blockUntilFinished();
            });
        }, 1, 2);
        cluster.get(1).acceptsOnInstance((InetSocketAddress ip) -> {
            Set<InetAddressAndPort> set = new HashSet<>();
            for (Map.Entry<Range<Token>, EndpointsForRange.Builder> e : StorageService.instance.getTokenMetadata().getPendingRanges(KEYSPACE)) set.addAll(e.getValue().build().endpoints());
            assert set.size() == 0 : set;
        }).accept(cluster.get(3).broadcastAddress());
        for (Map.Entry<Integer, Long> e : BootstrapTest.count(cluster).entrySet()) Assert.assertEquals("Node " + e.getKey() + " has incorrect row state", e.getValue().longValue(), 150L);
    }
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) Range(org.apache.cassandra.dht.Range) PendingRangeCalculatorService(org.apache.cassandra.service.PendingRangeCalculatorService) HashSet(java.util.HashSet) TokenSupplier(org.apache.cassandra.distributed.api.TokenSupplier) DistributedTestSnitch(org.apache.cassandra.distributed.impl.DistributedTestSnitch) Token(org.apache.cassandra.dht.Token) Duration(java.time.Duration) Map(java.util.Map) TestBaseImpl(org.apache.cassandra.distributed.test.TestBaseImpl) IInstanceConfig(org.apache.cassandra.distributed.api.IInstanceConfig) GossipHelper.statusToBootstrap(org.apache.cassandra.distributed.action.GossipHelper.statusToBootstrap) NETWORK(org.apache.cassandra.distributed.api.Feature.NETWORK) EndpointsForRange(org.apache.cassandra.locator.EndpointsForRange) Set(java.util.Set) StorageService(org.apache.cassandra.service.StorageService) Test(org.junit.Test) InetSocketAddress(java.net.InetSocketAddress) GossipHelper.disseminateGossipState(org.apache.cassandra.distributed.action.GossipHelper.disseminateGossipState) GossipHelper.bootstrap(org.apache.cassandra.distributed.action.GossipHelper.bootstrap) IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) Cluster(org.apache.cassandra.distributed.Cluster) GossipHelper.withProperty(org.apache.cassandra.distributed.action.GossipHelper.withProperty) Assert(org.junit.Assert) NetworkTopology(org.apache.cassandra.distributed.shared.NetworkTopology) GOSSIP(org.apache.cassandra.distributed.api.Feature.GOSSIP) IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) HashSet(java.util.HashSet) Set(java.util.Set) InetSocketAddress(java.net.InetSocketAddress) Cluster(org.apache.cassandra.distributed.Cluster) Token(org.apache.cassandra.dht.Token) IInstanceConfig(org.apache.cassandra.distributed.api.IInstanceConfig) EndpointsForRange(org.apache.cassandra.locator.EndpointsForRange) Map(java.util.Map) Test(org.junit.Test)

Example 38 with IInvokableInstance

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

the class RepairOperationalTest method emptyDC.

@Test
public void emptyDC() 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 [2020-09-10 11:30:04,139] Repair command #1 failed with error Nothing to repair for (0,1000] in distributed_test_keyspace - aborting. Check the logs on the repair participants for further details
        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 39 with IInvokableInstance

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

the class StreamCloseInMiddleTest method triggerStreaming.

private static void triggerStreaming(Cluster cluster, boolean expectedEntireSSTable) {
    IInvokableInstance node1 = cluster.get(1);
    IInvokableInstance node2 = cluster.get(2);
    // repair will do streaming IFF there is a mismatch; so cause one
    for (int i = 0; i < 10; i++) // timestamp won't match, causing a mismatch
    node1.executeInternal(withKeyspace("INSERT INTO %s.tbl (pk) VALUES (?)"), i);
    // trigger streaming; expected to fail as streaming socket closed in the middle (currently this is an unrecoverable event)
    node2.nodetoolResult("repair", "-full", KEYSPACE, "tbl").asserts().failure();
    assertStreamingType(node2, expectedEntireSSTable);
}
Also used : IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance)

Example 40 with IInvokableInstance

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

the class StreamCloseInMiddleTest method streamClose.

private void streamClose(boolean zeroCopyStreaming) throws IOException {
    try (Cluster cluster = Cluster.build(2).withTokenSupplier(TokenSupplier.evenlyDistributedTokens(3)).withInstanceInitializer(BBHelper::install).withConfig(c -> c.with(Feature.values()).set("stream_entire_sstables", zeroCopyStreaming).set("disk_failure_policy", "die")).start()) {
        init(cluster);
        cluster.schemaChange(withKeyspace("CREATE TABLE %s.tbl (pk int PRIMARY KEY)"));
        triggerStreaming(cluster, zeroCopyStreaming);
        // make sure disk failure policy is not triggered
        assertNoNodeShutdown(cluster);
        // now bootstrap a new node; streaming will fail
        IInvokableInstance node3 = ClusterUtils.addInstance(cluster, cluster.get(1).config(), c -> c.set("auto_bootstrap", true));
        node3.startup();
        for (String line : // bootstrap failed
        Arrays.asList(// bootstrap failed
        "Error while waiting on bootstrap to complete. Bootstrap will have to be restarted", // didn't join ring because bootstrap failed
        "Some data streaming failed. Use nodetool to check bootstrap state and resume")) Assertions.assertThat(node3.logs().grep(line).getResult()).hasSize(1);
        assertNoNodeShutdown(cluster);
    }
}
Also used : BigTableZeroCopyWriter(org.apache.cassandra.io.sstable.format.big.BigTableZeroCopyWriter) Arrays(java.util.Arrays) Feature(org.apache.cassandra.distributed.api.Feature) MethodDelegation(net.bytebuddy.implementation.MethodDelegation) ElementMatchers.named(net.bytebuddy.matcher.ElementMatchers.named) ByteBuddy(net.bytebuddy.ByteBuddy) ElementMatchers.takesArguments(net.bytebuddy.matcher.ElementMatchers.takesArguments) ClusterUtils(org.apache.cassandra.distributed.shared.ClusterUtils) IOException(java.io.IOException) Callable(java.util.concurrent.Callable) Test(org.junit.Test) ClassLoadingStrategy(net.bytebuddy.dynamic.loading.ClassLoadingStrategy) Collectors(java.util.stream.Collectors) ByteBuffer(java.nio.ByteBuffer) CassandraIncomingFile(org.apache.cassandra.db.streaming.CassandraIncomingFile) SuperCall(net.bytebuddy.implementation.bind.annotation.SuperCall) TokenSupplier(org.apache.cassandra.distributed.api.TokenSupplier) RangeAwareSSTableWriter(org.apache.cassandra.io.sstable.format.RangeAwareSSTableWriter) UnfilteredRowIterator(org.apache.cassandra.db.rows.UnfilteredRowIterator) IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) TestBaseImpl(org.apache.cassandra.distributed.test.TestBaseImpl) Assertions(org.assertj.core.api.Assertions) Cluster(org.apache.cassandra.distributed.Cluster) SequentialWriter(org.apache.cassandra.io.util.SequentialWriter) IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) Cluster(org.apache.cassandra.distributed.Cluster)

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