Search in sources :

Example 1 with ALL

use of org.apache.cassandra.distributed.api.ConsistencyLevel.ALL in project cassandra by apache.

the class GossipShutdownTest method shutdownStayDownTest.

/**
 * Makes sure that a node that has shutdown doesn't come back as live (without being restarted)
 */
@Test
public void shutdownStayDownTest() throws IOException, InterruptedException, ExecutionException {
    ExecutorService es = Executors.newSingleThreadExecutor();
    try (Cluster cluster = init(builder().withNodes(2).withConfig(config -> config.with(GOSSIP).with(NETWORK)).start())) {
        cluster.schemaChange("create table " + KEYSPACE + ".tbl (id int primary key, v int)");
        for (int i = 0; i < 10; i++) cluster.coordinator(1).execute("insert into " + KEYSPACE + ".tbl (id, v) values (?,?)", ALL, i, i);
        Condition timeToShutdown = newOneTimeCondition();
        Condition waitForShutdown = newOneTimeCondition();
        AtomicBoolean signalled = new AtomicBoolean(false);
        Future f = es.submit(() -> {
            await(timeToShutdown);
            cluster.get(1).runOnInstance(() -> {
                instance.register(new EPChanges());
            });
            cluster.get(2).runOnInstance(() -> {
                StorageService.instance.setIsShutdownUnsafeForTests(true);
                instance.stop();
            });
            waitForShutdown.signalAll();
        });
        cluster.filters().outbound().from(2).to(1).verbs(GOSSIP_DIGEST_SYN.id).messagesMatching((from, to, message) -> true).drop();
        cluster.filters().outbound().from(2).to(1).verbs(GOSSIP_DIGEST_ACK.id).messagesMatching((from, to, message) -> {
            if (signalled.compareAndSet(false, true)) {
                timeToShutdown.signalAll();
                await(waitForShutdown);
                return false;
            }
            return true;
        }).drop();
        // wait for gossip to exchange a few messages
        sleep(10000);
        f.get();
    } finally {
        es.shutdown();
    }
}
Also used : Condition(org.apache.cassandra.utils.concurrent.Condition) Condition.newOneTimeCondition(org.apache.cassandra.utils.concurrent.Condition.newOneTimeCondition) EndpointState(org.apache.cassandra.gms.EndpointState) VersionedValue(org.apache.cassandra.gms.VersionedValue) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) ApplicationState(org.apache.cassandra.gms.ApplicationState) IEndpointStateChangeSubscriber(org.apache.cassandra.gms.IEndpointStateChangeSubscriber) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) StorageService(org.apache.cassandra.service.StorageService) IOException(java.io.IOException) Condition(org.apache.cassandra.utils.concurrent.Condition) Test(org.junit.Test) Executors(java.util.concurrent.Executors) Serializable(java.io.Serializable) ExecutionException(java.util.concurrent.ExecutionException) Future(java.util.concurrent.Future) GOSSIP_DIGEST_SYN(org.apache.cassandra.net.Verb.GOSSIP_DIGEST_SYN) GOSSIP_DIGEST_ACK(org.apache.cassandra.net.Verb.GOSSIP_DIGEST_ACK) Gossiper.instance(org.apache.cassandra.gms.Gossiper.instance) Thread.sleep(java.lang.Thread.sleep) Cluster(org.apache.cassandra.distributed.Cluster) Condition.newOneTimeCondition(org.apache.cassandra.utils.concurrent.Condition.newOneTimeCondition) ALL(org.apache.cassandra.distributed.api.ConsistencyLevel.ALL) ExecutorService(java.util.concurrent.ExecutorService) NETWORK(org.apache.cassandra.distributed.api.Feature.NETWORK) GOSSIP(org.apache.cassandra.distributed.api.Feature.GOSSIP) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ExecutorService(java.util.concurrent.ExecutorService) Cluster(org.apache.cassandra.distributed.Cluster) Future(java.util.concurrent.Future) Test(org.junit.Test)

Example 2 with ALL

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

Aggregations

ExecutorService (java.util.concurrent.ExecutorService)2 Executors (java.util.concurrent.Executors)2 Future (java.util.concurrent.Future)2 Cluster (org.apache.cassandra.distributed.Cluster)2 ALL (org.apache.cassandra.distributed.api.ConsistencyLevel.ALL)2 InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)2 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 Thread.sleep (java.lang.Thread.sleep)1 InetSocketAddress (java.net.InetSocketAddress)1 List (java.util.List)1 Map (java.util.Map)1 Callable (java.util.concurrent.Callable)1 ExecutionException (java.util.concurrent.ExecutionException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 ByteBuddy (net.bytebuddy.ByteBuddy)1 ClassLoadingStrategy (net.bytebuddy.dynamic.loading.ClassLoadingStrategy)1 MethodDelegation (net.bytebuddy.implementation.MethodDelegation)1 SuperCall (net.bytebuddy.implementation.bind.annotation.SuperCall)1 ElementMatchers.named (net.bytebuddy.matcher.ElementMatchers.named)1