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);
}
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());
}
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);
}
Aggregations