Search in sources :

Example 11 with NATIVE_PROTOCOL

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

the class ReprepareTestBase method testReprepare.

public void testReprepare(BiConsumer<ClassLoader, Integer> instanceInitializer, ReprepareTestConfiguration... configs) throws Throwable {
    try (ICluster<IInvokableInstance> c = init(builder().withNodes(2).withConfig(config -> config.with(GOSSIP, NETWORK, NATIVE_PROTOCOL)).withInstanceInitializer(instanceInitializer).start())) {
        ForceHostLoadBalancingPolicy lbp = new ForceHostLoadBalancingPolicy();
        c.schemaChange(withKeyspace("CREATE TABLE %s.tbl (pk int, ck int, v int, PRIMARY KEY (pk, ck));"));
        for (ReprepareTestConfiguration config : configs) {
            // 1 has old behaviour
            for (int firstContact : new int[] { 1, 2 }) {
                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()) {
                    lbp.setPrimary(firstContact);
                    final PreparedStatement select = session.prepare(withKeyspace("SELECT * FROM %s.tbl"));
                    session.execute(select.bind());
                    c.stream().forEach((i) -> i.runOnInstance(QueryProcessor::clearPreparedStatementsCache));
                    lbp.setPrimary(firstContact == 1 ? 2 : 1);
                    if (config.withUse)
                        session.execute(withKeyspace("USE %s"));
                    // Re-preparing on the node
                    if (!config.skipBrokenBehaviours && firstContact == 1)
                        session.execute(select.bind());
                    c.stream().forEach((i) -> i.runOnInstance(QueryProcessor::clearPreparedStatementsCache));
                    lbp.setPrimary(firstContact);
                    // Re-preparing on the node with old behaviour will break no matter where the statement was initially prepared
                    if (!config.skipBrokenBehaviours)
                        session.execute(select.bind());
                    c.stream().forEach((i) -> i.runOnInstance(QueryProcessor::clearPreparedStatementsCache));
                }
            }
        }
    }
}
Also used : LoadBalancingPolicy(com.datastax.driver.core.policies.LoadBalancingPolicy) MethodDelegation(net.bytebuddy.implementation.MethodDelegation) ByteBuddy(net.bytebuddy.ByteBuddy) ElementMatchers.takesArguments(net.bytebuddy.matcher.ElementMatchers.takesArguments) QueryProcessor(org.apache.cassandra.cql3.QueryProcessor) QueryHandler(org.apache.cassandra.cql3.QueryHandler) Iterators(com.google.common.collect.Iterators) NATIVE_PROTOCOL(org.apache.cassandra.distributed.api.Feature.NATIVE_PROTOCOL) PreparedStatement(com.datastax.driver.core.PreparedStatement) FixedValue(net.bytebuddy.implementation.FixedValue) Session(com.datastax.driver.core.Session) BiConsumer(java.util.function.BiConsumer) AssertUtils.fail(org.apache.cassandra.distributed.shared.AssertUtils.fail) InvalidRequestException(org.apache.cassandra.exceptions.InvalidRequestException) NETWORK(org.apache.cassandra.distributed.api.Feature.NETWORK) ResultMessage(org.apache.cassandra.transport.messages.ResultMessage) FBUtilities(org.apache.cassandra.utils.FBUtilities) Iterator(java.util.Iterator) ElementMatchers.named(net.bytebuddy.matcher.ElementMatchers.named) Collection(java.util.Collection) ClientState(org.apache.cassandra.service.ClientState) ICluster(org.apache.cassandra.distributed.api.ICluster) ClassLoadingStrategy(net.bytebuddy.dynamic.loading.ClassLoadingStrategy) DriverInternalError(com.datastax.driver.core.exceptions.DriverInternalError) List(java.util.List) IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) Cluster(com.datastax.driver.core.Cluster) Host(com.datastax.driver.core.Host) HostDistance(com.datastax.driver.core.HostDistance) Comparator(java.util.Comparator) Assert(org.junit.Assert) Collections(java.util.Collections) Statement(com.datastax.driver.core.Statement) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) GOSSIP(org.apache.cassandra.distributed.api.Feature.GOSSIP) IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) Cluster(com.datastax.driver.core.Cluster) PreparedStatement(com.datastax.driver.core.PreparedStatement) Session(com.datastax.driver.core.Session)

Example 12 with NATIVE_PROTOCOL

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

the class NetstatsRepairStreamingTest method executeTest.

private void executeTest(boolean compressionEnabled) throws Exception {
    final ExecutorService executorService = Executors.newFixedThreadPool(1);
    try (final Cluster cluster = Cluster.build().withNodeIdTopology(NetworkTopology.singleDcNetworkTopology(2, "dc0", "rack0")).withConfig(config -> config.with(NETWORK, GOSSIP, NATIVE_PROTOCOL).set("stream_throughput_outbound", "122KiB/s").set("compaction_throughput", "1MiB/s").set("stream_entire_sstables", false)).start()) {
        final IInvokableInstance node1 = cluster.get(1);
        final IInvokableInstance node2 = cluster.get(2);
        createTable(cluster, 1, compressionEnabled);
        node1.nodetoolResult("disableautocompaction", "netstats_test").asserts().success();
        node2.nodetoolResult("disableautocompaction", "netstats_test").asserts().success();
        populateData(compressionEnabled);
        node1.flush("netstats_test");
        node2.flush("netstats_test");
        // change RF from 1 to 2 so we need to repair it, repairing will causes streaming shown in netstats
        changeReplicationFactor();
        final Future<NetstatResults> resultsFuture1 = executorService.submit(new NetstatsCallable(node1));
        node1.nodetoolResult("repair", "netstats_test").asserts().success();
        final NetstatResults results = resultsFuture1.get(1, MINUTES);
        results.assertSuccessful();
        NetstatsOutputParser.validate(NetstatsOutputParser.parse(results));
    }
}
Also used : Future(java.util.concurrent.Future) IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) Test(org.junit.Test) Cluster(org.apache.cassandra.distributed.Cluster) MINUTES(java.util.concurrent.TimeUnit.MINUTES) NetworkTopology(org.apache.cassandra.distributed.shared.NetworkTopology) ExecutorService(java.util.concurrent.ExecutorService) Executors(java.util.concurrent.Executors) 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) ExecutorService(java.util.concurrent.ExecutorService) Cluster(org.apache.cassandra.distributed.Cluster)

Example 13 with NATIVE_PROTOCOL

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

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