Search in sources :

Example 1 with GOSSIP

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

the class ClearSnapshotTest method testSeqClearsSnapshot.

@Test
public void testSeqClearsSnapshot() throws IOException, TimeoutException {
    try (Cluster cluster = init(Cluster.build(3).withConfig(config -> config.with(GOSSIP).with(NETWORK)).withInstanceInitializer(BB::install).start())) {
        cluster.schemaChange(withKeyspace("create table %s.tbl (id int primary key, x int)"));
        for (int i = 0; i < 10; i++) cluster.get(1).executeInternal(withKeyspace("insert into %s.tbl (id, x) values (?, ?)"), i, i);
        cluster.get(1).nodetoolResult("repair", "-seq", "-full", KEYSPACE).asserts().success();
        cluster.get(1).logs().watchFor("Clearing snapshot");
    }
}
Also used : Uninterruptibles(com.google.common.util.concurrent.Uninterruptibles) Logger(org.slf4j.Logger) MethodDelegation(net.bytebuddy.implementation.MethodDelegation) ElementMatchers.named(net.bytebuddy.matcher.ElementMatchers.named) ByteBuddy(net.bytebuddy.ByteBuddy) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IOException(java.io.IOException) Callable(java.util.concurrent.Callable) Test(org.junit.Test) ConsistencyLevel(org.apache.cassandra.distributed.api.ConsistencyLevel) ClassLoadingStrategy(net.bytebuddy.dynamic.loading.ClassLoadingStrategy) ArrayList(java.util.ArrayList) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) SuperCall(net.bytebuddy.implementation.bind.annotation.SuperCall) List(java.util.List) ActiveRepairService(org.apache.cassandra.service.ActiveRepairService) Assert.assertFalse(org.junit.Assert.assertFalse) Cluster(org.apache.cassandra.distributed.Cluster) Directories(org.apache.cassandra.db.Directories) 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 2 with GOSSIP

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

the class ClearSnapshotTest method clearSnapshotSlowTest.

@Test
public void clearSnapshotSlowTest() throws IOException, InterruptedException, ExecutionException {
    try (Cluster cluster = init(Cluster.build(3).withConfig(config -> config.with(GOSSIP).with(NETWORK)).withInstanceInitializer(BB::install).start())) {
        int tableCount = 50;
        for (int i = 0; i < tableCount; i++) {
            String ksname = "ks" + i;
            cluster.schemaChange("create keyspace " + ksname + " with replication = {'class': 'SimpleStrategy', 'replication_factor': 3}");
            cluster.schemaChange("create table " + ksname + ".tbl (id int primary key, t int)");
            cluster.get(1).executeInternal("insert into " + ksname + ".tbl (id , t) values (?, ?)", i, i);
            cluster.forEach((node) -> node.flush(ksname));
        }
        List<Thread> repairThreads = new ArrayList<>();
        for (int i = 0; i < tableCount; i++) {
            String ksname = "ks" + i;
            Thread t = new Thread(() -> cluster.get(1).nodetoolResult("repair", "-full", ksname).asserts().success());
            t.start();
            repairThreads.add(t);
        }
        AtomicBoolean gotExc = new AtomicBoolean(false);
        AtomicBoolean exit = new AtomicBoolean(false);
        Thread reads = new Thread(() -> {
            while (!exit.get()) {
                try {
                    cluster.coordinator(1).execute("select * from ks1.tbl where id = 5", ConsistencyLevel.QUORUM);
                    Uninterruptibles.sleepUninterruptibly(10, TimeUnit.MILLISECONDS);
                } catch (Exception e) {
                    if (!gotExc.get())
                        logger.error("Unexpected exception querying table ks1.tbl", e);
                    gotExc.set(true);
                }
            }
        });
        reads.start();
        long activeRepairs;
        do {
            activeRepairs = cluster.get(1).callOnInstance(() -> ActiveRepairService.instance.parentRepairSessionCount());
            Thread.sleep(50);
        } while (activeRepairs < 35);
        cluster.setUncaughtExceptionsFilter((t) -> t.getMessage() != null && t.getMessage().contains("Parent repair session with id"));
        cluster.get(2).shutdown().get();
        repairThreads.forEach(t -> {
            try {
                t.join();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });
        exit.set(true);
        reads.join();
        assertFalse(gotExc.get());
    }
}
Also used : Uninterruptibles(com.google.common.util.concurrent.Uninterruptibles) Logger(org.slf4j.Logger) MethodDelegation(net.bytebuddy.implementation.MethodDelegation) ElementMatchers.named(net.bytebuddy.matcher.ElementMatchers.named) ByteBuddy(net.bytebuddy.ByteBuddy) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IOException(java.io.IOException) Callable(java.util.concurrent.Callable) Test(org.junit.Test) ConsistencyLevel(org.apache.cassandra.distributed.api.ConsistencyLevel) ClassLoadingStrategy(net.bytebuddy.dynamic.loading.ClassLoadingStrategy) ArrayList(java.util.ArrayList) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) SuperCall(net.bytebuddy.implementation.bind.annotation.SuperCall) List(java.util.List) ActiveRepairService(org.apache.cassandra.service.ActiveRepairService) Assert.assertFalse(org.junit.Assert.assertFalse) Cluster(org.apache.cassandra.distributed.Cluster) Directories(org.apache.cassandra.db.Directories) NETWORK(org.apache.cassandra.distributed.api.Feature.NETWORK) GOSSIP(org.apache.cassandra.distributed.api.Feature.GOSSIP) ArrayList(java.util.ArrayList) Cluster(org.apache.cassandra.distributed.Cluster) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test)

Example 3 with GOSSIP

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

the class GossipTest method testPreventEnablingGossipDuringMove.

@Test
public void testPreventEnablingGossipDuringMove() throws Exception {
    try (Cluster cluster = builder().withNodes(2).withConfig(config -> config.with(GOSSIP).with(NETWORK)).start()) {
        cluster.get(1).runOnInstance(() -> {
            StorageService.instance.stopGossiping();
            StorageService.instance.setMovingModeUnsafe();
            try {
                StorageService.instance.startGossiping();
                Assert.fail("startGossiping did not fail!");
            } catch (Exception ex) {
                Assert.assertSame(ex.getClass(), IllegalStateException.class);
                Assert.assertEquals(ex.getMessage(), "Unable to start gossip because the node is not in the normal state.");
            }
        });
    }
}
Also used : EndpointState(org.apache.cassandra.gms.EndpointState) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) Iterables(com.google.common.collect.Iterables) MethodDelegation(net.bytebuddy.implementation.MethodDelegation) ByteBuddy(net.bytebuddy.ByteBuddy) ElementMatchers.takesArguments(net.bytebuddy.matcher.ElementMatchers.takesArguments) PendingRangeCalculatorService(org.apache.cassandra.service.PendingRangeCalculatorService) Gossiper(org.apache.cassandra.gms.Gossiper) ClusterUtils.runAndWaitForLogs(org.apache.cassandra.distributed.shared.ClusterUtils.runAndWaitForLogs) Token(org.apache.cassandra.dht.Token) StreamResultFuture(org.apache.cassandra.streaming.StreamResultFuture) DistributedTestSnitch.toCassandraInetAddressAndPort(org.apache.cassandra.distributed.impl.DistributedTestSnitch.toCassandraInetAddressAndPort) ClusterUtils.getLocalToken(org.apache.cassandra.distributed.shared.ClusterUtils.getLocalToken) NETWORK(org.apache.cassandra.distributed.api.Feature.NETWORK) ApplicationState(org.apache.cassandra.gms.ApplicationState) Uninterruptibles(com.google.common.util.concurrent.Uninterruptibles) FBUtilities(org.apache.cassandra.utils.FBUtilities) ElementMatchers.named(net.bytebuddy.matcher.ElementMatchers.named) java.util.concurrent(java.util.concurrent) org.apache.cassandra.distributed.api(org.apache.cassandra.distributed.api) Collection(java.util.Collection) StorageService(org.apache.cassandra.service.StorageService) Test(org.junit.Test) ClassLoadingStrategy(net.bytebuddy.dynamic.loading.ClassLoadingStrategy) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) LockSupport(java.util.concurrent.locks.LockSupport) Futures(com.google.common.util.concurrent.Futures) StreamPlan(org.apache.cassandra.streaming.StreamPlan) Closeable(java.io.Closeable) Cluster(org.apache.cassandra.distributed.Cluster) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) GOSSIP(org.apache.cassandra.distributed.api.Feature.GOSSIP) Cluster(org.apache.cassandra.distributed.Cluster) Test(org.junit.Test)

Example 4 with GOSSIP

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

the class GossipTest method nodeDownDuringMove.

@Test
public void nodeDownDuringMove() throws Throwable {
    int liveCount = 1;
    try (Cluster cluster = Cluster.build(2 + liveCount).withConfig(config -> config.with(NETWORK).with(GOSSIP)).createWithoutStarting()) {
        int fail = liveCount + 1;
        int late = fail + 1;
        for (int i = 1; i <= liveCount; ++i) cluster.get(i).startup();
        cluster.get(fail).startup();
        Collection<String> expectTokens = cluster.get(fail).callsOnInstance(() -> StorageService.instance.getTokenMetadata().getTokens(FBUtilities.getBroadcastAddressAndPort()).stream().map(Object::toString).collect(Collectors.toList())).call();
        InetSocketAddress failAddress = cluster.get(fail).broadcastAddress();
        // wait for NORMAL state
        for (int i = 1; i <= liveCount; ++i) {
            cluster.get(i).acceptsOnInstance((InetSocketAddress address) -> {
                EndpointState ep;
                InetAddressAndPort endpoint = toCassandraInetAddressAndPort(address);
                while (null == (ep = Gossiper.instance.getEndpointStateForEndpoint(endpoint)) || ep.getApplicationState(ApplicationState.STATUS_WITH_PORT) == null || !ep.getApplicationState(ApplicationState.STATUS_WITH_PORT).value.startsWith("NORMAL")) LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(10L));
            }).accept(failAddress);
        }
        // set ourselves to MOVING, and wait for it to propagate
        cluster.get(fail).runOnInstance(() -> {
            Token token = Iterables.getFirst(StorageService.instance.getTokenMetadata().getTokens(FBUtilities.getBroadcastAddressAndPort()), null);
            Gossiper.instance.addLocalApplicationState(ApplicationState.STATUS_WITH_PORT, StorageService.instance.valueFactory.moving(token));
        });
        for (int i = 1; i <= liveCount; ++i) {
            cluster.get(i).acceptsOnInstance((InetSocketAddress address) -> {
                EndpointState ep;
                InetAddressAndPort endpoint = toCassandraInetAddressAndPort(address);
                while (null == (ep = Gossiper.instance.getEndpointStateForEndpoint(endpoint)) || (ep.getApplicationState(ApplicationState.STATUS_WITH_PORT) == null || !ep.getApplicationState(ApplicationState.STATUS_WITH_PORT).value.startsWith("MOVING"))) LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(100L));
            }).accept(failAddress);
        }
        cluster.get(fail).shutdown(false).get();
        cluster.get(late).startup();
        cluster.get(late).acceptsOnInstance((InetSocketAddress address) -> {
            EndpointState ep;
            InetAddressAndPort endpoint = toCassandraInetAddressAndPort(address);
            while (null == (ep = Gossiper.instance.getEndpointStateForEndpoint(endpoint)) || !ep.getApplicationState(ApplicationState.STATUS_WITH_PORT).value.startsWith("MOVING")) LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(100L));
        }).accept(failAddress);
        Collection<String> tokens = cluster.get(late).appliesOnInstance((InetSocketAddress address) -> StorageService.instance.getTokenMetadata().getTokens(toCassandraInetAddressAndPort(address)).stream().map(Object::toString).collect(Collectors.toList())).apply(failAddress);
        Assert.assertEquals(expectTokens, tokens);
    }
}
Also used : EndpointState(org.apache.cassandra.gms.EndpointState) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) Iterables(com.google.common.collect.Iterables) MethodDelegation(net.bytebuddy.implementation.MethodDelegation) ByteBuddy(net.bytebuddy.ByteBuddy) ElementMatchers.takesArguments(net.bytebuddy.matcher.ElementMatchers.takesArguments) PendingRangeCalculatorService(org.apache.cassandra.service.PendingRangeCalculatorService) Gossiper(org.apache.cassandra.gms.Gossiper) ClusterUtils.runAndWaitForLogs(org.apache.cassandra.distributed.shared.ClusterUtils.runAndWaitForLogs) Token(org.apache.cassandra.dht.Token) StreamResultFuture(org.apache.cassandra.streaming.StreamResultFuture) DistributedTestSnitch.toCassandraInetAddressAndPort(org.apache.cassandra.distributed.impl.DistributedTestSnitch.toCassandraInetAddressAndPort) ClusterUtils.getLocalToken(org.apache.cassandra.distributed.shared.ClusterUtils.getLocalToken) NETWORK(org.apache.cassandra.distributed.api.Feature.NETWORK) ApplicationState(org.apache.cassandra.gms.ApplicationState) Uninterruptibles(com.google.common.util.concurrent.Uninterruptibles) FBUtilities(org.apache.cassandra.utils.FBUtilities) ElementMatchers.named(net.bytebuddy.matcher.ElementMatchers.named) java.util.concurrent(java.util.concurrent) org.apache.cassandra.distributed.api(org.apache.cassandra.distributed.api) Collection(java.util.Collection) StorageService(org.apache.cassandra.service.StorageService) Test(org.junit.Test) ClassLoadingStrategy(net.bytebuddy.dynamic.loading.ClassLoadingStrategy) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) LockSupport(java.util.concurrent.locks.LockSupport) Futures(com.google.common.util.concurrent.Futures) StreamPlan(org.apache.cassandra.streaming.StreamPlan) Closeable(java.io.Closeable) Cluster(org.apache.cassandra.distributed.Cluster) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) GOSSIP(org.apache.cassandra.distributed.api.Feature.GOSSIP) EndpointState(org.apache.cassandra.gms.EndpointState) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) DistributedTestSnitch.toCassandraInetAddressAndPort(org.apache.cassandra.distributed.impl.DistributedTestSnitch.toCassandraInetAddressAndPort) InetSocketAddress(java.net.InetSocketAddress) Cluster(org.apache.cassandra.distributed.Cluster) Token(org.apache.cassandra.dht.Token) ClusterUtils.getLocalToken(org.apache.cassandra.distributed.shared.ClusterUtils.getLocalToken) Test(org.junit.Test)

Example 5 with GOSSIP

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

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