Search in sources :

Example 6 with BlobShard

use of io.crate.blob.v2.BlobShard in project crate by crate.

the class HttpBlobHandler method head.

private void head(String index, String digest) throws IOException {
    // this method only supports local mode, which is ok, since there
    // should be a redirect upfront if data is not local
    BlobShard blobShard = localBlobShard(index, digest);
    long length = blobShard.blobContainer().getFile(digest).length();
    if (length < 1) {
        simpleResponse(HttpResponseStatus.NOT_FOUND);
        return;
    }
    HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
    HttpHeaders.setContentLength(response, length);
    setDefaultGetHeaders(response);
    sendResponse(response);
}
Also used : BlobShard(io.crate.blob.v2.BlobShard)

Example 7 with BlobShard

use of io.crate.blob.v2.BlobShard 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)

Example 8 with BlobShard

use of io.crate.blob.v2.BlobShard in project crate by crate.

the class TransportDeleteBlobAction method shardOperationOnPrimary.

@Override
protected Tuple<DeleteBlobResponse, DeleteBlobRequest> shardOperationOnPrimary(MetaData metaData, DeleteBlobRequest request) throws Throwable {
    logger.trace("shardOperationOnPrimary {}", request);
    BlobShard blobShard = blobIndicesService.blobShardSafe(request.shardId());
    boolean deleted = blobShard.delete(request.id());
    final DeleteBlobResponse response = new DeleteBlobResponse(deleted);
    return new Tuple<>(response, request);
}
Also used : BlobShard(io.crate.blob.v2.BlobShard) Tuple(org.elasticsearch.common.collect.Tuple)

Aggregations

BlobShard (io.crate.blob.v2.BlobShard)8 RandomAccessFile (java.io.RandomAccessFile)2 DigestMismatchException (io.crate.blob.exceptions.DigestMismatchException)1 BlobInfoRequest (io.crate.blob.pending_transfer.BlobInfoRequest)1 BlobTransferInfoResponse (io.crate.blob.pending_transfer.BlobTransferInfoResponse)1 GetBlobHeadRequest (io.crate.blob.pending_transfer.GetBlobHeadRequest)1 BlobAdminClient (io.crate.blob.v2.BlobAdminClient)1 BlobIndicesService (io.crate.blob.v2.BlobIndicesService)1 File (java.io.File)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Matcher (java.util.regex.Matcher)1 ClusterHealthResponse (org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse)1 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)1 DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)1 MoveAllocationCommand (org.elasticsearch.cluster.routing.allocation.command.MoveAllocationCommand)1 Tuple (org.elasticsearch.common.collect.Tuple)1 Settings (org.elasticsearch.common.settings.Settings)1 ShardId (org.elasticsearch.index.shard.ShardId)1