Search in sources :

Example 1 with ReadFailureException

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

the class ReadCallback method awaitResults.

public void awaitResults() throws ReadFailureException, ReadTimeoutException {
    boolean signaled = await(command.getTimeout(), TimeUnit.MILLISECONDS);
    boolean failed = blockfor + failures > endpoints.size();
    if (signaled && !failed)
        return;
    if (Tracing.isTracing()) {
        String gotData = received > 0 ? (resolver.isDataPresent() ? " (including data)" : " (only digests)") : "";
        Tracing.trace("{}; received {} of {} responses{}", new Object[] { (failed ? "Failed" : "Timed out"), received, blockfor, gotData });
    } else if (logger.isDebugEnabled()) {
        String gotData = received > 0 ? (resolver.isDataPresent() ? " (including data)" : " (only digests)") : "";
        logger.debug("{}; received {} of {} responses{}", new Object[] { (failed ? "Failed" : "Timed out"), received, blockfor, gotData });
    }
    // Same as for writes, see AbstractWriteResponseHandler
    throw failed ? new ReadFailureException(consistencyLevel, received, blockfor, resolver.isDataPresent(), failureReasonByEndpoint) : new ReadTimeoutException(consistencyLevel, received, blockfor, resolver.isDataPresent());
}
Also used : ReadFailureException(org.apache.cassandra.exceptions.ReadFailureException) ReadTimeoutException(org.apache.cassandra.exceptions.ReadTimeoutException)

Example 2 with ReadFailureException

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

the class ErrorMessageTest method testV5ReadFailureSerDeser.

@Test
public void testV5ReadFailureSerDeser() {
    int receivedBlockFor = 3;
    ConsistencyLevel consistencyLevel = ConsistencyLevel.ALL;
    boolean dataPresent = false;
    ReadFailureException rfe = new ReadFailureException(consistencyLevel, receivedBlockFor, receivedBlockFor, dataPresent, failureReasonMap1);
    ErrorMessage deserialized = serializeAndGetDeserializedErrorMessage(ErrorMessage.fromException(rfe), ProtocolVersion.V5);
    ReadFailureException deserializedRfe = (ReadFailureException) deserialized.error;
    assertEquals(failureReasonMap1, deserializedRfe.failureReasonByEndpoint);
    assertEquals(receivedBlockFor, deserializedRfe.received);
    assertEquals(receivedBlockFor, deserializedRfe.blockFor);
    assertEquals(consistencyLevel, deserializedRfe.consistency);
    assertEquals(dataPresent, deserializedRfe.dataPresent);
}
Also used : ConsistencyLevel(org.apache.cassandra.db.ConsistencyLevel) ReadFailureException(org.apache.cassandra.exceptions.ReadFailureException) ErrorMessage(org.apache.cassandra.transport.messages.ErrorMessage) Test(org.junit.Test)

Example 3 with ReadFailureException

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

the class ErrorMessageTest method testRequestFailureExceptionMakesCopy.

/**
     * Make sure that the map passed in to create a Read/WriteFailureException is copied
     * so later modifications to the map passed in don't affect the map in the exception.
     *
     * This is to prevent potential issues in serialization if the map created in
     * ReadCallback/AbstractWriteResponseHandler is modified due to a delayed failure
     * response after the exception is created.
     */
@Test
public void testRequestFailureExceptionMakesCopy() throws UnknownHostException {
    Map<InetAddress, RequestFailureReason> modifiableFailureReasons = new HashMap<>(failureReasonMap1);
    ReadFailureException rfe = new ReadFailureException(ConsistencyLevel.ALL, 3, 3, false, modifiableFailureReasons);
    WriteFailureException wfe = new WriteFailureException(ConsistencyLevel.ALL, 3, 3, WriteType.SIMPLE, modifiableFailureReasons);
    modifiableFailureReasons.put(InetAddress.getByName("127.0.0.4"), RequestFailureReason.UNKNOWN);
    assertEquals(failureReasonMap1, rfe.failureReasonByEndpoint);
    assertEquals(failureReasonMap1, wfe.failureReasonByEndpoint);
}
Also used : WriteFailureException(org.apache.cassandra.exceptions.WriteFailureException) RequestFailureReason(org.apache.cassandra.exceptions.RequestFailureReason) ReadFailureException(org.apache.cassandra.exceptions.ReadFailureException) HashMap(java.util.HashMap) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Aggregations

ReadFailureException (org.apache.cassandra.exceptions.ReadFailureException)3 Test (org.junit.Test)2 InetAddress (java.net.InetAddress)1 HashMap (java.util.HashMap)1 ConsistencyLevel (org.apache.cassandra.db.ConsistencyLevel)1 ReadTimeoutException (org.apache.cassandra.exceptions.ReadTimeoutException)1 RequestFailureReason (org.apache.cassandra.exceptions.RequestFailureReason)1 WriteFailureException (org.apache.cassandra.exceptions.WriteFailureException)1 ErrorMessage (org.apache.cassandra.transport.messages.ErrorMessage)1