Search in sources :

Example 31 with NETWORK

use of org.apache.cassandra.distributed.api.Feature.NETWORK in project cassandra by apache.

the class PartitionDenylistTest method checkTimerRetriesLoad.

@Test
public void checkTimerRetriesLoad() throws IOException {
    int nodeCount = 3;
    try (Cluster cluster = Cluster.build(nodeCount).withConfig(config -> config.with(NETWORK).with(GOSSIP).set("partition_denylist_enabled", true).set("denylist_initial_load_retry", "1s")).createWithoutStarting()) {
        // Starting without networking enabled in the hope it doesn't trigger
        // node lifecycle events when nodes start up.
        cluster.get(1).startup();
        cluster.get(1).runOnInstance(PartitionDenylistTest::checkTimerActive);
    }
}
Also used : Uninterruptibles(com.google.common.util.concurrent.Uninterruptibles) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) Global.currentTimeMillis(org.apache.cassandra.utils.Clock.Global.currentTimeMillis) TimeoutException(java.util.concurrent.TimeoutException) StorageService(org.apache.cassandra.service.StorageService) IOException(java.io.IOException) Test(org.junit.Test) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) StorageProxy(org.apache.cassandra.service.StorageProxy) Cluster(org.apache.cassandra.distributed.Cluster) Assert(org.junit.Assert) NETWORK(org.apache.cassandra.distributed.api.Feature.NETWORK) GOSSIP(org.apache.cassandra.distributed.api.Feature.GOSSIP) Cluster(org.apache.cassandra.distributed.Cluster) Test(org.junit.Test)

Example 32 with NETWORK

use of org.apache.cassandra.distributed.api.Feature.NETWORK in project cassandra by apache.

the class GossipSettlesTest method testGossipSettles.

@Test
public void testGossipSettles() throws Throwable {
    /* Use withSubnet(1) to prove seed provider is set correctly - without the fix to pass a seed provider, this test fails */
    try (Cluster cluster = builder().withNodes(3).withConfig(config -> config.with(GOSSIP).with(NETWORK)).withSubnet(1).start()) {
        // Verify the 4.0 WithPort versions of status reporting methods match their InetAddress
        // counterparts.  Disable Gossip first to prevent any bump in heartbeats that would
        // invalidate the comparison.  Compare the newer WithPort versions by adding the
        // storage port to IP addresses in keys/values/strings as appropriate.
        cluster.forEach(i -> i.runOnInstance(() -> {
            Gossiper.instance.stop();
        }));
        cluster.get(1).runOnInstance(() -> {
            // First prove that the storage port is added
            Assert.assertEquals("stuff 127.0.0.1:7012 morestuff 127.0.0.2:7012", addStoragePortToIP("stuff 127.0.0.1 morestuff 127.0.0.2"));
            FailureDetector fd = ((FailureDetector) FailureDetector.instance);
            Assert.assertEquals(addStoragePortToInstanceName(fd.getAllEndpointStates(false)), fd.getAllEndpointStates(true));
            Assert.assertEquals(addPortToKeys(fd.getSimpleStates()), fd.getSimpleStatesWithPort());
            StorageProxy sp = StorageProxy.instance;
            Assert.assertEquals(addPortToSchemaVersions(sp.getSchemaVersions()), sp.getSchemaVersionsWithPort());
            StorageService ss = StorageService.instance;
            Assert.assertEquals(addPortToValues(ss.getTokenToEndpointMap()), ss.getTokenToEndpointWithPortMap());
            Assert.assertEquals(addPortToKeys(ss.getEndpointToHostId()), ss.getEndpointWithPortToHostId());
            Assert.assertEquals(addPortToValues(ss.getHostIdToEndpoint()), ss.getHostIdToEndpointWithPort());
            Assert.assertEquals(addPortToKeys(ss.getLoadMap()), ss.getLoadMapWithPort());
            Assert.assertEquals(addPortToList(ss.getLiveNodes()), ss.getLiveNodesWithPort());
            List<String> naturalEndpointsAddedPort = ss.getNaturalEndpoints(SchemaConstants.DISTRIBUTED_KEYSPACE_NAME, SystemDistributedKeyspace.VIEW_BUILD_STATUS, "dummy").stream().map(e -> addStoragePortToIP(e.getHostAddress())).collect(Collectors.toList());
            Assert.assertEquals(naturalEndpointsAddedPort, ss.getNaturalEndpointsWithPort(SchemaConstants.DISTRIBUTED_KEYSPACE_NAME, SystemDistributedKeyspace.VIEW_BUILD_STATUS, "dummy"));
            naturalEndpointsAddedPort = ss.getNaturalEndpoints(SchemaConstants.DISTRIBUTED_KEYSPACE_NAME, ByteBufferUtil.EMPTY_BYTE_BUFFER).stream().map(e -> addStoragePortToIP(e.getHostAddress())).collect(Collectors.toList());
            Assert.assertEquals(naturalEndpointsAddedPort, ss.getNaturalEndpointsWithPort(SchemaConstants.DISTRIBUTED_KEYSPACE_NAME, ByteBufferUtil.EMPTY_BYTE_BUFFER));
            // Difference in key type... convert to String and add the port to the older format
            Map<String, Float> getOwnershipKeyAddedPort = ss.getOwnership().entrySet().stream().collect(Collectors.<Map.Entry<InetAddress, Float>, String, Float>toMap(e -> addStoragePortToIP(e.getKey().toString()), Map.Entry::getValue));
            Assert.assertEquals(getOwnershipKeyAddedPort, ss.getOwnershipWithPort());
            MessagingService ms = MessagingService.instance();
            Assert.assertEquals(addPortToKeys(ms.getTimeoutsPerHost()), ms.getTimeoutsPerHostWithPort());
            Assert.assertEquals(addPortToKeys(ms.getLargeMessagePendingTasks()), ms.getLargeMessagePendingTasksWithPort());
            Assert.assertEquals(addPortToKeys(ms.getLargeMessageCompletedTasks()), ms.getLargeMessageCompletedTasksWithPort());
            Assert.assertEquals(addPortToKeys(ms.getLargeMessageDroppedTasks()), ms.getLargeMessageDroppedTasksWithPort());
            Assert.assertEquals(addPortToKeys(ms.getSmallMessagePendingTasks()), ms.getSmallMessagePendingTasksWithPort());
            Assert.assertEquals(addPortToKeys(ms.getSmallMessageCompletedTasks()), ms.getSmallMessageCompletedTasksWithPort());
            Assert.assertEquals(addPortToKeys(ms.getSmallMessageDroppedTasks()), ms.getSmallMessageDroppedTasksWithPort());
            Assert.assertEquals(addPortToKeys(ms.getGossipMessagePendingTasks()), ms.getGossipMessagePendingTasksWithPort());
            Assert.assertEquals(addPortToKeys(ms.getGossipMessageCompletedTasks()), ms.getGossipMessageCompletedTasksWithPort());
            Assert.assertEquals(addPortToKeys(ms.getGossipMessageDroppedTasks()), ms.getGossipMessageDroppedTasksWithPort());
        });
    }
}
Also used : MessagingService(org.apache.cassandra.net.MessagingService) Arrays(java.util.Arrays) ByteBufferUtil(org.apache.cassandra.utils.ByteBufferUtil) StorageService(org.apache.cassandra.service.StorageService) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Gossiper(org.apache.cassandra.gms.Gossiper) InetAddress(java.net.InetAddress) SystemDistributedKeyspace(org.apache.cassandra.schema.SystemDistributedKeyspace) List(java.util.List) StorageProxy(org.apache.cassandra.service.StorageProxy) Map(java.util.Map) Cluster(org.apache.cassandra.distributed.Cluster) Pattern(java.util.regex.Pattern) Assert(org.junit.Assert) FailureDetector(org.apache.cassandra.gms.FailureDetector) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) SchemaConstants(org.apache.cassandra.schema.SchemaConstants) NETWORK(org.apache.cassandra.distributed.api.Feature.NETWORK) GOSSIP(org.apache.cassandra.distributed.api.Feature.GOSSIP) StorageProxy(org.apache.cassandra.service.StorageProxy) FailureDetector(org.apache.cassandra.gms.FailureDetector) Cluster(org.apache.cassandra.distributed.Cluster) Map(java.util.Map) InetAddress(java.net.InetAddress) StorageService(org.apache.cassandra.service.StorageService) MessagingService(org.apache.cassandra.net.MessagingService) Test(org.junit.Test)

Example 33 with NETWORK

use of org.apache.cassandra.distributed.api.Feature.NETWORK in project cassandra by apache.

the class PrepareBatchStatementsTest method testPreparedBatch.

@Test
public void testPreparedBatch() throws Exception {
    try (ICluster<IInvokableInstance> c = init(builder().withNodes(1).withConfig(config -> config.with(GOSSIP, NETWORK, NATIVE_PROTOCOL)).start())) {
        try (com.datastax.driver.core.Cluster cluster = com.datastax.driver.core.Cluster.builder().addContactPoint("127.0.0.1").build();
            Session s = cluster.connect()) {
            c.schemaChange(withKeyspace("CREATE KEYSPACE ks1 WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};"));
            c.schemaChange(withKeyspace("CREATE TABLE ks1.tbl (pk int, ck int, v int, PRIMARY KEY (pk, ck));"));
            c.schemaChange(withKeyspace("CREATE KEYSPACE ks2 WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};"));
            c.schemaChange(withKeyspace("CREATE TABLE ks2.tbl (pk int, ck int, v int, PRIMARY KEY (pk, ck));"));
            String batch1 = "BEGIN BATCH\n" + "UPDATE ks1.tbl SET v = ? where pk = ? and ck = ?;\n" + "UPDATE ks2.tbl SET v = ? where pk = ? and ck = ?;\n" + "APPLY BATCH;";
            String batch2 = "BEGIN BATCH\n" + "INSERT INTO ks1.tbl (pk, ck, v) VALUES (?, ?, ?);\n" + "INSERT INTO tbl (pk, ck, v) VALUES (?, ?, ?);\n" + "APPLY BATCH;";
            PreparedStatement prepared;
            prepared = s.prepare(batch1);
            s.execute(prepared.bind(1, 1, 1, 1, 1, 1));
            c.get(1).runOnInstance(() -> {
                // no USE here, only a fully qualified batch - should get stored ONCE
                List<String> stmts = StorageService.instance.getPreparedStatements().stream().map(p -> p.right).collect(Collectors.toList());
                assertEquals(Lists.newArrayList(batch1), stmts);
                QueryProcessor.clearPreparedStatements(false);
            });
            s.execute("use ks2");
            prepared = s.prepare(batch1);
            s.execute(prepared.bind(1, 1, 1, 1, 1, 1));
            c.get(1).runOnInstance(() -> {
                // after USE, fully qualified - should get stored twice! Once with null keyspace (new behaviour) once with ks2 keyspace (old behaviour)
                List<String> stmts = StorageService.instance.getPreparedStatements().stream().map(p -> p.right).collect(Collectors.toList());
                assertEquals(Lists.newArrayList(batch1, batch1), stmts);
                QueryProcessor.clearPreparedStatements(false);
            });
            prepared = s.prepare(batch2);
            s.execute(prepared.bind(1, 1, 1, 1, 1, 1));
            c.get(1).runOnInstance(() -> {
                // after USE, should get stored twice, once with keyspace, once without
                List<String> stmts = StorageService.instance.getPreparedStatements().stream().map(p -> p.right).collect(Collectors.toList());
                assertEquals(Lists.newArrayList(batch2, batch2), stmts);
                QueryProcessor.clearPreparedStatements(false);
            });
        }
    }
}
Also used : ICluster(org.apache.cassandra.distributed.api.ICluster) StorageService(org.apache.cassandra.service.StorageService) Test(org.junit.Test) QueryProcessor(org.apache.cassandra.cql3.QueryProcessor) Collectors(java.util.stream.Collectors) NATIVE_PROTOCOL(org.apache.cassandra.distributed.api.Feature.NATIVE_PROTOCOL) PreparedStatement(com.datastax.driver.core.PreparedStatement) List(java.util.List) IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) Lists(org.assertj.core.util.Lists) Session(com.datastax.driver.core.Session) NETWORK(org.apache.cassandra.distributed.api.Feature.NETWORK) Assert.assertEquals(org.junit.Assert.assertEquals) GOSSIP(org.apache.cassandra.distributed.api.Feature.GOSSIP) IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) PreparedStatement(com.datastax.driver.core.PreparedStatement) Session(com.datastax.driver.core.Session) Test(org.junit.Test)

Example 34 with NETWORK

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

NETWORK (org.apache.cassandra.distributed.api.Feature.NETWORK)34 GOSSIP (org.apache.cassandra.distributed.api.Feature.GOSSIP)33 Test (org.junit.Test)32 Cluster (org.apache.cassandra.distributed.Cluster)27 Assert (org.junit.Assert)17 IInvokableInstance (org.apache.cassandra.distributed.api.IInvokableInstance)16 ConsistencyLevel (org.apache.cassandra.distributed.api.ConsistencyLevel)13 NATIVE_PROTOCOL (org.apache.cassandra.distributed.api.Feature.NATIVE_PROTOCOL)13 StorageService (org.apache.cassandra.service.StorageService)13 ByteBuddy (net.bytebuddy.ByteBuddy)12 ClassLoadingStrategy (net.bytebuddy.dynamic.loading.ClassLoadingStrategy)12 MethodDelegation (net.bytebuddy.implementation.MethodDelegation)12 ElementMatchers.named (net.bytebuddy.matcher.ElementMatchers.named)12 List (java.util.List)11 Map (java.util.Map)11 TimeUnit (java.util.concurrent.TimeUnit)11 ICluster (org.apache.cassandra.distributed.api.ICluster)10 NetworkTopology (org.apache.cassandra.distributed.shared.NetworkTopology)10 IOException (java.io.IOException)9 TokenSupplier (org.apache.cassandra.distributed.api.TokenSupplier)9