Search in sources :

Example 1 with ConnectionFailedException

use of com.twitter.finagle.ConnectionFailedException in project distributedlog by twitter.

the class DistributedLogClientImpl method handleRequestException.

void handleRequestException(SocketAddress addr, ProxyClient sc, Optional<StreamOp> op, Throwable cause) {
    boolean resendOp = false;
    boolean removeOwnerFromStream = false;
    SocketAddress previousAddr = addr;
    String reason = cause.getMessage();
    if (cause instanceof ConnectionFailedException || cause instanceof java.net.ConnectException) {
        routingService.removeHost(addr, cause);
        onServerLeft(addr, sc);
        removeOwnerFromStream = true;
        // redirect the request to other host.
        resendOp = true;
    } else if (cause instanceof ChannelException) {
        // no process listening on remote address/port.
        if (cause.getCause() instanceof java.net.ConnectException) {
            routingService.removeHost(addr, cause.getCause());
            onServerLeft(addr);
            reason = cause.getCause().getMessage();
        } else {
            routingService.removeHost(addr, cause);
            reason = cause.getMessage();
        }
        removeOwnerFromStream = true;
        // redirect the request to other host.
        resendOp = true;
    } else if (cause instanceof ServiceTimeoutException) {
        // redirect the request to itself again, which will backoff for a while
        resendOp = true;
        previousAddr = null;
    } else if (cause instanceof WriteException) {
        // redirect the request to other host.
        resendOp = true;
    } else if (cause instanceof ServiceException) {
        // redirect the request to other host.
        clientManager.removeClient(addr, sc);
        resendOp = true;
    } else if (cause instanceof TApplicationException) {
        handleTApplicationException(cause, op, addr, sc);
    } else if (cause instanceof Failure) {
        handleFinagleFailure((Failure) cause, op, addr);
    } else {
        // Default handler
        handleException(cause, op, addr);
    }
    if (op.isPresent()) {
        if (removeOwnerFromStream) {
            ownershipCache.removeOwnerFromStream(op.get().stream, addr, reason);
        }
        if (resendOp) {
            doSend(op.get(), previousAddr);
        }
    }
}
Also used : WriteException(com.twitter.finagle.WriteException) ServiceException(com.twitter.finagle.ServiceException) SocketAddress(java.net.SocketAddress) DLSocketAddress(com.twitter.distributedlog.service.DLSocketAddress) ServiceTimeoutException(com.twitter.finagle.ServiceTimeoutException) ConnectionFailedException(com.twitter.finagle.ConnectionFailedException) Failure(com.twitter.finagle.Failure) ChannelException(org.jboss.netty.channel.ChannelException) TApplicationException(org.apache.thrift.TApplicationException)

Aggregations

DLSocketAddress (com.twitter.distributedlog.service.DLSocketAddress)1 ConnectionFailedException (com.twitter.finagle.ConnectionFailedException)1 Failure (com.twitter.finagle.Failure)1 ServiceException (com.twitter.finagle.ServiceException)1 ServiceTimeoutException (com.twitter.finagle.ServiceTimeoutException)1 WriteException (com.twitter.finagle.WriteException)1 SocketAddress (java.net.SocketAddress)1 TApplicationException (org.apache.thrift.TApplicationException)1 ChannelException (org.jboss.netty.channel.ChannelException)1