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