Search in sources :

Example 1 with FileNotFoundCacheException

use of diskCacheV111.util.FileNotFoundCacheException in project dcache by dCache.

the class ConsistentReplicaStore method get.

/**
 * Retrieves a CacheRepositoryEntry from the wrapped meta data store. If the entry is missing or
 * fails consistency checks, the entry is reconstructed with information from PNFS.
 */
@Override
public ReplicaRecord get(PnfsId id) throws IllegalArgumentException, CacheException {
    ReplicaRecord entry = _replicaStore.get(id);
    if (entry != null && isBroken(entry)) {
        LOGGER.warn("Recovering {}...", id);
        try {
            /* It is safe to remove FROM_STORE/FROM_POOL replicas: We have
                 * another copy anyway. Files in REMOVED or DESTROYED
                 * were about to be deleted, so we can finish the job.
                 */
            switch(entry.getState()) {
                case FROM_POOL:
                case FROM_STORE:
                case REMOVED:
                case DESTROYED:
                    _replicaStore.remove(id);
                    _pnfsHandler.clearCacheLocation(id);
                    LOGGER.info("Recovering: Removed {} because it was not fully staged.", id);
                    return null;
            }
            entry = rebuildEntry(entry);
        } catch (IOException e) {
            throw new DiskErrorCacheException("I/O error in healer: " + messageOrClassName(e), e);
        } catch (FileNotFoundCacheException e) {
            _replicaStore.remove(id);
            LOGGER.warn("Recovering: Removed {} because name space entry was deleted.", id);
            return null;
        } catch (FileIsNewCacheException e) {
            _replicaStore.remove(id);
            LOGGER.warn("Recovering: Removed {}: {}", id, e.getMessage());
            return null;
        } catch (TimeoutCacheException e) {
            throw e;
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new CacheException("Pool is shutting down", e);
        } catch (CacheException | NoSuchAlgorithmException e) {
            entry.update("Failed to recover replica: " + e.getMessage(), r -> r.setState(ReplicaState.BROKEN));
            LOGGER.error(AlarmMarkerFactory.getMarker(PredefinedAlarm.BROKEN_FILE, id.toString(), _poolName), "Marked {} bad: {}.", id, e.getMessage());
        }
    }
    return entry;
}
Also used : AlarmMarkerFactory(org.dcache.alarms.AlarmMarkerFactory) ReplicaStatePolicy(org.dcache.pool.classic.ReplicaStatePolicy) FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) AccessLatency(diskCacheV111.util.AccessLatency) PredefinedAlarm(org.dcache.alarms.PredefinedAlarm) LoggerFactory(org.slf4j.LoggerFactory) Exceptions.messageOrClassName(org.dcache.util.Exceptions.messageOrClassName) DiskErrorCacheException(diskCacheV111.util.DiskErrorCacheException) RETENTION_POLICY(org.dcache.namespace.FileAttribute.RETENTION_POLICY) PnfsHandler(diskCacheV111.util.PnfsHandler) CacheException(diskCacheV111.util.CacheException) Iterables.concat(com.google.common.collect.Iterables.concat) SIZE(org.dcache.namespace.FileAttribute.SIZE) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) EnumSet(java.util.EnumSet) ChecksumModule(org.dcache.pool.classic.ChecksumModule) FileAttributes(org.dcache.vehicles.FileAttributes) STORAGEINFO(org.dcache.namespace.FileAttribute.STORAGEINFO) PnfsId(diskCacheV111.util.PnfsId) Logger(org.slf4j.Logger) OpenOption(java.nio.file.OpenOption) LOCATIONS(org.dcache.namespace.FileAttribute.LOCATIONS) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException) Set(java.util.Set) IOException(java.io.IOException) Sets(com.google.common.collect.Sets) Checksum(org.dcache.util.Checksum) List(java.util.List) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) FileAttribute(org.dcache.namespace.FileAttribute) Collections(java.util.Collections) ACCESS_LATENCY(org.dcache.namespace.FileAttribute.ACCESS_LATENCY) CHECKSUM(org.dcache.namespace.FileAttribute.CHECKSUM) RetentionPolicy(diskCacheV111.util.RetentionPolicy) FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) DiskErrorCacheException(diskCacheV111.util.DiskErrorCacheException) CacheException(diskCacheV111.util.CacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) DiskErrorCacheException(diskCacheV111.util.DiskErrorCacheException) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException)

Example 2 with FileNotFoundCacheException

use of diskCacheV111.util.FileNotFoundCacheException in project dcache by dCache.

the class DcacheResource method setProperty.

@Override
public void setProperty(QName qname, Object o) throws PropertySource.PropertySetException, NotAuthorizedException {
    if (!qname.getNamespaceURI().equals(XATTR_NAMESPACE_URI)) {
        throw new NotAuthorizedException("Property not modifiable", this);
    }
    String name = qname.getLocalPart();
    try {
        if (o == null) {
            try {
                _factory.removeExtendedAttribute(_path, name);
            } catch (NoAttributeCacheException e) {
            // RFC 4918 14.23 "Specifying the removal of a property
            // that does not exist is not an error."
            }
        } else {
            byte[] data;
            if (o instanceof String) {
                data = ((String) o).getBytes(StandardCharsets.UTF_8);
            } else {
                LOGGER.warn("set property called with unexpected value" + " type {}", o.getClass().getCanonicalName());
                data = String.valueOf(o).getBytes(StandardCharsets.UTF_8);
            }
            _factory.writeExtendedAttribute(_path, name, data);
        }
    } catch (PermissionDeniedCacheException e) {
        throw new NotAuthorizedException("Permission denied", this);
    } catch (FileNotFoundCacheException e) {
        throw new PropertySource.PropertySetException(Response.Status.SC_NOT_FOUND, "File does not exist");
    } catch (CacheException e) {
        LOGGER.error("setProperty on {} to {} failed: {}", qname, o, e.getMessage());
        throw new PropertySource.PropertySetException(Response.Status.SC_INTERNAL_SERVER_ERROR, e.getMessage());
    }
}
Also used : PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) CacheException(diskCacheV111.util.CacheException) NoAttributeCacheException(diskCacheV111.util.NoAttributeCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) NotAuthorizedException(io.milton.http.exceptions.NotAuthorizedException) NoAttributeCacheException(diskCacheV111.util.NoAttributeCacheException) PropertySource(io.milton.property.PropertySource)

Example 3 with FileNotFoundCacheException

use of diskCacheV111.util.FileNotFoundCacheException in project dcache by dCache.

the class FileUpdate method getAttributes.

/**
 * @return <code>null</code> if AccessLatency is not ONLINE, or if the file
 * is not found or there are no locations for it and the message being processed is for a clear
 * cache location; otherwise the file attribute set required to process resilience.
 */
public static FileAttributes getAttributes(PnfsId pnfsId, String pool, MessageType messageType, NamespaceAccess namespace) throws CacheException {
    try {
        FileAttributes attributes = namespace.getRequiredAttributes(pnfsId);
        if (attributes == null) {
            throw new FileNotFoundCacheException(String.format("No attributes " + "returned for %s", pnfsId));
        }
        LOGGER.trace("Got required attributes for {}.", pnfsId);
        if (attributes.getLocations().isEmpty()) {
            if (messageType == CLEAR_CACHE_LOCATION) {
                LOGGER.trace("ClearCacheLocationMessage for {}; " + "no current locations; " + "file probably deleted " + "from namespace.", pnfsId);
                return null;
            }
            if (messageType != ADD_CACHE_LOCATION) {
                /*
                     * Since the scan began or the broken file reported,
                     * the file has been removed.
                     */
                throw new FileNotFoundCacheException(String.format("File no longer found: %s", pnfsId));
            }
            /*
                 *  May be due to a race between PnfsManager and resilience
                 *  to process the message into/from the namespace.
                 *
                 *  We can assume here that this is a new file, so
                 *  we just add the originating location to the attribute
                 *  location list.
                 */
            LOGGER.trace("{} has no locations yet.", pnfsId);
            Collection<String> singleLoc = new ArrayList<>();
            /*
                 *  Pool can now be <code>null</code>
                 *  but only if message type is QOS_MODIFIED.
                 */
            if (pool == null) {
                if (messageType != QOS_MODIFIED) {
                    throw new CacheException(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, String.format("resilience File update for %s, " + "messageType %s, " + "has no pool location!", pnfsId, messageType));
                }
                return null;
            }
            singleLoc.add(pool);
            attributes.setLocations(singleLoc);
        }
        LOGGER.debug("After call to namespace, {} has locations {}.", pnfsId, attributes.getLocations());
        return attributes;
    } catch (FileNotFoundCacheException e) {
        LOGGER.debug("{}; {} has likely been deleted from the namespace.", e.getMessage(), pnfsId);
        return null;
    }
}
Also used : CacheException(diskCacheV111.util.CacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) ArrayList(java.util.ArrayList) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) FileAttributes(org.dcache.vehicles.FileAttributes)

Example 4 with FileNotFoundCacheException

use of diskCacheV111.util.FileNotFoundCacheException in project dcache by dCache.

the class ConsistentReplicaStoreTest method shouldDeleteBrokenReplicasWithNoNameSpaceEntry.

@Test
public void shouldDeleteBrokenReplicasWithNoNameSpaceEntry() throws Exception {
    // Given a replica with no meta data
    givenStoreHasFileOfSize(PNFSID, 17);
    // and given the name space entry does not exist
    given(_pnfs.getFileAttributes(eq(PNFSID), Mockito.anySet())).willThrow(new FileNotFoundCacheException("No such file"));
    // when reading the meta data record
    ReplicaRecord record = _consistentReplicaStore.get(PNFSID);
    // then recovery is attempted
    verify(_pnfs).getFileAttributes(eq(PNFSID), Mockito.anySet());
    // but nothing is returned
    assertThat(record, is(nullValue()));
    // and the replica is deleted
    assertThat(_replicaStore.get(PNFSID), is(nullValue()));
    assertThat(_fileStore.contains(PNFSID), is(false));
    // and the name space entry is not touched
    verify(_pnfs, never()).setFileAttributes(eq(PNFSID), Mockito.any(FileAttributes.class));
}
Also used : FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) FileAttributes(org.dcache.vehicles.FileAttributes) Test(org.junit.Test)

Example 5 with FileNotFoundCacheException

use of diskCacheV111.util.FileNotFoundCacheException in project dcache by dCache.

the class ChimeraNameSpaceProvider method deleteEntry.

@Override
public FileAttributes deleteEntry(Subject subject, Set<FileType> allowed, String path, Set<FileAttribute> attr) throws CacheException {
    try {
        File filePath = new File(path);
        String parentPath = filePath.getParent();
        if (parentPath == null) {
            throw new CacheException("Cannot delete file system root.");
        }
        ExtendedInode parent = pathToInode(subject, parentPath);
        String name = filePath.getName();
        ExtendedInode inode = parent.inodeOf(name, STAT);
        checkAllowed(allowed, inode);
        if (!Subjects.isExemptFromNamespaceChecks(subject) && !canDelete(subject, parent, inode)) {
            throw new PermissionDeniedCacheException("Access denied: " + path);
        }
        _fs.remove(parent, name, inode);
        return getFileAttributes(inode, attr);
    } catch (FileNotFoundChimeraFsException fnf) {
        throw new FileNotFoundCacheException("No such file or directory: " + path);
    } catch (DirNotEmptyChimeraFsException e) {
        throw new CacheException("Directory is not empty: " + path);
    } catch (IOException e) {
        throw new CacheException(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, e.getMessage());
    }
}
Also used : FileNotFoundChimeraFsException(org.dcache.chimera.FileNotFoundChimeraFsException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) LockedCacheException(diskCacheV111.util.LockedCacheException) AttributeExistsCacheException(diskCacheV111.util.AttributeExistsCacheException) NotDirCacheException(diskCacheV111.util.NotDirCacheException) InvalidMessageCacheException(diskCacheV111.util.InvalidMessageCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) NotFileCacheException(diskCacheV111.util.NotFileCacheException) CacheException(diskCacheV111.util.CacheException) NoAttributeCacheException(diskCacheV111.util.NoAttributeCacheException) FileCorruptedCacheException(diskCacheV111.util.FileCorruptedCacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) DirNotEmptyChimeraFsException(org.dcache.chimera.DirNotEmptyChimeraFsException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) File(java.io.File)

Aggregations

FileNotFoundCacheException (diskCacheV111.util.FileNotFoundCacheException)85 CacheException (diskCacheV111.util.CacheException)80 PermissionDeniedCacheException (diskCacheV111.util.PermissionDeniedCacheException)61 NotDirCacheException (diskCacheV111.util.NotDirCacheException)51 FileExistsCacheException (diskCacheV111.util.FileExistsCacheException)44 FileIsNewCacheException (diskCacheV111.util.FileIsNewCacheException)34 FileAttributes (org.dcache.vehicles.FileAttributes)34 NotFileCacheException (diskCacheV111.util.NotFileCacheException)33 FileCorruptedCacheException (diskCacheV111.util.FileCorruptedCacheException)31 FsPath (diskCacheV111.util.FsPath)31 InvalidMessageCacheException (diskCacheV111.util.InvalidMessageCacheException)28 TimeoutCacheException (diskCacheV111.util.TimeoutCacheException)27 NoAttributeCacheException (diskCacheV111.util.NoAttributeCacheException)24 FileNotFoundChimeraFsException (org.dcache.chimera.FileNotFoundChimeraFsException)24 AttributeExistsCacheException (diskCacheV111.util.AttributeExistsCacheException)23 PnfsId (diskCacheV111.util.PnfsId)21 LockedCacheException (diskCacheV111.util.LockedCacheException)20 MissingResourceCacheException (diskCacheV111.util.MissingResourceCacheException)19 FileAttribute (org.dcache.namespace.FileAttribute)18 IOException (java.io.IOException)17