Search in sources :

Example 1 with TooManyStreamsException

use of com.twitter.distributedlog.exceptions.TooManyStreamsException 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)

Aggregations

RegionUnavailableException (com.twitter.distributedlog.exceptions.RegionUnavailableException)1 ServiceUnavailableException (com.twitter.distributedlog.exceptions.ServiceUnavailableException)1 StreamUnavailableException (com.twitter.distributedlog.exceptions.StreamUnavailableException)1 TooManyStreamsException (com.twitter.distributedlog.exceptions.TooManyStreamsException)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 IOException (java.io.IOException)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1