Search in sources :

Example 6 with SimpleQueryResult

use of org.apache.cassandra.distributed.api.SimpleQueryResult in project cassandra by apache.

the class HostReplacementTest method validateRows.

static void validateRows(ICoordinator coordinator, SimpleQueryResult expected) {
    expected.reset();
    SimpleQueryResult rows = coordinator.executeWithResult("SELECT * FROM " + KEYSPACE + ".tbl", ConsistencyLevel.ALL);
    AssertUtils.assertRows(rows, expected);
}
Also used : SimpleQueryResult(org.apache.cassandra.distributed.api.SimpleQueryResult)

Example 7 with SimpleQueryResult

use of org.apache.cassandra.distributed.api.SimpleQueryResult in project cassandra by apache.

the class HostReplacementTest method seedGoesDownBeforeDownHost.

/**
 * If the seed goes down, then another node, once the seed comes back, make sure host replacements still work.
 */
@Test
public void seedGoesDownBeforeDownHost() throws IOException {
    // start with 3 nodes, stop both nodes, start the seed, host replace the down node)
    TokenSupplier even = TokenSupplier.evenlyDistributedTokens(3);
    try (Cluster cluster = Cluster.build(3).withConfig(c -> c.with(Feature.GOSSIP, Feature.NETWORK)).withTokenSupplier(node -> even.token(node == 4 ? 2 : node)).start()) {
        // call early as this can't be touched on a down node
        IInvokableInstance seed = cluster.get(1);
        IInvokableInstance nodeToRemove = cluster.get(2);
        IInvokableInstance nodeToStayAlive = cluster.get(3);
        setupCluster(cluster);
        // collect rows/tokens to detect issues later on if the state doesn't match
        SimpleQueryResult expectedState = nodeToRemove.coordinator().executeWithResult("SELECT * FROM " + KEYSPACE + ".tbl", ConsistencyLevel.ALL);
        List<String> beforeCrashTokens = getTokenMetadataTokens(seed);
        // shutdown the seed, then the node to remove
        stopUnchecked(seed);
        stopUnchecked(nodeToRemove);
        // restart the seed
        seed.startup();
        // make sure the node to remove is still in the ring
        assertInRing(seed, nodeToRemove);
        // make sure node1 still has node2's tokens
        List<String> currentTokens = getTokenMetadataTokens(seed);
        Assertions.assertThat(currentTokens).as("Tokens no longer match after restarting").isEqualTo(beforeCrashTokens);
        // now create a new node to replace the other node
        IInvokableInstance replacingNode = replaceHostAndStart(cluster, nodeToRemove);
        List<IInvokableInstance> expectedRing = Arrays.asList(seed, replacingNode, nodeToStayAlive);
        // wait till the replacing node is in the ring
        awaitRingJoin(seed, replacingNode);
        awaitRingJoin(replacingNode, seed);
        awaitRingJoin(nodeToStayAlive, replacingNode);
        // make sure all nodes are healthy
        logger.info("Current ring is {}", awaitRingHealthy(seed));
        expectedRing.forEach(i -> assertRingIs(i, expectedRing));
        validateRows(seed.coordinator(), expectedState);
        validateRows(replacingNode.coordinator(), expectedState);
    }
}
Also used : Arrays(java.util.Arrays) ClusterUtils.getTokenMetadataTokens(org.apache.cassandra.distributed.shared.ClusterUtils.getTokenMetadataTokens) LoggerFactory(org.slf4j.LoggerFactory) ClusterUtils.stopUnchecked(org.apache.cassandra.distributed.shared.ClusterUtils.stopUnchecked) BOOTSTRAP_SKIP_SCHEMA_CHECK(org.apache.cassandra.config.CassandraRelevantProperties.BOOTSTRAP_SKIP_SCHEMA_CHECK) TokenSupplier(org.apache.cassandra.distributed.api.TokenSupplier) ClusterUtils.replaceHostAndStart(org.apache.cassandra.distributed.shared.ClusterUtils.replaceHostAndStart) ICoordinator(org.apache.cassandra.distributed.api.ICoordinator) ClusterUtils.assertInRing(org.apache.cassandra.distributed.shared.ClusterUtils.assertInRing) TestBaseImpl(org.apache.cassandra.distributed.test.TestBaseImpl) SimpleQueryResult(org.apache.cassandra.distributed.api.SimpleQueryResult) Assertions(org.assertj.core.api.Assertions) Constants(org.apache.cassandra.distributed.Constants) AssertUtils(org.apache.cassandra.distributed.shared.AssertUtils) Feature(org.apache.cassandra.distributed.api.Feature) Logger(org.slf4j.Logger) GOSSIPER_QUARANTINE_DELAY(org.apache.cassandra.config.CassandraRelevantProperties.GOSSIPER_QUARANTINE_DELAY) ClusterUtils.awaitRingJoin(org.apache.cassandra.distributed.shared.ClusterUtils.awaitRingJoin) IOException(java.io.IOException) Test(org.junit.Test) ConsistencyLevel(org.apache.cassandra.distributed.api.ConsistencyLevel) List(java.util.List) IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) Cluster(org.apache.cassandra.distributed.Cluster) ClusterUtils.assertRingIs(org.apache.cassandra.distributed.shared.ClusterUtils.assertRingIs) ClusterUtils.awaitRingHealthy(org.apache.cassandra.distributed.shared.ClusterUtils.awaitRingHealthy) IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) SimpleQueryResult(org.apache.cassandra.distributed.api.SimpleQueryResult) TokenSupplier(org.apache.cassandra.distributed.api.TokenSupplier) Cluster(org.apache.cassandra.distributed.Cluster) Test(org.junit.Test)

Example 8 with SimpleQueryResult

use of org.apache.cassandra.distributed.api.SimpleQueryResult in project cassandra by apache.

the class AbstractClientSizeWarning method noWarnings.

public void noWarnings(String cql) {
    CLUSTER.coordinator(1).execute("INSERT INTO " + KEYSPACE + ".tbl (pk, ck, v) VALUES (1, 1, ?)", ConsistencyLevel.ALL, bytes(128));
    CLUSTER.coordinator(1).execute("INSERT INTO " + KEYSPACE + ".tbl (pk, ck, v) VALUES (1, 2, ?)", ConsistencyLevel.ALL, bytes(128));
    if (shouldFlush())
        CLUSTER.stream().forEach(i -> i.flush(KEYSPACE));
    Consumer<List<String>> test = warnings -> Assert.assertEquals(Collections.emptyList(), warnings);
    for (boolean b : Arrays.asList(true, false)) {
        enable(b);
        checkpointHistogram();
        SimpleQueryResult result = CLUSTER.coordinator(1).executeWithResult(cql, ConsistencyLevel.ALL);
        test.accept(result.warnings());
        if (b) {
            assertHistogramUpdated();
        } else {
            assertHistogramNotUpdated();
        }
        test.accept(driverQueryAll(cql).getExecutionInfo().getWarnings());
        if (b) {
            assertHistogramUpdated();
        } else {
            assertHistogramNotUpdated();
        }
        assertWarnAborts(0, 0, 0);
    }
}
Also used : Arrays(java.util.Arrays) SimpleStatement(com.datastax.driver.core.SimpleStatement) BeforeClass(org.junit.BeforeClass) ClientWarn(org.apache.cassandra.service.ClientWarn) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Random(java.util.Random) JavaDriverUtils(org.apache.cassandra.distributed.test.JavaDriverUtils) QueryProcessor(org.apache.cassandra.cql3.QueryProcessor) ByteBuffer(java.nio.ByteBuffer) InetAddress(java.net.InetAddress) ResultSet(com.datastax.driver.core.ResultSet) ICoordinator(org.apache.cassandra.distributed.api.ICoordinator) TestBaseImpl(org.apache.cassandra.distributed.test.TestBaseImpl) SimpleQueryResult(org.apache.cassandra.distributed.api.SimpleQueryResult) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) Before(org.junit.Before) Feature(org.apache.cassandra.distributed.api.Feature) CoordinatorWarnings(org.apache.cassandra.service.reads.trackwarnings.CoordinatorWarnings) ImmutableSet(com.google.common.collect.ImmutableSet) QueryState(org.apache.cassandra.service.QueryState) ReadSizeAbortException(org.apache.cassandra.exceptions.ReadSizeAbortException) ICluster(org.apache.cassandra.distributed.api.ICluster) IOException(java.io.IOException) Test(org.junit.Test) ConsistencyLevel(org.apache.cassandra.distributed.api.ConsistencyLevel) RequestFailureReason(org.apache.cassandra.exceptions.RequestFailureReason) UnknownHostException(java.net.UnknownHostException) Consumer(java.util.function.Consumer) List(java.util.List) IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) Condition(org.assertj.core.api.Condition) Cluster(org.apache.cassandra.distributed.Cluster) Assert(org.junit.Assert) Collections(java.util.Collections) SimpleQueryResult(org.apache.cassandra.distributed.api.SimpleQueryResult) List(java.util.List)

Example 9 with SimpleQueryResult

use of org.apache.cassandra.distributed.api.SimpleQueryResult in project cassandra by apache.

the class TombstoneCountWarningTest method noWarnings.

public void noWarnings(String cql) {
    Consumer<List<String>> test = warnings -> Assert.assertEquals(Collections.emptyList(), warnings);
    for (int i = 0; i < TOMBSTONE_WARN; i++) CLUSTER.coordinator(1).execute("INSERT INTO " + KEYSPACE + ".tbl (pk, ck, v) VALUES (1, ?, null)", ConsistencyLevel.ALL, i);
    for (boolean b : Arrays.asList(true, false)) {
        enable(b);
        SimpleQueryResult result = CLUSTER.coordinator(1).executeWithResult(cql, ConsistencyLevel.ALL);
        test.accept(result.warnings());
        test.accept(driverQueryAll(cql).getExecutionInfo().getWarnings());
        assertWarnAborts(0, 0, 0);
    }
}
Also used : TombstoneAbortException(org.apache.cassandra.exceptions.TombstoneAbortException) Arrays(java.util.Arrays) Iterables(com.google.common.collect.Iterables) SimpleStatement(com.datastax.driver.core.SimpleStatement) BeforeClass(org.junit.BeforeClass) ClientWarn(org.apache.cassandra.service.ClientWarn) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) JavaDriverUtils(org.apache.cassandra.distributed.test.JavaDriverUtils) QueryProcessor(org.apache.cassandra.cql3.QueryProcessor) InetAddress(java.net.InetAddress) ResultSet(com.datastax.driver.core.ResultSet) TestBaseImpl(org.apache.cassandra.distributed.test.TestBaseImpl) SimpleQueryResult(org.apache.cassandra.distributed.api.SimpleQueryResult) Assertions(org.assertj.core.api.Assertions) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) Before(org.junit.Before) AfterClass(org.junit.AfterClass) Feature(org.apache.cassandra.distributed.api.Feature) CoordinatorWarnings(org.apache.cassandra.service.reads.trackwarnings.CoordinatorWarnings) ImmutableSet(com.google.common.collect.ImmutableSet) QueryState(org.apache.cassandra.service.QueryState) ReadFailureException(org.apache.cassandra.exceptions.ReadFailureException) ICluster(org.apache.cassandra.distributed.api.ICluster) IOException(java.io.IOException) Test(org.junit.Test) ConsistencyLevel(org.apache.cassandra.distributed.api.ConsistencyLevel) RequestFailureReason(org.apache.cassandra.exceptions.RequestFailureReason) UnknownHostException(java.net.UnknownHostException) Consumer(java.util.function.Consumer) List(java.util.List) IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) Condition(org.assertj.core.api.Condition) Cluster(org.apache.cassandra.distributed.Cluster) Assert(org.junit.Assert) Collections(java.util.Collections) SimpleQueryResult(org.apache.cassandra.distributed.api.SimpleQueryResult) List(java.util.List)

Example 10 with SimpleQueryResult

use of org.apache.cassandra.distributed.api.SimpleQueryResult in project cassandra by apache.

the class HostReplacementAbruptDownedInstanceTest method hostReplaceAbruptShutdown.

/**
 * Can we maybe also test with an abrupt shutdown, that is when the shutdown state is not broadcast and the node to be replaced is on NORMAL state?
 */
@Test
public void hostReplaceAbruptShutdown() throws IOException {
    int numStartNodes = 3;
    TokenSupplier even = TokenSupplier.evenlyDistributedTokens(numStartNodes);
    try (Cluster cluster = Cluster.build(numStartNodes).withConfig(c -> c.with(Feature.GOSSIP, Feature.NETWORK)).withTokenSupplier(node -> even.token(node == (numStartNodes + 1) ? 2 : node)).start()) {
        IInvokableInstance seed = cluster.get(1);
        IInvokableInstance nodeToRemove = cluster.get(2);
        IInvokableInstance peer = cluster.get(3);
        List<IInvokableInstance> peers = Arrays.asList(seed, peer);
        setupCluster(cluster);
        // collect rows/tokens to detect issues later on if the state doesn't match
        SimpleQueryResult expectedState = nodeToRemove.coordinator().executeWithResult("SELECT * FROM " + KEYSPACE + ".tbl", ConsistencyLevel.ALL);
        stopAbrupt(cluster, nodeToRemove);
        // at this point node 2 should still be NORMAL on all other nodes
        peers.forEach(p -> assertRingState(p, nodeToRemove, "Normal"));
        // node is down, but queries should still work
        // TODO failing, but shouldn't!
        // peers.forEach(p -> validateRows(p.coordinator(), expectedState));
        // now create a new node to replace the other node
        long startNanos = nanoTime();
        IInvokableInstance replacingNode = replaceHostAndStart(cluster, nodeToRemove, properties -> {
            // since node2 was killed abruptly its possible that node2's gossip state has an old schema version
            // if this happens then bootstrap will fail waiting for a schema version it will never see; to avoid
            // this, setting this property to log the warning rather than fail bootstrap
            properties.set(BOOTSTRAP_SKIP_SCHEMA_CHECK, true);
        });
        logger.info("Host replacement of {} with {} took {}", nodeToRemove, replacingNode, Duration.ofNanos(nanoTime() - startNanos));
        peers.forEach(p -> awaitRingJoin(p, replacingNode));
        // make sure all nodes are healthy
        awaitRingHealthy(seed);
        List<IInvokableInstance> expectedRing = Arrays.asList(seed, peer, replacingNode);
        expectedRing.forEach(p -> assertRingIs(p, expectedRing));
        expectedRing.forEach(p -> validateRows(p.coordinator(), expectedState));
    }
}
Also used : Arrays(java.util.Arrays) Feature(org.apache.cassandra.distributed.api.Feature) Logger(org.slf4j.Logger) ClusterUtils.stopAbrupt(org.apache.cassandra.distributed.shared.ClusterUtils.stopAbrupt) HostReplacementTest.setupCluster(org.apache.cassandra.distributed.test.hostreplacement.HostReplacementTest.setupCluster) LoggerFactory(org.slf4j.LoggerFactory) ClusterUtils.awaitRingJoin(org.apache.cassandra.distributed.shared.ClusterUtils.awaitRingJoin) HostReplacementTest.validateRows(org.apache.cassandra.distributed.test.hostreplacement.HostReplacementTest.validateRows) IOException(java.io.IOException) Test(org.junit.Test) ConsistencyLevel(org.apache.cassandra.distributed.api.ConsistencyLevel) Global.nanoTime(org.apache.cassandra.utils.Clock.Global.nanoTime) BOOTSTRAP_SKIP_SCHEMA_CHECK(org.apache.cassandra.config.CassandraRelevantProperties.BOOTSTRAP_SKIP_SCHEMA_CHECK) TokenSupplier(org.apache.cassandra.distributed.api.TokenSupplier) ClusterUtils.replaceHostAndStart(org.apache.cassandra.distributed.shared.ClusterUtils.replaceHostAndStart) List(java.util.List) IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) Duration(java.time.Duration) TestBaseImpl(org.apache.cassandra.distributed.test.TestBaseImpl) SimpleQueryResult(org.apache.cassandra.distributed.api.SimpleQueryResult) Cluster(org.apache.cassandra.distributed.Cluster) ClusterUtils.assertRingState(org.apache.cassandra.distributed.shared.ClusterUtils.assertRingState) ClusterUtils.assertRingIs(org.apache.cassandra.distributed.shared.ClusterUtils.assertRingIs) ClusterUtils.awaitRingHealthy(org.apache.cassandra.distributed.shared.ClusterUtils.awaitRingHealthy) IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) SimpleQueryResult(org.apache.cassandra.distributed.api.SimpleQueryResult) TokenSupplier(org.apache.cassandra.distributed.api.TokenSupplier) HostReplacementTest.setupCluster(org.apache.cassandra.distributed.test.hostreplacement.HostReplacementTest.setupCluster) Cluster(org.apache.cassandra.distributed.Cluster) Test(org.junit.Test)

Aggregations

SimpleQueryResult (org.apache.cassandra.distributed.api.SimpleQueryResult)16 Cluster (org.apache.cassandra.distributed.Cluster)13 IInvokableInstance (org.apache.cassandra.distributed.api.IInvokableInstance)13 Test (org.junit.Test)13 IOException (java.io.IOException)12 List (java.util.List)12 ConsistencyLevel (org.apache.cassandra.distributed.api.ConsistencyLevel)12 Feature (org.apache.cassandra.distributed.api.Feature)12 TestBaseImpl (org.apache.cassandra.distributed.test.TestBaseImpl)12 Arrays (java.util.Arrays)10 Assertions (org.assertj.core.api.Assertions)8 TokenSupplier (org.apache.cassandra.distributed.api.TokenSupplier)6 ClusterUtils.assertRingIs (org.apache.cassandra.distributed.shared.ClusterUtils.assertRingIs)6 ClusterUtils.awaitRingHealthy (org.apache.cassandra.distributed.shared.ClusterUtils.awaitRingHealthy)6 ClusterUtils.awaitRingJoin (org.apache.cassandra.distributed.shared.ClusterUtils.awaitRingJoin)6 ClusterUtils.replaceHostAndStart (org.apache.cassandra.distributed.shared.ClusterUtils.replaceHostAndStart)6 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6 ResultSet (com.datastax.driver.core.ResultSet)5 SimpleStatement (com.datastax.driver.core.SimpleStatement)5