use of diskCacheV111.util.FileCorruptedCacheException in project dcache by dCache.
the class HttpPoolRequestHandler method userEventTriggered.
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object event) throws Exception {
if (event instanceof IdleStateEvent) {
IdleStateEvent idleStateEvent = (IdleStateEvent) event;
if (idleStateEvent.state() == IdleState.ALL_IDLE) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Connection from {} id idle; disconnecting.", ctx.channel().remoteAddress());
}
releaseAllFiles(uploadsSeeError(new FileCorruptedCacheException("Channel idle for too long during upload.")));
ctx.close();
}
}
}
use of diskCacheV111.util.FileCorruptedCacheException in project dcache by dCache.
the class ChimeraNameSpaceProvider method commitUpload.
@Override
public FileAttributes commitUpload(Subject subject, FsPath temporaryPath, FsPath finalPath, Set<CreateOption> options, Set<FileAttribute> attributesToFetch) throws CacheException {
try {
FsPath temporaryDir = getParentOfFile(temporaryPath);
FsPath finalDir = getParentOfFile(finalPath);
checkIsTemporaryDirectory(temporaryPath, temporaryDir);
/* File must have been created...
*/
ExtendedInode uploadDirInode;
ExtendedInode temporaryDirInode;
ExtendedInode inodeOfFile;
try {
uploadDirInode = new ExtendedInode(_fs, _fs.path2inode(temporaryDir.parent().toString()));
temporaryDirInode = uploadDirInode.inodeOf(temporaryDir.name(), STAT);
inodeOfFile = temporaryDirInode.inodeOf(temporaryPath.name(), STAT);
} catch (FileNotFoundChimeraFsException e) {
throw new FileNotFoundCacheException("No such file or directory: " + temporaryPath, e);
}
/* ...and upload must have completed...
*/
ImmutableList<StorageLocatable> locations = inodeOfFile.getLocations();
if (locations.isEmpty()) {
throw new FileIsNewCacheException("Upload has not completed.");
}
/* ...and it must have the correct size.
*/
ImmutableList<String> size = inodeOfFile.getTag(TAG_EXPECTED_SIZE);
if (!size.isEmpty()) {
long expectedSize = Long.parseLong(size.get(0));
long actualSize = inodeOfFile.statCache().getSize();
if (expectedSize != actualSize) {
throw new FileCorruptedCacheException(expectedSize, actualSize);
}
}
/* Target directory must exist.
*/
ExtendedInode finalDirInode;
try {
finalDirInode = new ExtendedInode(_fs, _fs.path2inode(finalDir.toString()));
} catch (FileNotFoundChimeraFsException e) {
throw new FileNotFoundCacheException("No such file or directory: " + finalDir, e);
}
/* File must not exist unless overwrite is enabled.
*/
try {
ExtendedInode inodeOfExistingFile = finalDirInode.inodeOf(finalPath.name(), STAT);
if (!options.contains(CreateOption.OVERWRITE_EXISTING)) {
throw new FileExistsCacheException("File exists: " + finalPath);
}
/* User must be authorized to delete existing file.
*/
if (!Subjects.isExemptFromNamespaceChecks(subject)) {
FileAttributes attributesOfParent = getFileAttributesForPermissionHandler(finalDirInode);
FileAttributes attributesOfFile = getFileAttributesForPermissionHandler(inodeOfExistingFile);
if (_permissionHandler.canDeleteFile(subject, attributesOfParent, attributesOfFile) != ACCESS_ALLOWED) {
throw new PermissionDeniedCacheException("Overwrite denied: " + finalPath);
}
}
} catch (FileNotFoundChimeraFsException ignored) {
}
/* Read file attributes before moving the file. Otherwise the cached parent will
* be gone.
*/
FileAttributes attributes = getFileAttributes(inodeOfFile, attributesToFetch);
/* File is moved to correct directory.
*/
_fs.rename(inodeOfFile, temporaryDirInode, temporaryPath.name(), finalDirInode, finalPath.name());
/* Delete temporary upload directory and any files in it.
*/
removeRecursively(uploadDirInode, temporaryDir.name(), temporaryDirInode, i -> {
});
return attributes;
} catch (ChimeraFsException e) {
throw new CacheException(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, e.getMessage());
} catch (NumberFormatException e) {
throw new FileCorruptedCacheException("Failed to commit file: " + e.getMessage());
}
}
use of diskCacheV111.util.FileCorruptedCacheException in project dcache by dCache.
the class XrootdPoolRequestHandler method channelInactive.
@Override
public void channelInactive(ChannelHandlerContext ctx) {
writeLock.lock();
try {
/* close leftover descriptors */
for (FileDescriptor descriptor : _descriptors) {
if (descriptor != null) {
if (descriptor.isPersistOnSuccessfulClose()) {
removeDescriptorAtomically(descriptor);
descriptor.getChannel().release(new FileCorruptedCacheException("File was opened with Persist On Successful Close and not closed."));
} else if (descriptor.getChannel().getIoMode().contains(StandardOpenOption.WRITE)) {
removeDescriptorAtomically(descriptor);
descriptor.getChannel().release(new CacheException("Client disconnected without closing file."));
} else if (!descriptor.getChannel().getIoMode().contains(StandardOpenOption.READ)) {
descriptor.getChannel().release();
} else {
/*
* Because IO stall during a read may trigger the xrootd client
* to attempt, after a timeout, to reconnect by opening another socket,
* we would like not to reject it on the basis of a missing mover. Thus in the
* case that the file descriptor maps to a READ mover channel, we leave the
* mover in the map held by the transfer service. We start a timer
* in case there is no reconnect, in which case the channel is then released.
*/
_server.scheduleReconnectTimerForMover(descriptor);
_log.debug("{} channeInactive, starting timer for reconnect with mover {}.", ctx.channel(), descriptor.getChannel().getMoverUuid());
}
}
}
} finally {
writeLock.unlock();
;
}
}
use of diskCacheV111.util.FileCorruptedCacheException in project dcache by dCache.
the class Storage method putDone.
@Override
public void putDone(SRMUser user, String localTransferPath, URI surl, boolean overwrite) throws SRMException {
try {
Subject subject = asDcacheUser(user).getSubject();
Restriction restriction = asDcacheUser(user).getRestriction();
FsPath fullPath = getPath(surl);
checkNonBrokenUpload(localTransferPath);
EnumSet<CreateOption> options = EnumSet.noneOf(CreateOption.class);
if (overwrite) {
options.add(CreateOption.OVERWRITE_EXISTING);
}
PnfsCommitUpload msg = new PnfsCommitUpload(subject, restriction, FsPath.create(localTransferPath), fullPath, options, EnumSet.of(PNFSID, SIZE, STORAGEINFO));
msg = _pnfsStub.sendAndWait(msg);
DoorRequestInfoMessage infoMsg = new DoorRequestInfoMessage(getCellAddress());
infoMsg.setSubject(subject);
infoMsg.setBillingPath(fullPath.toString());
infoMsg.setTransferPath(localTransferPath);
infoMsg.setTransaction(CDC.getSession());
infoMsg.setPnfsId(msg.getFileAttributes().getPnfsId());
infoMsg.setResult(0, "");
infoMsg.setFileSize(msg.getFileAttributes().getSizeIfPresent().orElse(0L));
infoMsg.setStorageInfo(msg.getFileAttributes().getStorageInfo());
Origin origin = Subjects.getOrigin(subject);
if (origin != null) {
infoMsg.setClient(origin.getAddress().getHostAddress());
}
_billingStub.notify(infoMsg);
} catch (FileNotFoundCacheException e) {
throw new SRMInvalidPathException(e.getMessage(), e);
} catch (FileIsNewCacheException | FileCorruptedCacheException e) {
throw new SRMException(e.getMessage(), e);
} catch (PermissionDeniedCacheException e) {
throw new SRMAuthorizationException("Permission denied.", e);
} catch (FileExistsCacheException e) {
throw new SRMDuplicationException(surl + " exists.", e);
} catch (CacheException e) {
throw new SRMInternalErrorException(e.getMessage(), e);
} catch (InterruptedException e) {
throw new SRMInternalErrorException("Operation interrupted", e);
} catch (NoRouteToCellException e) {
throw new SRMInternalErrorException("Internal communication failure", e);
}
}
use of diskCacheV111.util.FileCorruptedCacheException in project dcache by dCache.
the class ReplicaRepository method openEntry.
@Override
public ReplicaDescriptor openEntry(PnfsId id, Set<? extends OpenOption> flags) throws CacheException {
_stateLock.readLock().lock();
try {
checkInitialized();
FileAttributes fileAttributes;
ReplicaRecord entry = getReplicaRecord(id);
synchronized (entry) {
switch(entry.getState()) {
case NEW:
case FROM_CLIENT:
case FROM_STORE:
case FROM_POOL:
throw new LockedCacheException("File is incomplete");
case BROKEN:
throw new FileCorruptedCacheException("File is broken");
case REMOVED:
case DESTROYED:
throw new LockedCacheException("File has been removed");
case PRECIOUS:
case CACHED:
break;
}
fileAttributes = entry.getFileAttributes();
if (!flags.contains(OpenFlags.NOATIME)) {
entry.setLastAccessTime(System.currentTimeMillis());
}
entry.incrementLinkCount();
}
// Here we assume that all client-drive activity can (potentially)
// update the file's atime (hence does not have NOATIME flag), while
// all dCache-internal activity cannot (hence has NOATIME flag).
boolean isInternalActivity = flags.contains(OpenFlags.NOATIME);
return new ReadHandleImpl(_pnfs, entry, fileAttributes, isInternalActivity);
} catch (FileNotInCacheException e) {
/* Somebody got the idea that we have the file, so we make
* sure to remove any stray pointers.
*/
try {
ReplicaRecord entry = _store.create(id, EnumSet.noneOf(OpenFlags.class));
entry.update("Removing replica created to recover from unknown open request", r -> r.setState(REMOVED));
} catch (DuplicateEntryException concurrentCreation) {
return openEntry(id, flags);
} catch (CacheException | RuntimeException f) {
e.addSuppressed(f);
}
throw e;
} finally {
_stateLock.readLock().unlock();
}
}
Aggregations