Search in sources :

Example 1 with NATIVE_PROTOCOL

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

the class HintedHandoffAddRemoveNodesTest method shouldBootstrapWithHintsOutstanding.

@Ignore
@Test
public void shouldBootstrapWithHintsOutstanding() throws Exception {
    try (Cluster cluster = builder().withNodes(3).withTokenSupplier(TokenSupplier.evenlyDistributedTokens(4)).withNodeIdTopology(NetworkTopology.singleDcNetworkTopology(4, "dc0", "rack0")).withConfig(config -> config.with(NETWORK, GOSSIP, NATIVE_PROTOCOL)).start()) {
        cluster.schemaChange(withKeyspace("CREATE KEYSPACE %s WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 2}"));
        cluster.schemaChange(withKeyspace("CREATE TABLE %s.boot_hint_test (key int PRIMARY KEY, value int)"));
        cluster.get(3).shutdown().get();
        // Write data using the second node as the coordinator...
        populate(cluster, "boot_hint_test", 2, 0, 128, ConsistencyLevel.ONE);
        Long totalHints = countTotalHints(cluster);
        // ...and verify that we've accumulated hints intended for node 3, which is down.
        assertThat(totalHints).isGreaterThan(0);
        // Bootstrap a new/4th node into the cluster...
        bootstrapAndJoinNode(cluster);
        // ...and verify that all data is available.
        verify(cluster, "boot_hint_test", 4, 0, 128, ConsistencyLevel.ONE);
        // Finally, bring node 3 back up and verify that all hints were delivered.
        cluster.get(3).startup();
        await().atMost(30, SECONDS).pollDelay(3, SECONDS).until(() -> count(cluster, "boot_hint_test", 3).equals(totalHints));
        verify(cluster, "boot_hint_test", 3, 0, 128, ConsistencyLevel.ONE);
        verify(cluster, "boot_hint_test", 3, 0, 128, ConsistencyLevel.TWO);
    }
}
Also used : StorageMetrics(org.apache.cassandra.metrics.StorageMetrics) StorageService(org.apache.cassandra.service.StorageService) Test(org.junit.Test) ConsistencyLevel(org.apache.cassandra.distributed.api.ConsistencyLevel) GossipHelper(org.apache.cassandra.distributed.action.GossipHelper) NATIVE_PROTOCOL(org.apache.cassandra.distributed.api.Feature.NATIVE_PROTOCOL) TimeUnit(java.util.concurrent.TimeUnit) AssertUtils.assertRows(org.apache.cassandra.distributed.shared.AssertUtils.assertRows) TokenSupplier(org.apache.cassandra.distributed.api.TokenSupplier) Ignore(org.junit.Ignore) Cluster(org.apache.cassandra.distributed.Cluster) NetworkTopology(org.apache.cassandra.distributed.shared.NetworkTopology) AssertionsForClassTypes.assertThat(org.assertj.core.api.AssertionsForClassTypes.assertThat) Awaitility(org.awaitility.Awaitility) NETWORK(org.apache.cassandra.distributed.api.Feature.NETWORK) AssertUtils.row(org.apache.cassandra.distributed.shared.AssertUtils.row) Assert.assertEquals(org.junit.Assert.assertEquals) GossipHelper.decommission(org.apache.cassandra.distributed.action.GossipHelper.decommission) GOSSIP(org.apache.cassandra.distributed.api.Feature.GOSSIP) Cluster(org.apache.cassandra.distributed.Cluster) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with NATIVE_PROTOCOL

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

the class HintedHandoffAddRemoveNodesTest method shouldStreamHintsDuringDecommission.

/**
 * Replaces Python dtest {@code hintedhandoff_test.py:TestHintedHandoff.test_hintedhandoff_decom()}.
 * Ignored for now as there is some in-jvm bug which needs to be fixed, otherwise the test is flaky
 * For more information see CASSANDRA-16679
 */
@Ignore
@Test
public void shouldStreamHintsDuringDecommission() throws Exception {
    try (Cluster cluster = builder().withNodes(4).withConfig(config -> config.with(NETWORK, GOSSIP, NATIVE_PROTOCOL)).start()) {
        cluster.schemaChange(withKeyspace("CREATE KEYSPACE %s WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 2}"));
        cluster.schemaChange(withKeyspace("CREATE TABLE %s.decom_hint_test (key int PRIMARY KEY, value int)"));
        cluster.get(4).shutdown().get();
        // Write data using the second node as the coordinator...
        populate(cluster, "decom_hint_test", 2, 0, 128, ConsistencyLevel.ONE);
        Long totalHints = countTotalHints(cluster);
        // ...and verify that we've accumulated hints intended for node 4, which is down.
        assertThat(totalHints).isGreaterThan(0);
        // Decomision node 1...
        assertEquals(4, endpointsKnownTo(cluster, 2));
        cluster.run(decommission(), 1);
        await().pollDelay(1, SECONDS).until(() -> endpointsKnownTo(cluster, 2) == 3);
        // ...and verify that all data still exists on either node 2 or 3.
        verify(cluster, "decom_hint_test", 2, 0, 128, ConsistencyLevel.ONE);
        // Start node 4 back up and verify that all hints were delivered.
        cluster.get(4).startup();
        await().atMost(30, SECONDS).pollDelay(3, SECONDS).until(() -> count(cluster, "decom_hint_test", 4).equals(totalHints));
        // Now decommission both nodes 2 and 3...
        cluster.run(GossipHelper.decommission(true), 2);
        cluster.run(GossipHelper.decommission(true), 3);
        await().pollDelay(1, SECONDS).until(() -> endpointsKnownTo(cluster, 4) == 1);
        // ...and verify that even if we drop below the replication factor of 2, all data has been preserved.
        verify(cluster, "decom_hint_test", 4, 0, 128, ConsistencyLevel.ONE);
    }
}
Also used : StorageMetrics(org.apache.cassandra.metrics.StorageMetrics) StorageService(org.apache.cassandra.service.StorageService) Test(org.junit.Test) ConsistencyLevel(org.apache.cassandra.distributed.api.ConsistencyLevel) GossipHelper(org.apache.cassandra.distributed.action.GossipHelper) NATIVE_PROTOCOL(org.apache.cassandra.distributed.api.Feature.NATIVE_PROTOCOL) TimeUnit(java.util.concurrent.TimeUnit) AssertUtils.assertRows(org.apache.cassandra.distributed.shared.AssertUtils.assertRows) TokenSupplier(org.apache.cassandra.distributed.api.TokenSupplier) Ignore(org.junit.Ignore) Cluster(org.apache.cassandra.distributed.Cluster) NetworkTopology(org.apache.cassandra.distributed.shared.NetworkTopology) AssertionsForClassTypes.assertThat(org.assertj.core.api.AssertionsForClassTypes.assertThat) Awaitility(org.awaitility.Awaitility) NETWORK(org.apache.cassandra.distributed.api.Feature.NETWORK) AssertUtils.row(org.apache.cassandra.distributed.shared.AssertUtils.row) Assert.assertEquals(org.junit.Assert.assertEquals) GossipHelper.decommission(org.apache.cassandra.distributed.action.GossipHelper.decommission) GOSSIP(org.apache.cassandra.distributed.api.Feature.GOSSIP) Cluster(org.apache.cassandra.distributed.Cluster) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with NATIVE_PROTOCOL

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

the class CommunicationDuringDecommissionTest method internodeConnectionsDuringDecom.

@Test
public void internodeConnectionsDuringDecom() throws Throwable {
    try (Cluster cluster = builder().withNodes(4).withConfig(config -> config.with(NETWORK, GOSSIP, NATIVE_PROTOCOL)).start()) {
        BootstrapTest.populate(cluster, 0, 100);
        cluster.run(decommission(), 1);
        cluster.filters().allVerbs().from(1).messagesMatching((i, i1, iMessage) -> {
            throw new AssertionError("Decomissioned node should not send any messages");
        }).drop();
        Map<Integer, Long> connectionAttempts = new HashMap<>();
        long deadline = currentTimeMillis() + TimeUnit.SECONDS.toMillis(10);
        // Wait 10 seconds and check if there are any new connection attempts to the decomissioned node
        while (currentTimeMillis() <= deadline) {
            for (int i = 2; i <= cluster.size(); i++) {
                Object[][] res = cluster.get(i).executeInternal("SELECT active_connections, connection_attempts FROM system_views.internode_outbound WHERE address = '127.0.0.1' AND port = 7012");
                Assert.assertEquals(1, res.length);
                Assert.assertEquals(0L, ((Long) res[0][0]).longValue());
                long attempts = ((Long) res[0][1]).longValue();
                if (connectionAttempts.get(i) == null)
                    connectionAttempts.put(i, attempts);
                else
                    Assert.assertEquals(connectionAttempts.get(i), (Long) attempts);
            }
            LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(100));
        }
    }
}
Also used : Global.currentTimeMillis(org.apache.cassandra.utils.Clock.Global.currentTimeMillis) HashMap(java.util.HashMap) Test(org.junit.Test) NATIVE_PROTOCOL(org.apache.cassandra.distributed.api.Feature.NATIVE_PROTOCOL) TimeUnit(java.util.concurrent.TimeUnit) LockSupport(java.util.concurrent.locks.LockSupport) Map(java.util.Map) TestBaseImpl(org.apache.cassandra.distributed.test.TestBaseImpl) Cluster(org.apache.cassandra.distributed.Cluster) Assert(org.junit.Assert) NETWORK(org.apache.cassandra.distributed.api.Feature.NETWORK) GossipHelper.decommission(org.apache.cassandra.distributed.action.GossipHelper.decommission) GOSSIP(org.apache.cassandra.distributed.api.Feature.GOSSIP) HashMap(java.util.HashMap) Cluster(org.apache.cassandra.distributed.Cluster) Test(org.junit.Test)

Example 4 with NATIVE_PROTOCOL

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

the class TopologyChangeTest method testRestartNode.

@Test
public void testRestartNode() throws Throwable {
    try (Cluster control = init(Cluster.build().withNodes(3).withNodeProvisionStrategy(strategy).withConfig(config -> config.with(GOSSIP, NETWORK, NATIVE_PROTOCOL)).start());
        com.datastax.driver.core.Cluster cluster = com.datastax.driver.core.Cluster.builder().addContactPoint("127.0.0.1").build();
        Session session = cluster.connect()) {
        EventStateListener eventStateListener = new EventStateListener();
        session.getCluster().register(eventStateListener);
        control.get(3).shutdown().get();
        await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> Assert.assertEquals(2, cluster.getMetadata().getAllHosts().stream().filter(h -> h.isUp()).count()));
        control.get(3).startup();
        await().atMost(30, TimeUnit.SECONDS).untilAsserted(() -> Assert.assertEquals(3, cluster.getMetadata().getAllHosts().stream().filter(h -> h.isUp()).count()));
        // DOWN UP can also be seen if the jvm is slow and connections are closed, but make sure it at least happens once
        // given the node restarts
        assertThat(eventStateListener.events).containsSequence(new Event(Down, control.get(3)), new Event(Up, control.get(3)));
    }
}
Also used : Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) Down(org.apache.cassandra.distributed.test.TopologyChangeTest.EventStateListener.EventType.Down) NATIVE_PROTOCOL(org.apache.cassandra.distributed.api.Feature.NATIVE_PROTOCOL) Event(org.apache.cassandra.distributed.test.TopologyChangeTest.EventStateListener.Event) Session(com.datastax.driver.core.Session) Parameterized(org.junit.runners.Parameterized) NETWORK(org.apache.cassandra.distributed.api.Feature.NETWORK) OneNetworkInterface(org.apache.cassandra.distributed.impl.INodeProvisionStrategy.Strategy.OneNetworkInterface) Awaitility.await(org.awaitility.Awaitility.await) Collection(java.util.Collection) Test(org.junit.Test) InetSocketAddress(java.net.InetSocketAddress) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) MultipleNetworkInterfaces(org.apache.cassandra.distributed.impl.INodeProvisionStrategy.Strategy.MultipleNetworkInterfaces) Remove(org.apache.cassandra.distributed.test.TopologyChangeTest.EventStateListener.EventType.Remove) List(java.util.List) IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) Host(com.datastax.driver.core.Host) Up(org.apache.cassandra.distributed.test.TopologyChangeTest.EventStateListener.EventType.Up) Strategy(org.apache.cassandra.distributed.impl.INodeProvisionStrategy.Strategy) Cluster(org.apache.cassandra.distributed.Cluster) Assert(org.junit.Assert) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) GOSSIP(org.apache.cassandra.distributed.api.Feature.GOSSIP) Cluster(org.apache.cassandra.distributed.Cluster) Event(org.apache.cassandra.distributed.test.TopologyChangeTest.EventStateListener.Event) Session(com.datastax.driver.core.Session) Test(org.junit.Test)

Example 5 with NATIVE_PROTOCOL

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

the class ReprepareTestOldBehaviour method testReprepareMixedVersionWithoutReset.

@Test
public void testReprepareMixedVersionWithoutReset() throws Throwable {
    try (ICluster<IInvokableInstance> c = init(builder().withNodes(2).withConfig(config -> config.with(GOSSIP, NETWORK, NATIVE_PROTOCOL)).withInstanceInitializer(PrepareBehaviour::oldBehaviour).start())) {
        ForceHostLoadBalancingPolicy lbp = new ForceHostLoadBalancingPolicy();
        c.schemaChange(withKeyspace("CREATE TABLE %s.tbl (pk int, ck int, v int, PRIMARY KEY (pk, ck));"));
        // 1 has old behaviour
        for (int firstContact : new int[] { 1, 2 }) {
            for (boolean withUse : new boolean[] { true, false }) {
                for (boolean clearBetweenExecutions : new boolean[] { true, false }) {
                    try (com.datastax.driver.core.Cluster cluster = com.datastax.driver.core.Cluster.builder().addContactPoint("127.0.0.1").addContactPoint("127.0.0.2").withLoadBalancingPolicy(lbp).build();
                        Session session = cluster.connect()) {
                        if (withUse)
                            session.execute(withKeyspace("USE %s"));
                        lbp.setPrimary(firstContact);
                        final PreparedStatement select = session.prepare(withKeyspace("SELECT * FROM %s.tbl"));
                        session.execute(select.bind());
                        if (clearBetweenExecutions)
                            c.get(2).runOnInstance(QueryProcessor::clearPreparedStatementsCache);
                        lbp.setPrimary(firstContact == 1 ? 2 : 1);
                        session.execute(select.bind());
                        if (clearBetweenExecutions)
                            c.get(2).runOnInstance(QueryProcessor::clearPreparedStatementsCache);
                        lbp.setPrimary(firstContact);
                        session.execute(select.bind());
                        c.get(2).runOnInstance(QueryProcessor::clearPreparedStatementsCache);
                    }
                }
            }
        }
    }
}
Also used : PreparedStatement(com.datastax.driver.core.PreparedStatement) IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) Session(com.datastax.driver.core.Session) ICluster(org.apache.cassandra.distributed.api.ICluster) Test(org.junit.Test) QueryProcessor(org.apache.cassandra.cql3.QueryProcessor) NETWORK(org.apache.cassandra.distributed.api.Feature.NETWORK) GOSSIP(org.apache.cassandra.distributed.api.Feature.GOSSIP) NATIVE_PROTOCOL(org.apache.cassandra.distributed.api.Feature.NATIVE_PROTOCOL) IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) PreparedStatement(com.datastax.driver.core.PreparedStatement) QueryProcessor(org.apache.cassandra.cql3.QueryProcessor) Session(com.datastax.driver.core.Session) Test(org.junit.Test)

Aggregations

GOSSIP (org.apache.cassandra.distributed.api.Feature.GOSSIP)14 NATIVE_PROTOCOL (org.apache.cassandra.distributed.api.Feature.NATIVE_PROTOCOL)14 NETWORK (org.apache.cassandra.distributed.api.Feature.NETWORK)13 Test (org.junit.Test)12 IInvokableInstance (org.apache.cassandra.distributed.api.IInvokableInstance)10 Session (com.datastax.driver.core.Session)8 PreparedStatement (com.datastax.driver.core.PreparedStatement)7 QueryProcessor (org.apache.cassandra.cql3.QueryProcessor)7 Cluster (org.apache.cassandra.distributed.Cluster)7 ICluster (org.apache.cassandra.distributed.api.ICluster)7 List (java.util.List)6 Assert (org.junit.Assert)6 TimeUnit (java.util.concurrent.TimeUnit)5 ConsistencyLevel (org.apache.cassandra.distributed.api.ConsistencyLevel)5 Host (com.datastax.driver.core.Host)4 Iterator (java.util.Iterator)4 ByteBuddy (net.bytebuddy.ByteBuddy)4 ClassLoadingStrategy (net.bytebuddy.dynamic.loading.ClassLoadingStrategy)4 MethodDelegation (net.bytebuddy.implementation.MethodDelegation)4 ElementMatchers.named (net.bytebuddy.matcher.ElementMatchers.named)4