Search in sources :

Example 1 with StageRequest

use of org.dcache.pool.nearline.spi.StageRequest in project dcache by dCache.

the class AbstractBlockingNearlineStorage method stage.

@Override
public void stage(Iterable<StageRequest> requests) {
    for (StageRequest request : requests) {
        Task<StageRequest, Set<Checksum>> task = new Task<StageRequest, Set<Checksum>>(request) {

            @Override
            public Set<Checksum> call() throws Exception {
                FileAttributes attributes = request.getFileAttributes();
                NDC.push(attributes.getPnfsId().toString());
                try {
                    request.allocate().get();
                    return stage(request);
                } finally {
                    NDC.pop();
                }
            }

            @Override
            protected void execute() {
                getStageExecutor().execute(this);
            }
        };
        task.execute();
    }
}
Also used : Set(java.util.Set) StageRequest(org.dcache.pool.nearline.spi.StageRequest) Checksum(org.dcache.util.Checksum) FileAttributes(org.dcache.vehicles.FileAttributes)

Example 2 with StageRequest

use of org.dcache.pool.nearline.spi.StageRequest in project dcache-cta by dCache.

the class DataServerHandler method doOnOpen.

/**
 * Obtains the right mover instance using an opaque token in the request and instruct the mover
 * to open the file in the request. Associates the mover with the file-handle that is produced
 * during processing
 */
@Override
protected OpenResponse doOnOpen(ChannelHandlerContext ctx, OpenRequest msg) throws XrootdException {
    try {
        var pr = getIORequest(msg.getPath());
        var r = pr.getRequest();
        var file = getFile(r);
        LOGGER.info("Request {} scheduling time: {}", file, TimeUtils.describe(Duration.between(Instant.now(), pr.getSubmissionTime()).abs()).orElse("-"));
        RandomAccessFile raf;
        if (msg.isReadWrite() || msg.isNew() || msg.isDelete()) {
            if (!(r instanceof StageRequest)) {
                throw new XrootdException(kXR_ArgInvalid, "An attempt to open-for-read for stage requests");
            }
            LOGGER.info("Opening {} for writing", file);
            raf = new RandomAccessFile(file, "rw");
            if (msg.isDelete()) {
                raf.setLength(0);
            }
        } else {
            if (!(r instanceof FlushRequest)) {
                throw new XrootdException(kXR_ArgInvalid, "An attempt to open-for-write for flush requests");
            }
            LOGGER.info("Opening {} for reading.", file);
            raf = new RandomAccessFile(file, "r");
        }
        FileStatus stat = null;
        if (msg.isRetStat()) {
            stat = statusByFile(file);
        }
        var migrationRequest = new MigrationRequest(r, raf);
        int fd = addOpenFile(migrationRequest);
        return new OpenResponse(msg, fd, null, null, stat);
    } catch (FileNotFoundException e) {
        throw new XrootdException(kXR_NotFound, e.getMessage());
    } catch (IOException e) {
        throw new XrootdException(kXR_IOError, e.getMessage());
    }
}
Also used : FileStatus(org.dcache.xrootd.util.FileStatus) RandomAccessFile(java.io.RandomAccessFile) StageRequest(org.dcache.pool.nearline.spi.StageRequest) FlushRequest(org.dcache.pool.nearline.spi.FlushRequest) OpenResponse(org.dcache.xrootd.protocol.messages.OpenResponse) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) XrootdException(org.dcache.xrootd.core.XrootdException)

Example 3 with StageRequest

use of org.dcache.pool.nearline.spi.StageRequest in project dcache-cta by dCache.

the class DataServerHandler method doOnClose.

/**
 * Retrieves the right descriptor based on the request's file-handle and invokes its close
 * information.
 *
 * @param ctx received from the netty pipeline
 * @param msg The actual request
 */
@Override
protected OkResponse<CloseRequest> doOnClose(ChannelHandlerContext ctx, CloseRequest msg) throws XrootdException {
    try {
        var migrationRequest = getAndRemoveOpenFile(msg.getFileHandle());
        migrationRequest.raf().close();
        var r = migrationRequest.request();
        var file = getFile(r);
        long size = file.length();
        long duration = Duration.between(migrationRequest.getCreationTime(), Instant.now()).toMillis();
        double bandwidth = (double) size / duration;
        LOGGER.info("Closing file {}. Transferred {} in {}, {}", file, Strings.humanReadableSize(size), TimeUtils.describeDuration(duration, TimeUnit.MILLISECONDS), Strings.describeBandwidth(bandwidth * 1000));
        if (r instanceof StageRequest) {
            ForkJoinPool.commonPool().execute(() -> {
                try {
                    Checksum checksum = calculateChecksum(file);
                    LOGGER.info("Files {} checksum after restore: {}", file, checksum);
                    r.completed(Set.of(checksum));
                } catch (IOException e) {
                    LOGGER.error("Post-restore checksum calculation of {} failed: {}", file, e.getMessage());
                    r.failed(e);
                }
            });
        }
        return withOk(msg);
    } catch (IOException e) {
        throw new XrootdException(kXR_IOError, e.getMessage());
    }
}
Also used : StageRequest(org.dcache.pool.nearline.spi.StageRequest) Checksum(org.dcache.util.Checksum) IOException(java.io.IOException) XrootdException(org.dcache.xrootd.core.XrootdException)

Example 4 with StageRequest

use of org.dcache.pool.nearline.spi.StageRequest in project dcache by dCache.

the class TarNearlineStorage method stage.

@Override
public void stage(Iterable<StageRequest> requests) {
    for (StageRequest request : requests) {
        File tarFile;
        try {
            FileAttributes fileAttributes = request.getFileAttributes();
            URI location = getFirst(getLocations(fileAttributes), null);
            if (location == null) {
                throw new CacheException(CacheException.BROKEN_ON_TAPE, "File not on nearline storage: " + fileAttributes.getPnfsId());
            }
            String path = location.getPath();
            if (path == null) {
                throw new InvalidMessageCacheException("Invalid nearline storage URI: " + location);
            }
            tarFile = new File(path).getParentFile();
            if (tarFile == null) {
                throw new InvalidMessageCacheException("Invalid nearline storage URI: " + location);
            }
        } catch (CacheException e) {
            request.failed(e);
            continue;
        }
        stageRequests.put(tarFile.getName(), request);
    }
    executor.execute(new StageTask());
}
Also used : StageRequest(org.dcache.pool.nearline.spi.StageRequest) CacheException(diskCacheV111.util.CacheException) InvalidMessageCacheException(diskCacheV111.util.InvalidMessageCacheException) InvalidMessageCacheException(diskCacheV111.util.InvalidMessageCacheException) File(java.io.File) FileAttributes(org.dcache.vehicles.FileAttributes) URI(java.net.URI)

Aggregations

StageRequest (org.dcache.pool.nearline.spi.StageRequest)4 IOException (java.io.IOException)2 Checksum (org.dcache.util.Checksum)2 FileAttributes (org.dcache.vehicles.FileAttributes)2 XrootdException (org.dcache.xrootd.core.XrootdException)2 CacheException (diskCacheV111.util.CacheException)1 InvalidMessageCacheException (diskCacheV111.util.InvalidMessageCacheException)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 RandomAccessFile (java.io.RandomAccessFile)1 URI (java.net.URI)1 Set (java.util.Set)1 FlushRequest (org.dcache.pool.nearline.spi.FlushRequest)1 OpenResponse (org.dcache.xrootd.protocol.messages.OpenResponse)1 FileStatus (org.dcache.xrootd.util.FileStatus)1