Search in sources :

Example 11 with PnfsId

use of diskCacheV111.util.PnfsId 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 12 with PnfsId

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

the class Job method add.

/**
 * Adds a new task to the job.
 */
@GuardedBy("_lock")
private void add(CacheEntry entry) {
    PnfsId pnfsId = entry.getPnfsId();
    if (!_queued.contains(pnfsId) && !_running.containsKey(pnfsId)) {
        long size = entry.getReplicaSize();
        _queued.add(pnfsId);
        _sizes.put(pnfsId, size);
        _statistics.addToTotal(size);
        schedule();
    }
}
Also used : PnfsId(diskCacheV111.util.PnfsId) GuardedBy(javax.annotation.concurrent.GuardedBy)

Example 13 with PnfsId

use of diskCacheV111.util.PnfsId 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();
        }
    }
}
Also used : PnfsId(diskCacheV111.util.PnfsId) StickyChangeEvent(org.dcache.pool.repository.StickyChangeEvent) CacheEntry(org.dcache.pool.repository.CacheEntry)

Example 14 with PnfsId

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

the class Job method taskFailed.

/**
 * Callback from task: Task failed, reschedule it.
 */
@Override
public void taskFailed(Task task, int rc, String msg) {
    _lock.lock();
    try {
        PnfsId pnfsId = task.getPnfsId();
        if (task == _running.remove(pnfsId)) {
            _queued.add(pnfsId);
            _context.unlock(pnfsId);
        }
        if (_state == State.RUNNING) {
            setState(State.SLEEPING);
        } else {
            schedule();
        }
        addError(new Error(task.getId(), pnfsId, msg));
    } finally {
        _lock.unlock();
    }
}
Also used : PnfsId(diskCacheV111.util.PnfsId)

Example 15 with PnfsId

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

the class NearlineStorageHandler method stateChanged.

@Override
public void stateChanged(StateChangeEvent event) {
    if (event.getNewState() == ReplicaState.REMOVED) {
        PnfsId pnfsId = event.getPnfsId();
        stageRequests.cancel(pnfsId);
        flushRequests.cancel(pnfsId);
    }
}
Also used : PnfsId(diskCacheV111.util.PnfsId)

Aggregations

PnfsId (diskCacheV111.util.PnfsId)216 CacheException (diskCacheV111.util.CacheException)124 Test (org.junit.Test)70 FileAttributes (org.dcache.vehicles.FileAttributes)67 FileNotFoundCacheException (diskCacheV111.util.FileNotFoundCacheException)51 PermissionDeniedCacheException (diskCacheV111.util.PermissionDeniedCacheException)45 FileAttribute (org.dcache.namespace.FileAttribute)43 ArrayList (java.util.ArrayList)35 IOException (java.io.IOException)34 PnfsGetFileAttributes (org.dcache.vehicles.PnfsGetFileAttributes)34 FsInode (org.dcache.chimera.FsInode)31 NotDirCacheException (diskCacheV111.util.NotDirCacheException)30 NoRouteToCellException (dmg.cells.nucleus.NoRouteToCellException)30 InvalidMessageCacheException (diskCacheV111.util.InvalidMessageCacheException)29 CellPath (dmg.cells.nucleus.CellPath)26 Inode (org.dcache.nfs.vfs.Inode)22 TimeoutCacheException (diskCacheV111.util.TimeoutCacheException)21 FileType (org.dcache.namespace.FileType)21 PnfsHandler (diskCacheV111.util.PnfsHandler)20 List (java.util.List)20