Search in sources :

Example 1 with DigestMismatchException

use of io.crate.blob.exceptions.DigestMismatchException in project crate by crate.

the class HttpBlobHandler method exceptionCaught.

@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
    Throwable ex = e.getCause();
    if (ex instanceof ClosedChannelException) {
        LOGGER.trace("channel closed: {}", ex.toString());
        return;
    } else if (ex instanceof IOException) {
        String message = ex.getMessage();
        if (message != null && message.contains("Connection reset by peer")) {
            LOGGER.debug(message);
        } else {
            LOGGER.warn(message, e);
        }
        return;
    }
    HttpResponseStatus status;
    String body = null;
    if (ex instanceof DigestMismatchException || ex instanceof BlobsDisabledException || ex instanceof IllegalArgumentException) {
        status = HttpResponseStatus.BAD_REQUEST;
        body = String.format(Locale.ENGLISH, "Invalid request sent: %s", ex.getMessage());
    } else if (ex instanceof DigestNotFoundException || ex instanceof IndexNotFoundException) {
        status = HttpResponseStatus.NOT_FOUND;
    } else if (ex instanceof EsRejectedExecutionException) {
        status = TOO_MANY_REQUESTS;
        body = String.format(Locale.ENGLISH, "Rejected execution: %s", ex.getMessage());
    } else {
        status = HttpResponseStatus.INTERNAL_SERVER_ERROR;
        body = String.format(Locale.ENGLISH, "Unhandled exception: %s", ex);
    }
    if (body != null) {
        LOGGER.debug(body);
    }
    simpleResponse(status, body);
}
Also used : ClosedChannelException(java.nio.channels.ClosedChannelException) DigestNotFoundException(io.crate.blob.exceptions.DigestNotFoundException) HttpResponseStatus(org.jboss.netty.handler.codec.http.HttpResponseStatus) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) DigestMismatchException(io.crate.blob.exceptions.DigestMismatchException) IOException(java.io.IOException) BlobsDisabledException(io.crate.blob.v2.BlobsDisabledException) EsRejectedExecutionException(org.elasticsearch.common.util.concurrent.EsRejectedExecutionException)

Example 2 with DigestMismatchException

use of io.crate.blob.exceptions.DigestMismatchException in project crate by crate.

the class BlobTransferTarget method startTransfer.

public void startTransfer(StartBlobRequest request, StartBlobResponse response) {
    logger.debug("startTransfer {} {}", request.transferId(), request.isLast());
    BlobShard blobShard = blobIndicesService.blobShardSafe(request.shardId());
    File existing = blobShard.blobContainer().getFile(request.id());
    long size = existing.length();
    if (existing.exists()) {
        // the file exists
        response.status(RemoteDigestBlob.Status.EXISTS);
        response.size(size);
        return;
    }
    DigestBlob digestBlob = blobShard.blobContainer().createBlob(request.id(), request.transferId());
    digestBlob.addContent(request.content(), request.isLast());
    response.size(digestBlob.size());
    if (request.isLast()) {
        try {
            digestBlob.commit();
            response.status(RemoteDigestBlob.Status.FULL);
        } catch (DigestMismatchException e) {
            response.status(RemoteDigestBlob.Status.MISMATCH);
        }
    } else {
        BlobTransferStatus status = new BlobTransferStatus(request.index(), request.transferId(), digestBlob);
        activeTransfers.put(request.transferId(), status);
        response.status(RemoteDigestBlob.Status.PARTIAL);
    }
    logger.debug("startTransfer finished {} {}", response.status(), response.size());
}
Also used : BlobShard(io.crate.blob.v2.BlobShard) DigestMismatchException(io.crate.blob.exceptions.DigestMismatchException) File(java.io.File)

Aggregations

DigestMismatchException (io.crate.blob.exceptions.DigestMismatchException)2 DigestNotFoundException (io.crate.blob.exceptions.DigestNotFoundException)1 BlobShard (io.crate.blob.v2.BlobShard)1 BlobsDisabledException (io.crate.blob.v2.BlobsDisabledException)1 File (java.io.File)1 IOException (java.io.IOException)1 ClosedChannelException (java.nio.channels.ClosedChannelException)1 EsRejectedExecutionException (org.elasticsearch.common.util.concurrent.EsRejectedExecutionException)1 IndexNotFoundException (org.elasticsearch.index.IndexNotFoundException)1 HttpResponseStatus (org.jboss.netty.handler.codec.http.HttpResponseStatus)1