Search in sources :

Example 1 with UnavailableException

use of org.apache.cassandra.thrift.UnavailableException in project eiger by wlloyd.

the class CounterMutationVerbHandler method applyAndRespond.

protected void applyAndRespond(Message message, String id, CounterMutation cm) {
    try {
        String localDataCenter = DatabaseDescriptor.getEndpointSnitch().getDatacenter(FBUtilities.getBroadcastAddress());
        StorageProxy.applyCounterMutationOnLeader(cm, localDataCenter).get();
        WriteResponse response = new WriteResponse(cm.getTable(), cm.key(), true);
        Message responseMessage = WriteResponse.makeWriteResponseMessage(message, response);
        MessagingService.instance().sendReply(responseMessage, id, message.getFrom());
    } catch (UnavailableException e) {
    // We check for UnavailableException in the coordinator not. It is
    // hence reasonable to let the coordinator timeout in the very
    // unlikely case we arrive here
    } catch (TimeoutException e) {
    // The coordinator node will have timeout itself so we let that goes
    } catch (IOException e) {
        logger.error("Error in counter mutation", e);
    }
}
Also used : Message(org.apache.cassandra.net.Message) UnavailableException(org.apache.cassandra.thrift.UnavailableException) IOException(java.io.IOException) TimeoutException(java.util.concurrent.TimeoutException)

Example 2 with UnavailableException

use of org.apache.cassandra.thrift.UnavailableException in project eiger by wlloyd.

the class DatacenterSyncWriteResponseHandler method assureSufficientLiveNodes.

public void assureSufficientLiveNodes() throws UnavailableException {
    Map<String, AtomicInteger> dcEndpoints = new HashMap<String, AtomicInteger>();
    for (String dc : strategy.getDatacenters()) dcEndpoints.put(dc, new AtomicInteger());
    for (InetAddress destination : writeEndpoints) {
        if (FailureDetector.instance.isAlive(destination)) {
            // figure out the destination dc
            String destinationDC = snitch.getDatacenter(destination);
            dcEndpoints.get(destinationDC).incrementAndGet();
        }
    }
    // Throw exception if any of the DC doesn't have livenodes to accept write.
    for (String dc : strategy.getDatacenters()) {
        if (dcEndpoints.get(dc).get() < responses.get(dc).get())
            throw new UnavailableException();
    }
}
Also used : HashMap(java.util.HashMap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) UnavailableException(org.apache.cassandra.thrift.UnavailableException) InetAddress(java.net.InetAddress)

Example 3 with UnavailableException

use of org.apache.cassandra.thrift.UnavailableException in project scale7-pelops by s7.

the class Operand method tryOperation.

protected <ReturnType> ReturnType tryOperation(IOperation<ReturnType> operation, OperandPolicy operandPolicy) throws PelopsException {
    Set<String> avoidNodes = null;
    Exception lastException = null;
    int retries = 0;
    do {
        // Get a connection to a Cassandra node
        IPooledConnection conn = null;
        try {
            conn = thrift.getConnectionExcept(avoidNodes);
        } catch (Exception e) {
            // the pool is responsible for blocking and waiting for a connection, so don't retry
            throw operandPolicy.getExceptionTranslator().translate(e);
        }
        try {
            // Return result!
            return operation.execute(conn);
        } catch (Exception e) {
            // Should we try again?
            if (e instanceof TimedOutException || e instanceof TTransportException || e instanceof UnavailableException) {
                logger.warn("Operation failed as result of network exception. Connection to node {} is being marked as corrupt " + "(and will probably be be destroyed). Cause of failure is {}", conn.getNode().getAddress(), e);
                // This connection is "broken" by network timeout or other problem.
                conn.corrupted();
                // to avoid create the set for every request create the set here
                if (avoidNodes == null)
                    avoidNodes = new HashSet<String>(10);
                avoidNodes.add(conn.getNode().getAddress());
                retries++;
                lastException = e;
            } else if (e instanceof NotFoundException) {
                // Re-throw application-level exceptions immediately.
                throw operandPolicy.getExceptionTranslator().translate(e);
            } else {
                // This connection is "broken" by network timeout or other problem.
                conn.corrupted();
                // Re-throw application-level exceptions immediately.
                throw operandPolicy.getExceptionTranslator().translate(e);
            }
        } finally {
            conn.release();
        }
    } while (retries < operandPolicy.getMaxOpRetries());
    throw operandPolicy.getExceptionTranslator().translate(lastException);
}
Also used : TimedOutException(org.apache.cassandra.thrift.TimedOutException) UnavailableException(org.apache.cassandra.thrift.UnavailableException) TTransportException(org.apache.thrift.transport.TTransportException) NotFoundException(org.apache.cassandra.thrift.NotFoundException) TimedOutException(org.apache.cassandra.thrift.TimedOutException) PelopsException(org.scale7.cassandra.pelops.exceptions.PelopsException) UnavailableException(org.apache.cassandra.thrift.UnavailableException) TTransportException(org.apache.thrift.transport.TTransportException) NotFoundException(org.apache.cassandra.thrift.NotFoundException) IPooledConnection(org.scale7.cassandra.pelops.pool.IThriftPool.IPooledConnection)

Example 4 with UnavailableException

use of org.apache.cassandra.thrift.UnavailableException in project eiger by wlloyd.

the class DatacenterReadCallback method assureSufficientLiveNodes.

@Override
public void assureSufficientLiveNodes() throws UnavailableException {
    int localEndpoints = 0;
    for (InetAddress endpoint : endpoints) {
        if (localdc.equals(snitch.getDatacenter(endpoint)))
            localEndpoints++;
    }
    if (localEndpoints < blockfor) {
        if (logger.isDebugEnabled()) {
            StringBuilder builder = new StringBuilder("Local replicas [");
            for (InetAddress endpoint : endpoints) {
                if (localdc.equals(snitch.getDatacenter(endpoint)))
                    builder.append(endpoint).append(",");
            }
            builder.append("] are insufficient to satisfy LOCAL_QUORUM requirement of ").append(blockfor).append(" live nodes in '").append(localdc).append("'");
            logger.debug(builder.toString());
        }
        throw new UnavailableException();
    }
}
Also used : UnavailableException(org.apache.cassandra.thrift.UnavailableException) InetAddress(java.net.InetAddress)

Aggregations

UnavailableException (org.apache.cassandra.thrift.UnavailableException)4 InetAddress (java.net.InetAddress)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 TimeoutException (java.util.concurrent.TimeoutException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Message (org.apache.cassandra.net.Message)1 NotFoundException (org.apache.cassandra.thrift.NotFoundException)1 TimedOutException (org.apache.cassandra.thrift.TimedOutException)1 TTransportException (org.apache.thrift.transport.TTransportException)1 PelopsException (org.scale7.cassandra.pelops.exceptions.PelopsException)1 IPooledConnection (org.scale7.cassandra.pelops.pool.IThriftPool.IPooledConnection)1