Search in sources :

Example 1 with FileNotInCacheException

use of diskCacheV111.util.FileNotInCacheException 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;
}
Also used : StickyRecord(org.dcache.pool.repository.StickyRecord) ChangePreciousBitMessage(org.dcache.vehicles.qos.ChangePreciousBitMessage) Message(diskCacheV111.vehicles.Message) ChangeStickyBitMessage(org.dcache.vehicles.qos.ChangeStickyBitMessage) ReplicaStatusMessage(org.dcache.vehicles.qos.ReplicaStatusMessage) MessageReply(org.dcache.cells.MessageReply) PnfsId(diskCacheV111.util.PnfsId) CacheEntry(org.dcache.pool.repository.CacheEntry) FileNotInCacheException(diskCacheV111.util.FileNotInCacheException) FileNotInCacheException(diskCacheV111.util.FileNotInCacheException)

Example 2 with FileNotInCacheException

use of diskCacheV111.util.FileNotInCacheException 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);
            }
        }
    }
}
Also used : Repository(org.dcache.pool.repository.Repository) FireAndForgetTask(org.dcache.util.FireAndForgetTask) Expression(org.dcache.util.expression.Expression) CacheException(diskCacheV111.util.CacheException) FileNotInCacheException(diskCacheV111.util.FileNotInCacheException) PnfsId(diskCacheV111.util.PnfsId) CacheEntry(org.dcache.pool.repository.CacheEntry) FileNotInCacheException(diskCacheV111.util.FileNotInCacheException) GuardedBy(javax.annotation.concurrent.GuardedBy)

Example 3 with FileNotInCacheException

use of diskCacheV111.util.FileNotInCacheException 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;
}
Also used : StickyRecord(org.dcache.pool.repository.StickyRecord) RemoveReplicaMessage(org.dcache.vehicles.resilience.RemoveReplicaMessage) ReplicaStatusMessage(org.dcache.vehicles.resilience.ReplicaStatusMessage) Message(diskCacheV111.vehicles.Message) ForceSystemStickyBitMessage(org.dcache.vehicles.resilience.ForceSystemStickyBitMessage) MessageReply(org.dcache.cells.MessageReply) PnfsId(diskCacheV111.util.PnfsId) CacheEntry(org.dcache.pool.repository.CacheEntry) FileNotInCacheException(diskCacheV111.util.FileNotInCacheException) FileNotInCacheException(diskCacheV111.util.FileNotInCacheException)

Example 4 with FileNotInCacheException

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

the class NearlineStorageHandlerTest method testFlushQueueStateOnError.

@Test
public void testFlushQueueStateOnError() throws CacheException {
    var attr = given(aFile().withStorageClass("a:b", "foo").withSize(34567));
    when(repository.openEntry(any(), any())).thenThrow(new FileNotInCacheException("injected"));
    nsh.flush("foo", Set.of(attr.getPnfsId()), hsmMigrationRequestCallack);
    assertThat(nsh.getActiveStoreJobs(), is(0));
    assertThat(nsh.getStoreQueueSize(), is(0));
    verify(hsmMigrationRequestCallack).failed(any(), any());
}
Also used : FileNotInCacheException(diskCacheV111.util.FileNotInCacheException) Test(org.junit.Test)

Example 5 with FileNotInCacheException

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

the class CacheEntryOrder method compare.

@Override
public int compare(PnfsId id1, PnfsId id2) {
    try {
        CacheEntry entry1 = _repository.getEntry(id1);
        CacheEntry entry2 = _repository.getEntry(id2);
        return _comparator.compare(entry1, entry2);
    } catch (FileNotInCacheException e) {
        return id1.compareTo(id2);
    } catch (InterruptedException e) {
        throw new RuntimeException("Thread got interupted", e);
    } catch (CacheException e) {
        throw new RuntimeException("Repository failed: " + e.getMessage(), e);
    }
}
Also used : CacheException(diskCacheV111.util.CacheException) FileNotInCacheException(diskCacheV111.util.FileNotInCacheException) CacheEntry(org.dcache.pool.repository.CacheEntry) FileNotInCacheException(diskCacheV111.util.FileNotInCacheException)

Aggregations

FileNotInCacheException (diskCacheV111.util.FileNotInCacheException)13 CacheEntry (org.dcache.pool.repository.CacheEntry)9 PnfsId (diskCacheV111.util.PnfsId)8 CacheException (diskCacheV111.util.CacheException)7 StickyRecord (org.dcache.pool.repository.StickyRecord)6 Repository (org.dcache.pool.repository.Repository)5 IllegalTransitionException (org.dcache.pool.repository.IllegalTransitionException)4 FileInCacheException (diskCacheV111.util.FileInCacheException)3 ArrayList (java.util.ArrayList)3 OptionalLong (java.util.OptionalLong)3 ReplicaRecord (org.dcache.pool.repository.ReplicaRecord)3 ReplicaState (org.dcache.pool.repository.ReplicaState)3 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)2 Preconditions.checkState (com.google.common.base.Preconditions.checkState)2 Stopwatch (com.google.common.base.Stopwatch)2 DiskErrorCacheException (diskCacheV111.util.DiskErrorCacheException)2 DiskSpace (diskCacheV111.util.DiskSpace)2 FileCorruptedCacheException (diskCacheV111.util.FileCorruptedCacheException)2 LockedCacheException (diskCacheV111.util.LockedCacheException)2 PnfsHandler (diskCacheV111.util.PnfsHandler)2