Search in sources :

Example 1 with IllegalTransitionException

use of org.dcache.pool.repository.IllegalTransitionException in project dcache by dCache.

the class PoolV4 method remove.

private String remove(String file, String why) throws CacheException, InterruptedException {
    try {
        PnfsId pnfsId = new PnfsId(file);
        _repository.setState(pnfsId, ReplicaState.REMOVED, why);
        return null;
    } catch (IllegalTransitionException e) {
        LOGGER.error("Replica {} not removed: {}", file, e.getMessage());
        return file;
    }
}
Also used : PnfsId(diskCacheV111.util.PnfsId) IllegalTransitionException(org.dcache.pool.repository.IllegalTransitionException)

Example 2 with IllegalTransitionException

use of org.dcache.pool.repository.IllegalTransitionException in project dcache by dCache.

the class SpaceSweeper2 method reclaim.

private long reclaim(long amount, String why) throws InterruptedException {
    LOGGER.debug("Sweeper tries to reclaim {} bytes.", amount);
    /* We copy the entries into a tmp list to avoid
         * ConcurrentModificationException.
         */
    List<PnfsId> tmpList = _queue.values();
    /* Delete the files.
         */
    long deleted = 0;
    for (PnfsId id : tmpList) {
        try {
            CacheEntry entry = _repository.getEntry(id);
            // the file is closed, so we skip it this time around.
            if (entry.getLinkCount() > 0) {
                LOGGER.debug("File skipped by sweeper (in use): {}", entry);
                continue;
            }
            if (!isRemovable(entry)) {
                LOGGER.debug("File skipped by sweeper (not removable): {}", entry);
                continue;
            }
            long size = entry.getReplicaSize();
            LOGGER.debug("Sweeper removes {}.", id);
            _repository.setState(id, ReplicaState.REMOVED, why);
            deleted += size;
        } catch (IllegalTransitionException | FileNotInCacheException e) {
        /* Normal if file got removed just as we wanted to
                 * remove it ourselves.
                 */
        } catch (CacheException e) {
            LOGGER.error(e.getMessage());
        }
        if (deleted >= amount) {
            break;
        }
    }
    return deleted;
}
Also used : CacheException(diskCacheV111.util.CacheException) FileNotInCacheException(diskCacheV111.util.FileNotInCacheException) PnfsId(diskCacheV111.util.PnfsId) IllegalTransitionException(org.dcache.pool.repository.IllegalTransitionException) CacheEntry(org.dcache.pool.repository.CacheEntry) FileNotInCacheException(diskCacheV111.util.FileNotInCacheException)

Example 3 with IllegalTransitionException

use of org.dcache.pool.repository.IllegalTransitionException in project dcache by dCache.

the class Job method applySourceMode.

/**
 * Apply source mode update to replica.
 */
private void applySourceMode(PnfsId pnfsId) {
    try {
        CacheEntryMode mode = _definition.sourceMode;
        Repository repository = _context.getRepository();
        CacheEntry entry = repository.getEntry(pnfsId);
        switch(mode.state) {
            case SAME:
                applySticky(pnfsId, mode.stickyRecords);
                break;
            case DELETE:
                if (!isPinned(entry)) {
                    repository.setState(pnfsId, ReplicaState.REMOVED, "migration job deleting source");
                    break;
                }
            // Fall through
            case REMOVABLE:
                List<StickyRecord> list = mode.stickyRecords;
                applySticky(pnfsId, list);
                for (StickyRecord record : entry.getStickyRecords()) {
                    String owner = record.owner();
                    if (!isPin(record) && !containsOwner(list, owner)) {
                        repository.setSticky(pnfsId, owner, 0, true);
                    }
                }
                repository.setState(pnfsId, ReplicaState.CACHED, "migration job making source removable");
                break;
            case CACHED:
                applySticky(pnfsId, mode.stickyRecords);
                repository.setState(pnfsId, ReplicaState.CACHED, "migration job making source cached");
                break;
            case PRECIOUS:
                repository.setState(pnfsId, ReplicaState.PRECIOUS, "migration job making source precious");
                applySticky(pnfsId, mode.stickyRecords);
                break;
        }
    } catch (FileNotInCacheException e) {
    // File got remove before we could update it. TODO: log it
    } catch (IllegalTransitionException e) {
    // File is likely about to be removed. TODO: log it
    } catch (CacheException e) {
        LOGGER.error("Migration job failed to update source mode: {}", e.getMessage());
        setState(State.FAILED);
    } catch (InterruptedException e) {
        LOGGER.error("Migration job was interrupted");
        setState(State.FAILED);
    }
}
Also used : StickyRecord(org.dcache.pool.repository.StickyRecord) Repository(org.dcache.pool.repository.Repository) CacheException(diskCacheV111.util.CacheException) FileNotInCacheException(diskCacheV111.util.FileNotInCacheException) IllegalTransitionException(org.dcache.pool.repository.IllegalTransitionException) CacheEntry(org.dcache.pool.repository.CacheEntry) FileNotInCacheException(diskCacheV111.util.FileNotInCacheException)

Example 4 with IllegalTransitionException

use of org.dcache.pool.repository.IllegalTransitionException in project dcache by dCache.

the class ReplicaRepository method setState.

@Override
public void setState(PnfsId id, ReplicaState state, String why) throws IllegalArgumentException, InterruptedException, CacheException {
    if (id == null) {
        throw new IllegalArgumentException("id is null");
    }
    _stateLock.readLock().lock();
    try {
        checkOpen();
        try {
            ReplicaRecord entry = getReplicaRecord(id);
            entry.update(why, r -> {
                ReplicaState source = r.getState();
                switch(source) {
                    case NEW:
                    case REMOVED:
                    case DESTROYED:
                        if (state == ReplicaState.REMOVED) {
                            /* File doesn't exist or is already
                                 * deleted. That's all we care about.
                                 */
                            return null;
                        }
                        break;
                    case PRECIOUS:
                    case CACHED:
                    case BROKEN:
                        switch(state) {
                            case REMOVED:
                            case CACHED:
                            case PRECIOUS:
                            case BROKEN:
                                return r.setState(state);
                            default:
                                break;
                        }
                    default:
                        break;
                }
                throw new IllegalTransitionException(id, source, state);
            });
        } catch (FileNotInCacheException e) {
            /* File disappeared before we could change the
                 * state. That's okay if we wanted to remove it, otherwise
                 * not.
                 */
            if (state != REMOVED) {
                throw new IllegalTransitionException(id, NEW, state);
            }
        }
    } finally {
        _stateLock.readLock().unlock();
    }
}
Also used : IllegalTransitionException(org.dcache.pool.repository.IllegalTransitionException) ReplicaRecord(org.dcache.pool.repository.ReplicaRecord) ReplicaState(org.dcache.pool.repository.ReplicaState) FileNotInCacheException(diskCacheV111.util.FileNotInCacheException)

Aggregations

IllegalTransitionException (org.dcache.pool.repository.IllegalTransitionException)4 FileNotInCacheException (diskCacheV111.util.FileNotInCacheException)3 CacheException (diskCacheV111.util.CacheException)2 PnfsId (diskCacheV111.util.PnfsId)2 CacheEntry (org.dcache.pool.repository.CacheEntry)2 ReplicaRecord (org.dcache.pool.repository.ReplicaRecord)1 ReplicaState (org.dcache.pool.repository.ReplicaState)1 Repository (org.dcache.pool.repository.Repository)1 StickyRecord (org.dcache.pool.repository.StickyRecord)1