Search in sources :

Example 1 with ServiceUnavailableException

use of com.twitter.distributedlog.exceptions.ServiceUnavailableException in project distributedlog by twitter.

the class DistributedLogClientImpl method handleServiceUnavailable.

void handleServiceUnavailable(SocketAddress addr, ProxyClient sc, Optional<StreamOp> op) {
    // service is unavailable, remove it out of routing service
    routingService.removeHost(addr, new ServiceUnavailableException(addr + " is unavailable now."));
    onServerLeft(addr);
    if (op.isPresent()) {
        ownershipCache.removeOwnerFromStream(op.get().stream, addr, addr + " is unavailable now.");
        // redirect the request to other host.
        redirect(op.get(), null);
    }
}
Also used : ServiceUnavailableException(com.twitter.distributedlog.exceptions.ServiceUnavailableException)

Example 2 with ServiceUnavailableException

use of com.twitter.distributedlog.exceptions.ServiceUnavailableException in project distributedlog by twitter.

the class DistributedLogServiceImpl method executeStreamOp.

private void executeStreamOp(final StreamOp op) {
    // Must attach this as early as possible--returning before this point will cause us to
    // lose the status code.
    op.responseHeader().addEventListener(new FutureEventListener<ResponseHeader>() {

        @Override
        public void onSuccess(ResponseHeader header) {
            if (header.getLocation() != null || header.getCode() == StatusCode.FOUND) {
                redirects.inc();
            }
            countStatusCode(header.getCode());
        }

        @Override
        public void onFailure(Throwable cause) {
        }
    });
    try {
        // Apply the request limiter
        limiter.apply(op);
        // Execute per-op pre-exec code
        op.preExecute();
    } catch (TooManyStreamsException e) {
        // Translate to StreamUnavailableException to ensure that the client will redirect
        // to a different host. Ideally we would be able to return TooManyStreamsException,
        // but the way exception handling works right now we can't control the handling in
        // the client because client changes deploy very slowly.
        op.fail(new StreamUnavailableException(e.getMessage()));
        return;
    } catch (Exception e) {
        op.fail(e);
        return;
    }
    Stream stream;
    try {
        stream = getLogWriter(op.streamName());
    } catch (RegionUnavailableException rue) {
        // redirect the requests to other region
        op.fail(new RegionUnavailableException("Region " + serverRegionId + " is unavailable."));
        return;
    } catch (IOException e) {
        op.fail(e);
        return;
    }
    if (null == stream) {
        // redirect the requests when stream is unavailable.
        op.fail(new ServiceUnavailableException("Server " + clientId + " is closed."));
        return;
    }
    if (op instanceof WriteOpWithPayload) {
        WriteOpWithPayload writeOp = (WriteOpWithPayload) op;
        windowedBps.add(writeOp.getPayloadSize());
        windowedRps.inc();
    }
    stream.submit(op);
}
Also used : StreamUnavailableException(com.twitter.distributedlog.exceptions.StreamUnavailableException) WriteOpWithPayload(com.twitter.distributedlog.service.stream.WriteOpWithPayload) ResponseHeader(com.twitter.distributedlog.thrift.service.ResponseHeader) RegionUnavailableException(com.twitter.distributedlog.exceptions.RegionUnavailableException) TooManyStreamsException(com.twitter.distributedlog.exceptions.TooManyStreamsException) Stream(com.twitter.distributedlog.service.stream.Stream) IOException(java.io.IOException) ServiceUnavailableException(com.twitter.distributedlog.exceptions.ServiceUnavailableException) ServiceUnavailableException(com.twitter.distributedlog.exceptions.ServiceUnavailableException) StreamUnavailableException(com.twitter.distributedlog.exceptions.StreamUnavailableException) RegionUnavailableException(com.twitter.distributedlog.exceptions.RegionUnavailableException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) IOException(java.io.IOException) TooManyStreamsException(com.twitter.distributedlog.exceptions.TooManyStreamsException)

Example 3 with ServiceUnavailableException

use of com.twitter.distributedlog.exceptions.ServiceUnavailableException in project distributedlog by twitter.

the class StreamManagerImpl method closeAndRemoveAsync.

/**
     * Must be enqueued to an executor to avoid deadlocks (close and execute-op both
     * try to acquire the same read-write lock).
     */
@Override
public Future<Void> closeAndRemoveAsync(final String streamName) {
    final Promise<Void> releasePromise = new Promise<Void>();
    java.util.concurrent.Future<?> scheduleFuture = schedule(new Runnable() {

        @Override
        public void run() {
            releasePromise.become(doCloseAndRemoveAsync(streamName));
        }
    }, 0);
    if (null == scheduleFuture) {
        return Future.exception(new ServiceUnavailableException("Couldn't schedule a release task."));
    }
    return releasePromise;
}
Also used : Promise(com.twitter.util.Promise) ServiceUnavailableException(com.twitter.distributedlog.exceptions.ServiceUnavailableException)

Example 4 with ServiceUnavailableException

use of com.twitter.distributedlog.exceptions.ServiceUnavailableException in project distributedlog by twitter.

the class StreamManagerImpl method deleteAndRemoveAsync.

/**
     * Must be enqueued to an executor to avoid deadlocks (close and execute-op both
     * try to acquire the same read-write lock).
     */
@Override
public Future<Void> deleteAndRemoveAsync(final String stream) {
    final Promise<Void> result = new Promise<Void>();
    java.util.concurrent.Future<?> scheduleFuture = schedule(new Runnable() {

        @Override
        public void run() {
            result.become(doDeleteAndRemoveAsync(stream));
        }
    }, 0);
    if (null == scheduleFuture) {
        return Future.exception(new ServiceUnavailableException("Couldn't schedule a delete task."));
    }
    return result;
}
Also used : Promise(com.twitter.util.Promise) ServiceUnavailableException(com.twitter.distributedlog.exceptions.ServiceUnavailableException)

Example 5 with ServiceUnavailableException

use of com.twitter.distributedlog.exceptions.ServiceUnavailableException in project distributedlog by twitter.

the class StreamManagerImpl method createStreamAsync.

@Override
public Future<Void> createStreamAsync(final String stream) {
    final Promise<Void> createPromise = new Promise<Void>();
    java.util.concurrent.Future<?> scheduleFuture = schedule(new Runnable() {

        @Override
        public void run() {
            try {
                dlNamespace.createLog(stream);
                createPromise.setValue(null);
            } catch (Exception e) {
                createPromise.setException(e);
            }
        }
    }, 0);
    if (null == scheduleFuture) {
        return Future.exception(new ServiceUnavailableException("Couldn't schedule a create task."));
    }
    return createPromise;
}
Also used : Promise(com.twitter.util.Promise) ServiceUnavailableException(com.twitter.distributedlog.exceptions.ServiceUnavailableException) UnexpectedException(com.twitter.distributedlog.exceptions.UnexpectedException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ServiceUnavailableException(com.twitter.distributedlog.exceptions.ServiceUnavailableException) IOException(java.io.IOException) StreamUnavailableException(com.twitter.distributedlog.exceptions.StreamUnavailableException)

Aggregations

ServiceUnavailableException (com.twitter.distributedlog.exceptions.ServiceUnavailableException)5 Promise (com.twitter.util.Promise)3 StreamUnavailableException (com.twitter.distributedlog.exceptions.StreamUnavailableException)2 IOException (java.io.IOException)2 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)2 RegionUnavailableException (com.twitter.distributedlog.exceptions.RegionUnavailableException)1 TooManyStreamsException (com.twitter.distributedlog.exceptions.TooManyStreamsException)1 UnexpectedException (com.twitter.distributedlog.exceptions.UnexpectedException)1 Stream (com.twitter.distributedlog.service.stream.Stream)1 WriteOpWithPayload (com.twitter.distributedlog.service.stream.WriteOpWithPayload)1 ResponseHeader (com.twitter.distributedlog.thrift.service.ResponseHeader)1