use of org.dcache.pool.repository.CacheEntry in project dcache by dCache.
the class QoSMessageHandler method messageArrived.
/**
* Returns whether replica exists, the status of its system sticky flag and whether its state
* allows for reading and removal.
*/
public Reply messageArrived(ReplicaStatusMessage message) {
MessageReply<Message> reply = new MessageReply<>();
executor.execute(() -> {
PnfsId pnfsId = message.getPnfsId();
try {
CacheEntry entry = repository.getEntry(pnfsId);
message.setExists(true);
switch(entry.getState()) {
case FROM_CLIENT:
case FROM_POOL:
case FROM_STORE:
message.setWaiting(true);
break;
case CACHED:
message.setReadable(true);
message.setRemovable(true);
break;
case BROKEN:
message.setBroken(true);
message.setRemovable(true);
break;
case PRECIOUS:
message.setReadable(true);
message.setPrecious(true);
break;
default:
break;
}
Collection<StickyRecord> records = entry.getStickyRecords();
for (StickyRecord record : records) {
if (record.owner().equals(SYSTEM_OWNER) && record.isNonExpiring()) {
message.setSystemSticky(true);
break;
}
}
reply.reply(message);
} catch (FileNotInCacheException e) {
reply.reply(message);
} catch (Exception e) {
reply.fail(message, e);
}
});
return reply;
}
use of org.dcache.pool.repository.CacheEntry in project dcache by dCache.
the class Job method schedule.
/**
* Schedules jobs, depending on the current state and available resources.
* <p>
* Closely coupled to the <code>setState</code> method.
*
* @see setState
*/
@GuardedBy("_lock")
private void schedule() {
if (_state == State.CANCELLING && _running.isEmpty()) {
setState(State.CANCELLED);
} else if (_state != State.INITIALIZING && _state != State.NEW && !_definition.isPermanent && _queued.isEmpty() && _running.isEmpty()) {
setState(State.FINISHED);
} else if (_state == State.STOPPING && _running.isEmpty()) {
setState(State.FINISHED);
} else if (_state == State.RUNNING && (!_definition.sourceList.isValid() || !_definition.poolList.isValid())) {
setState(State.SLEEPING);
} else if (_state == State.RUNNING) {
Iterator<PnfsId> i = _queued.iterator();
while ((_running.size() < _concurrency) && i.hasNext()) {
Expression stopWhen = _definition.stopWhen;
if (stopWhen != null && evaluateLifetimePredicate(stopWhen)) {
stop();
break;
}
Expression pauseWhen = _definition.pauseWhen;
if (pauseWhen != null && evaluateLifetimePredicate(pauseWhen)) {
pause();
break;
}
PnfsId pnfsId = i.next();
if (!_context.lock(pnfsId)) {
addError(new Error(0, pnfsId, "File is locked"));
continue;
}
try {
i.remove();
Repository repository = _context.getRepository();
CacheEntry entry = repository.getEntry(pnfsId);
Task task = new Task(_taskParameters, this, _context.getPoolName(), entry.getPnfsId(), getTargetState(entry), getTargetStickyRecords(entry), getPins(entry), entry.getFileAttributes(), entry.getLastAccessTime());
_running.put(pnfsId, task);
_statistics.addAttempt();
task.run();
} catch (FileNotInCacheException e) {
_sizes.remove(pnfsId);
} catch (CacheException e) {
LOGGER.error("Migration job failed to read entry: {}", e.getMessage());
setState(State.FAILED);
break;
} catch (InterruptedException e) {
LOGGER.error("Migration job was interrupted: {}", e.getMessage());
setState(State.FAILED);
break;
} finally {
if (!_running.containsKey(pnfsId)) {
_context.unlock(pnfsId);
}
}
}
if (_running.isEmpty()) {
if (!_definition.isPermanent && _queued.isEmpty()) {
setState(State.FINISHED);
} else {
setState(State.SLEEPING);
}
}
}
}
use of org.dcache.pool.repository.CacheEntry in project dcache by dCache.
the class Job method entryChanged.
private void entryChanged(EntryChangeEvent event) {
PnfsId pnfsId = event.getPnfsId();
CacheEntry entry = event.getNewEntry();
if (!accept(entry)) {
_lock.lock();
try {
if (!_running.containsKey(pnfsId)) {
String type = event instanceof StickyChangeEvent ? "sticky" : "atime";
remove(pnfsId, type + " changed, so file no longer matches criteria");
}
} finally {
_lock.unlock();
}
} else if (_definition.isPermanent && !accept(event.getOldEntry())) {
_lock.lock();
try {
add(entry);
} finally {
_lock.unlock();
}
}
}
use of org.dcache.pool.repository.CacheEntry in project dcache by dCache.
the class ResilienceMessageHandler method messageArrived.
/**
* <p>Returns whether replica exists, the status of its system sticky flag
* and whether its state allows for reading and removal.</p>
*/
public Reply messageArrived(ReplicaStatusMessage message) {
MessageReply<Message> reply = new MessageReply<>();
executor.execute(() -> {
PnfsId pnfsId = message.getPnfsId();
if (pnfsId == null) {
reply.fail(message, new IllegalArgumentException("no pnfsid"));
return;
}
try {
CacheEntry entry = repository.getEntry(pnfsId);
message.setExists(true);
switch(entry.getState()) {
case FROM_CLIENT:
case FROM_POOL:
case FROM_STORE:
message.setWaiting(true);
break;
case CACHED:
message.setReadable(true);
message.setRemovable(true);
break;
case BROKEN:
message.setBroken(true);
message.setRemovable(true);
break;
case PRECIOUS:
message.setReadable(true);
break;
default:
break;
}
Collection<StickyRecord> records = entry.getStickyRecords();
for (StickyRecord record : records) {
if (record.owner().equals(SYSTEM_OWNER) && record.isNonExpiring()) {
message.setSystemSticky(true);
break;
}
}
reply.reply(message);
} catch (FileNotInCacheException e) {
reply.reply(message);
} catch (Exception e) {
reply.fail(message, e);
}
});
return reply;
}
use of org.dcache.pool.repository.CacheEntry in project dcache by dCache.
the class NoCachedFilesSpaceSweeper method stateChanged.
@Override
public void stateChanged(StateChangeEvent event) {
try {
if (event.getNewState() == ReplicaState.CACHED) {
PnfsId id = event.getPnfsId();
CacheEntry entry = event.getNewEntry();
if (!entry.isSticky()) {
_repository.setState(id, ReplicaState.REMOVED, "Replica is now cache-only on pool with no-cache policy");
LOGGER.debug(entry.getPnfsId() + " removed: {}", event.getWhy());
}
}
} catch (InterruptedException | CacheException e) {
LOGGER.warn("Failed to remove entry from repository ({}): {}", event.getWhy(), e.getMessage());
}
}
Aggregations