Search in sources :

Example 1 with ReadSizeAbortException

use of org.apache.cassandra.exceptions.ReadSizeAbortException in project cassandra by apache.

the class AbstractClientSizeWarning method failThreshold.

public void failThreshold(String cql) throws UnknownHostException {
    ICoordinator node = CLUSTER.coordinator(1);
    for (int i = 0; i < failThresholdRowCount(); i++) node.execute("INSERT INTO " + KEYSPACE + ".tbl (pk, ck, v) VALUES (1, ?, ?)", ConsistencyLevel.ALL, i + 1, bytes(512));
    if (shouldFlush())
        CLUSTER.stream().forEach(i -> i.flush(KEYSPACE));
    enable(true);
    checkpointHistogram();
    List<String> warnings = CLUSTER.get(1).callsOnInstance(() -> {
        ClientWarn.instance.captureWarnings();
        CoordinatorWarnings.init();
        try {
            QueryProcessor.execute(cql, org.apache.cassandra.db.ConsistencyLevel.ALL, QueryState.forInternalCalls());
            Assert.fail("Expected query failure");
        } catch (ReadSizeAbortException e) {
        // expected, client transport returns an error message and includes client warnings
        }
        CoordinatorWarnings.done();
        CoordinatorWarnings.reset();
        return ClientWarn.instance.getWarnings();
    }).call();
    assertAbortWarnings(warnings);
    assertHistogramUpdated();
    assertWarnAborts(0, 1, 1);
    try {
        driverQueryAll(cql);
        Assert.fail("Query should have thrown ReadFailureException");
    } catch (com.datastax.driver.core.exceptions.ReadFailureException e) {
        // without changing the client can't produce a better message...
        // client does NOT include the message sent from the server in the exception; so the message doesn't work
        // well in this case
        assertThat(e.getMessage()).contains("responses were required but only 0 replica responded");
        ImmutableSet<InetAddress> expectedKeys = ImmutableSet.of(InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 }), InetAddress.getByAddress(new byte[] { 127, 0, 0, 2 }), InetAddress.getByAddress(new byte[] { 127, 0, 0, 3 }));
        assertThat(e.getFailuresMap()).hasSizeBetween(1, 3).containsValue(RequestFailureReason.READ_SIZE.code).hasKeySatisfying(new Condition<InetAddress>() {

            public boolean matches(InetAddress value) {
                return expectedKeys.contains(value);
            }
        });
    }
    assertHistogramUpdated();
    assertWarnAborts(0, 2, 1);
    // query should no longer fail
    enable(false);
    SimpleQueryResult result = node.executeWithResult(cql, ConsistencyLevel.ALL);
    assertThat(result.warnings()).isEmpty();
    assertHistogramNotUpdated();
    assertThat(driverQueryAll(cql).getExecutionInfo().getWarnings()).isEmpty();
    assertHistogramNotUpdated();
    assertWarnAborts(0, 2, 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) Condition(org.assertj.core.api.Condition) ICoordinator(org.apache.cassandra.distributed.api.ICoordinator) SimpleQueryResult(org.apache.cassandra.distributed.api.SimpleQueryResult) ReadSizeAbortException(org.apache.cassandra.exceptions.ReadSizeAbortException) ImmutableSet(com.google.common.collect.ImmutableSet) InetAddress(java.net.InetAddress)

Aggregations

ResultSet (com.datastax.driver.core.ResultSet)1 SimpleStatement (com.datastax.driver.core.SimpleStatement)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 ByteBuffer (java.nio.ByteBuffer)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Random (java.util.Random)1 Consumer (java.util.function.Consumer)1 DatabaseDescriptor (org.apache.cassandra.config.DatabaseDescriptor)1 QueryProcessor (org.apache.cassandra.cql3.QueryProcessor)1 Cluster (org.apache.cassandra.distributed.Cluster)1 ConsistencyLevel (org.apache.cassandra.distributed.api.ConsistencyLevel)1 Feature (org.apache.cassandra.distributed.api.Feature)1 ICluster (org.apache.cassandra.distributed.api.ICluster)1 ICoordinator (org.apache.cassandra.distributed.api.ICoordinator)1 IInvokableInstance (org.apache.cassandra.distributed.api.IInvokableInstance)1