Search in sources :

Example 31 with GOSSIP

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

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

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

Example 34 with GOSSIP

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

the class CountersTest method testUpdateCounter.

private static void testUpdateCounter(boolean droppedCompactStorage) throws Throwable {
    try (Cluster cluster = Cluster.build(2).withConfig(c -> c.with(GOSSIP, NATIVE_PROTOCOL).set("drop_compact_storage_enabled", true)).start()) {
        cluster.schemaChange("CREATE KEYSPACE k WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}");
        String createTable = "CREATE TABLE k.t ( k int, c int, total counter, PRIMARY KEY (k, c))";
        if (droppedCompactStorage) {
            cluster.schemaChange(createTable + " WITH COMPACT STORAGE");
            cluster.schemaChange("ALTER TABLE k.t DROP COMPACT STORAGE");
        } else {
            cluster.schemaChange(createTable);
        }
        ConsistencyLevel cl = ConsistencyLevel.ONE;
        String select = "SELECT total FROM k.t WHERE k = 1 AND c = ?";
        for (int i = 1; i <= cluster.size(); i++) {
            ICoordinator coordinator = cluster.coordinator(i);
            coordinator.execute("UPDATE k.t SET total = total + 1 WHERE k = 1 AND c = ?", cl, i);
            assertRows(coordinator.execute(select, cl, i), row(1L));
            coordinator.execute("UPDATE k.t SET total = total - 4 WHERE k = 1 AND c = ?", cl, i);
            assertRows(coordinator.execute(select, cl, i), row(-3L));
        }
    }
}
Also used : AssertUtils.assertRows(org.apache.cassandra.distributed.shared.AssertUtils.assertRows) ICoordinator(org.apache.cassandra.distributed.api.ICoordinator) Test(org.junit.Test) Cluster(org.apache.cassandra.distributed.Cluster) ConsistencyLevel(org.apache.cassandra.distributed.api.ConsistencyLevel) AssertUtils.row(org.apache.cassandra.distributed.shared.AssertUtils.row) GOSSIP(org.apache.cassandra.distributed.api.Feature.GOSSIP) NATIVE_PROTOCOL(org.apache.cassandra.distributed.api.Feature.NATIVE_PROTOCOL) ConsistencyLevel(org.apache.cassandra.distributed.api.ConsistencyLevel) ICoordinator(org.apache.cassandra.distributed.api.ICoordinator) Cluster(org.apache.cassandra.distributed.Cluster)

Aggregations

GOSSIP (org.apache.cassandra.distributed.api.Feature.GOSSIP)34 NETWORK (org.apache.cassandra.distributed.api.Feature.NETWORK)33 Test (org.junit.Test)32 Cluster (org.apache.cassandra.distributed.Cluster)27 Assert (org.junit.Assert)16 IInvokableInstance (org.apache.cassandra.distributed.api.IInvokableInstance)15 ConsistencyLevel (org.apache.cassandra.distributed.api.ConsistencyLevel)14 NATIVE_PROTOCOL (org.apache.cassandra.distributed.api.Feature.NATIVE_PROTOCOL)14 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 StorageService (org.apache.cassandra.service.StorageService)12 TimeUnit (java.util.concurrent.TimeUnit)11 List (java.util.List)10 Map (java.util.Map)10 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