use of org.dcache.pool.repository.ReplicaState.NEW 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();
}
}
use of org.dcache.pool.repository.ReplicaState.NEW in project dcache by dCache.
the class ReplicaRepository method setSticky.
@Override
public void setSticky(PnfsId id, String owner, long expire, boolean overwrite) throws IllegalArgumentException, CacheException, InterruptedException {
requireNonNull(id);
requireNonNull(owner);
checkArgument(expire >= -1, "Expiration time must be -1 or non-negative");
_stateLock.readLock().lock();
try {
checkInitialized();
ReplicaRecord entry;
try {
entry = getReplicaRecord(id);
} catch (FileNotInCacheException e) {
/* Attempts to set a sticky bit on a missing file may
* indicate a stale registration in the name space.
*/
try {
entry = _store.create(id, EnumSet.noneOf(OpenFlags.class));
entry.update("Removing replica created to recover from unknown setSticky request", r -> r.setState(REMOVED));
} catch (DuplicateEntryException concurrentCreation) {
setSticky(id, owner, expire, overwrite);
return;
} catch (CacheException | RuntimeException f) {
e.addSuppressed(f);
}
throw e;
}
entry.update("Setting " + owner + " sticky", r -> {
switch(r.getState()) {
case NEW:
case FROM_CLIENT:
case FROM_STORE:
case FROM_POOL:
throw new LockedCacheException("File is incomplete");
case REMOVED:
case DESTROYED:
throw new LockedCacheException("File has been removed");
case BROKEN:
case PRECIOUS:
case CACHED:
break;
}
return r.setSticky(owner, expire, overwrite);
});
} finally {
_stateLock.readLock().unlock();
}
}
Aggregations