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);
}
}
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();
}
}
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);
}
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();
}
}
Aggregations