Search in sources :

Example 11 with IInstanceConfig

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

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

the class ReadRepairTest method readRepairRTRangeMovementTest.

@Test
public void readRepairRTRangeMovementTest() throws Throwable {
    ExecutorService es = Executors.newFixedThreadPool(1);
    String key = "test1";
    try (Cluster cluster = init(Cluster.build().withConfig(config -> config.with(Feature.GOSSIP, Feature.NETWORK).set("read_request_timeout", String.format("%dms", Integer.MAX_VALUE))).withTokenSupplier(TokenSupplier.evenlyDistributedTokens(4)).withNodeIdTopology(NetworkTopology.singleDcNetworkTopology(4, "dc0", "rack0")).withNodes(3).start())) {
        cluster.schemaChange("CREATE TABLE distributed_test_keyspace.tbl (\n" + "    key text,\n" + "    column1 int,\n" + "    PRIMARY KEY (key, column1)\n" + ") WITH CLUSTERING ORDER BY (column1 ASC)");
        cluster.forEach(i -> i.runOnInstance(() -> open(KEYSPACE).getColumnFamilyStore("tbl").disableAutoCompaction()));
        for (int i = 1; i <= 2; i++) {
            cluster.get(i).executeInternal("DELETE FROM distributed_test_keyspace.tbl USING TIMESTAMP 50 WHERE key=?;", key);
            cluster.get(i).executeInternal("DELETE FROM distributed_test_keyspace.tbl USING TIMESTAMP 80 WHERE key=? and column1 >= ? and column1 < ?;", key, 10, 100);
            cluster.get(i).executeInternal("DELETE FROM distributed_test_keyspace.tbl USING TIMESTAMP 70 WHERE key=? and column1 = ?;", key, 30);
            cluster.get(i).flush(KEYSPACE);
        }
        cluster.get(3).executeInternal("DELETE FROM distributed_test_keyspace.tbl USING TIMESTAMP 100 WHERE key=?;", key);
        cluster.get(3).flush(KEYSPACE);
        // pause the read until we have bootstrapped a new node below
        Condition continueRead = newOneTimeCondition();
        Condition readStarted = newOneTimeCondition();
        cluster.filters().outbound().from(3).to(1, 2).verbs(READ_REQ.id).messagesMatching((i, i1, iMessage) -> {
            try {
                readStarted.signalAll();
                continueRead.await();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            return false;
        }).drop();
        Future<Object[][]> read = es.submit(() -> cluster.coordinator(3).execute("SELECT * FROM distributed_test_keyspace.tbl WHERE key=? and column1 >= ? and column1 <= ?", ALL, key, 20, 40));
        readStarted.await();
        IInstanceConfig config = cluster.newInstanceConfig();
        config.set("auto_bootstrap", true);
        cluster.bootstrap(config).startup();
        continueRead.signalAll();
        read.get();
    } finally {
        es.shutdown();
    }
}
Also used : MethodDelegation(net.bytebuddy.implementation.MethodDelegation) ByteBuddy(net.bytebuddy.ByteBuddy) PendingRangeCalculatorService(org.apache.cassandra.service.PendingRangeCalculatorService) TokenSupplier(org.apache.cassandra.distributed.api.TokenSupplier) READ_REPAIR_REQ(org.apache.cassandra.net.Verb.READ_REPAIR_REQ) Future(java.util.concurrent.Future) DecoratedKey(org.apache.cassandra.db.DecoratedKey) READ_REQ(org.apache.cassandra.net.Verb.READ_REQ) Mutation(org.apache.cassandra.db.Mutation) Map(java.util.Map) Murmur3Partitioner(org.apache.cassandra.dht.Murmur3Partitioner) Assert.fail(org.junit.Assert.fail) IInstanceConfig(org.apache.cassandra.distributed.api.IInstanceConfig) ReplicaPlan(org.apache.cassandra.locator.ReplicaPlan) Condition.newOneTimeCondition(org.apache.cassandra.utils.concurrent.Condition.newOneTimeCondition) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) QUORUM(org.apache.cassandra.distributed.api.ConsistencyLevel.QUORUM) AssertUtils.row(org.apache.cassandra.distributed.shared.AssertUtils.row) ElementMatchers.named(net.bytebuddy.matcher.ElementMatchers.named) ConsistencyLevel(org.apache.cassandra.distributed.api.ConsistencyLevel) InetSocketAddress(java.net.InetSocketAddress) Executors(java.util.concurrent.Executors) ReadRepairStrategy(org.apache.cassandra.service.reads.repair.ReadRepairStrategy) AssertUtils.assertRows(org.apache.cassandra.distributed.shared.AssertUtils.assertRows) List(java.util.List) Keyspace.open(org.apache.cassandra.db.Keyspace.open) NetworkTopology(org.apache.cassandra.distributed.shared.NetworkTopology) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) PartitionUpdate(org.apache.cassandra.db.partitions.PartitionUpdate) READ_REPAIR_RSP(org.apache.cassandra.net.Verb.READ_REPAIR_RSP) Config(org.apache.cassandra.config.Config) Global.currentTimeMillis(org.apache.cassandra.utils.Clock.Global.currentTimeMillis) Callable(java.util.concurrent.Callable) Int32Type(org.apache.cassandra.db.marshal.Int32Type) Token(org.apache.cassandra.dht.Token) ICoordinator(org.apache.cassandra.distributed.api.ICoordinator) BlockingReadRepair(org.apache.cassandra.service.reads.repair.BlockingReadRepair) ALL(org.apache.cassandra.distributed.api.ConsistencyLevel.ALL) ExecutorService(java.util.concurrent.ExecutorService) Feature(org.apache.cassandra.distributed.api.Feature) StorageService(org.apache.cassandra.service.StorageService) Condition(org.apache.cassandra.utils.concurrent.Condition) Test(org.junit.Test) ClassLoadingStrategy(net.bytebuddy.dynamic.loading.ClassLoadingStrategy) Replica(org.apache.cassandra.locator.Replica) SuperCall(net.bytebuddy.implementation.bind.annotation.SuperCall) AssertUtils.assertEquals(org.apache.cassandra.distributed.shared.AssertUtils.assertEquals) Cluster(org.apache.cassandra.distributed.Cluster) Assert(org.junit.Assert) Condition.newOneTimeCondition(org.apache.cassandra.utils.concurrent.Condition.newOneTimeCondition) Condition(org.apache.cassandra.utils.concurrent.Condition) IInstanceConfig(org.apache.cassandra.distributed.api.IInstanceConfig) ExecutorService(java.util.concurrent.ExecutorService) Cluster(org.apache.cassandra.distributed.Cluster) Test(org.junit.Test)

Example 13 with IInstanceConfig

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

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

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

the class MigrationCoordinatorTest method explicitVersionIgnore.

@Test
public void explicitVersionIgnore() throws Throwable {
    try (Cluster cluster = Cluster.build(2).withTokenSupplier(TokenSupplier.evenlyDistributedTokens(3)).withNodeIdTopology(NetworkTopology.singleDcNetworkTopology(3, "dc0", "rack0")).withConfig(config -> config.with(NETWORK, GOSSIP)).start()) {
        UUID initialVersion = cluster.get(2).callsOnInstance(() -> Schema.instance.getVersion()).call();
        cluster.schemaChange("CREATE KEYSPACE ks with replication={'class':'SimpleStrategy', 'replication_factor':2}");
        UUID oldVersion;
        do {
            oldVersion = cluster.get(2).callsOnInstance(() -> Schema.instance.getVersion()).call();
        } while (oldVersion.equals(initialVersion));
        cluster.get(2).shutdown(false);
        cluster.schemaChangeIgnoringStoppedInstances("CREATE TABLE ks.tbl (k int primary key, v int)");
        IInstanceConfig config = cluster.newInstanceConfig();
        config.set("auto_bootstrap", true);
        System.setProperty(MigrationCoordinator.IGNORED_VERSIONS_PROP, initialVersion.toString() + ',' + oldVersion.toString());
        System.setProperty("cassandra.consistent.rangemovement", "false");
        cluster.bootstrap(config).startup();
    }
}
Also used : InetAddress(java.net.InetAddress) TokenSupplier(org.apache.cassandra.distributed.api.TokenSupplier) Test(org.junit.Test) Cluster(org.apache.cassandra.distributed.Cluster) UUID(java.util.UUID) MigrationCoordinator(org.apache.cassandra.schema.MigrationCoordinator) IInstanceConfig(org.apache.cassandra.distributed.api.IInstanceConfig) NetworkTopology(org.apache.cassandra.distributed.shared.NetworkTopology) NETWORK(org.apache.cassandra.distributed.api.Feature.NETWORK) Before(org.junit.Before) Schema(org.apache.cassandra.schema.Schema) GOSSIP(org.apache.cassandra.distributed.api.Feature.GOSSIP) IInstanceConfig(org.apache.cassandra.distributed.api.IInstanceConfig) Cluster(org.apache.cassandra.distributed.Cluster) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

IInstanceConfig (org.apache.cassandra.distributed.api.IInstanceConfig)18 Cluster (org.apache.cassandra.distributed.Cluster)8 TokenSupplier (org.apache.cassandra.distributed.api.TokenSupplier)7 NetworkTopology (org.apache.cassandra.distributed.shared.NetworkTopology)7 Test (org.junit.Test)7 GOSSIP (org.apache.cassandra.distributed.api.Feature.GOSSIP)6 NETWORK (org.apache.cassandra.distributed.api.Feature.NETWORK)6 IInvokableInstance (org.apache.cassandra.distributed.api.IInvokableInstance)6 Map (java.util.Map)5 File (org.apache.cassandra.io.util.File)4 Assert (org.junit.Assert)4 InetAddress (java.net.InetAddress)3 InetSocketAddress (java.net.InetSocketAddress)3 UUID (java.util.UUID)3 GossipHelper.bootstrap (org.apache.cassandra.distributed.action.GossipHelper.bootstrap)3 GossipHelper.statusToBootstrap (org.apache.cassandra.distributed.action.GossipHelper.statusToBootstrap)3 GossipHelper.withProperty (org.apache.cassandra.distributed.action.GossipHelper.withProperty)3 ConsistencyLevel (org.apache.cassandra.distributed.api.ConsistencyLevel)3 TestBaseImpl (org.apache.cassandra.distributed.test.TestBaseImpl)3 Arrays.asList (java.util.Arrays.asList)2