Search in sources :

Example 11 with StickyRecord

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

the class PoolV4 method createMover.

// //////////////////////////////////////////////////////////////
// 
// The io File Part
// 
// 
public Mover<?> createMover(CellMessage envelop, PoolIoFileMessage message) throws CacheException {
    CellPath source = envelop.getSourcePath().revert();
    FileAttributes attributes = message.getFileAttributes();
    PnfsId pnfsId = attributes.getPnfsId();
    ProtocolInfo pi = message.getProtocolInfo();
    MoverFactory moverFactory = _transferServices.getMoverFactory(pi);
    ReplicaDescriptor handle;
    try {
        if (message instanceof PoolAcceptFileMessage) {
            OptionalLong maximumSize = ((PoolAcceptFileMessage) message).getMaximumSize();
            List<StickyRecord> stickyRecords = _replicaStatePolicy.getStickyRecords(attributes);
            ReplicaState targetState = _replicaStatePolicy.getTargetState(attributes);
            handle = _repository.createEntry(attributes, ReplicaState.FROM_CLIENT, targetState, stickyRecords, moverFactory.getChannelCreateOptions(), maximumSize);
        } else {
            Set<? extends OpenOption> openFlags = message.isPool2Pool() ? EnumSet.of(Repository.OpenFlags.NOATIME) : EnumSet.noneOf(Repository.OpenFlags.class);
            handle = _repository.openEntry(pnfsId, openFlags);
        }
    } catch (FileNotInCacheException e) {
        throw new FileNotInCacheException("File " + pnfsId + " does not exist in " + _poolName, e);
    } catch (FileInCacheException e) {
        throw new FileInCacheException("File " + pnfsId + " already exists in " + _poolName, e);
    }
    try {
        return moverFactory.createMover(handle, message, source);
    } catch (Throwable t) {
        handle.close();
        throw t;
    }
}
Also used : CellPath(dmg.cells.nucleus.CellPath) PnfsId(diskCacheV111.util.PnfsId) ReplicaState(org.dcache.pool.repository.ReplicaState) StickyRecord(org.dcache.pool.repository.StickyRecord) MoverFactory(org.dcache.pool.movers.MoverFactory) ReplicaDescriptor(org.dcache.pool.repository.ReplicaDescriptor) FileInCacheException(diskCacheV111.util.FileInCacheException) ProtocolInfo(diskCacheV111.vehicles.ProtocolInfo) DCapProtocolInfo(diskCacheV111.vehicles.DCapProtocolInfo) OptionalLong(java.util.OptionalLong) PoolAcceptFileMessage(diskCacheV111.vehicles.PoolAcceptFileMessage) FileAttributes(org.dcache.vehicles.FileAttributes) FileNotInCacheException(diskCacheV111.util.FileNotInCacheException)

Example 12 with StickyRecord

use of org.dcache.pool.repository.StickyRecord 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 13 with StickyRecord

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

the class QoSTransitionEngine method directoryQoS.

private QosStatus directoryQoS() {
    ReplicaState state = POOL_POLICY.getTargetState(attributes);
    boolean isSticky = POOL_POLICY.getStickyRecords(attributes).stream().anyMatch(StickyRecord::isNonExpiring);
    Qos qos;
    if (state == ReplicaState.PRECIOUS) {
        qos = isSticky ? DISK_TAPE : TAPE;
    } else {
        qos = isSticky ? DISK : VOLATILE;
    }
    return new QosStatus(qos);
}
Also used : StickyRecord(org.dcache.pool.repository.StickyRecord) ReplicaState(org.dcache.pool.repository.ReplicaState)

Example 14 with StickyRecord

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

the class Sticky method removeRecord.

/**
 * Removes all sticky flags owned by <code>owner</code> and not valid at <code>time</code>. No
 * flag is valid at time point -1.
 * <p>
 * Returns true if all flags owned by <code>owner</code> have been removed, false otherwise.
 */
private synchronized boolean removeRecord(String owner, long time) {
    StickyRecord record = _records.get(owner);
    if ((record != null) && (time > -1) && record.isValidAt(time)) {
        return false;
    }
    _records.remove(owner);
    return true;
}
Also used : StickyRecord(org.dcache.pool.repository.StickyRecord)

Example 15 with StickyRecord

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

the class Sticky method removeExpired.

/**
 * Removes expired flags. Returns the list of removed records.
 */
public synchronized List<StickyRecord> removeExpired() {
    List<StickyRecord> removed = new ArrayList();
    long now = System.currentTimeMillis();
    Iterator<StickyRecord> i = _records.values().iterator();
    while (i.hasNext()) {
        StickyRecord record = i.next();
        if (!record.isValidAt(now)) {
            i.remove();
            removed.add(record);
        }
    }
    return removed;
}
Also used : StickyRecord(org.dcache.pool.repository.StickyRecord) ArrayList(java.util.ArrayList)

Aggregations

StickyRecord (org.dcache.pool.repository.StickyRecord)17 CacheException (diskCacheV111.util.CacheException)6 FileNotInCacheException (diskCacheV111.util.FileNotInCacheException)6 PnfsId (diskCacheV111.util.PnfsId)6 ReplicaState (org.dcache.pool.repository.ReplicaState)4 FileInCacheException (diskCacheV111.util.FileInCacheException)3 CacheEntry (org.dcache.pool.repository.CacheEntry)3 ReplicaDescriptor (org.dcache.pool.repository.ReplicaDescriptor)3 DiskErrorCacheException (diskCacheV111.util.DiskErrorCacheException)2 LockedCacheException (diskCacheV111.util.LockedCacheException)2 TimeoutCacheException (diskCacheV111.util.TimeoutCacheException)2 Message (diskCacheV111.vehicles.Message)2 CellPath (dmg.cells.nucleus.CellPath)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 MessageReply (org.dcache.cells.MessageReply)2 OpenFlags (org.dcache.pool.repository.Repository.OpenFlags)2 CellStubHelper (org.dcache.tests.cells.CellStubHelper)2 FileAttributes (org.dcache.vehicles.FileAttributes)2 PnfsSetFileAttributes (org.dcache.vehicles.PnfsSetFileAttributes)2