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;
}
}
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);
}
}
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);
}
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;
}
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;
}
Aggregations