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