use of org.dcache.pool.repository.ReplicaState in project dcache by dCache.
the class P2PClient method newCompanion.
public synchronized int newCompanion(String sourcePoolName, FileAttributes fileAttributes, ReplicaState targetState, List<StickyRecord> stickyRecords, CacheFileAvailable callback, boolean forceSourceMode, Long atime) throws IOException, CacheException, InterruptedException, IllegalStateException {
if (getCellEndpoint() == null) {
throw new IllegalStateException("Endpoint not initialized");
}
if (_pool == null) {
throw new IllegalStateException("Pool stub not initialized");
}
if (_executor == null) {
throw new IllegalStateException("Executor not initialized");
}
if (_repository == null) {
throw new IllegalStateException("Repository not initialized");
}
if (_checksumModule == null) {
throw new IllegalStateException("Checksum module not initialized");
}
if (_pnfs == null) {
throw new IllegalStateException("PNFS stub not initialized");
}
ReplicaState state = _repository.getState(fileAttributes.getPnfsId());
if (state != ReplicaState.NEW) {
throw new IllegalStateException("Replica exists with state: " + state);
}
Callback cb = new Callback(callback);
Companion companion = new Companion(_executor, _interface, _repository, _checksumModule, _pnfs, _pool, fileAttributes, sourcePoolName, getCellName(), getCellDomainName(), targetState, stickyRecords, cb, forceSourceMode, atime, getContextIfNeeded);
int id = addCompanion(companion);
cb.setId(id);
return id;
}
use of org.dcache.pool.repository.ReplicaState in project dcache by dCache.
the class PoolV4 method messageArrived.
public DelayedReply messageArrived(Pool2PoolTransferMsg msg) throws CacheException, IOException, InterruptedException {
if (_poolMode.isDisabled(PoolV2Mode.DISABLED_P2P_CLIENT)) {
LOGGER.warn("Pool2PoolTransferMsg request rejected due to {}", _poolMode);
throw new CacheException(CacheException.POOL_DISABLED, "Pool is disabled");
}
String poolName = msg.getPoolName();
FileAttributes fileAttributes = msg.getFileAttributes();
CompanionFileAvailableCallback callback = new CompanionFileAvailableCallback(msg);
ReplicaState targetState = ReplicaState.CACHED;
int fileMode = msg.getDestinationFileStatus();
if (fileMode != Pool2PoolTransferMsg.UNDETERMINED) {
if (fileMode == Pool2PoolTransferMsg.PRECIOUS) {
targetState = ReplicaState.PRECIOUS;
}
} else if (!_hasTapeBackend && !_isVolatile && (_p2pFileMode == P2P_PRECIOUS)) {
targetState = ReplicaState.PRECIOUS;
}
List<StickyRecord> stickyRecords = Collections.emptyList();
_p2pClient.newCompanion(poolName, fileAttributes, targetState, stickyRecords, callback, false, null);
return callback;
}
use of org.dcache.pool.repository.ReplicaState in project dcache by dCache.
the class ReplicaRepository method loadRecord.
private PnfsId loadRecord(PnfsId id) throws CacheException, IllegalStateException, InterruptedException {
ReplicaRecord entry = readReplicaRecord(id);
if (entry != null) {
ReplicaState state = entry.getState();
LOGGER.debug("{} {}", id, state);
}
// Lazily check if repository was closed
if (_state != State.LOADING) {
throw new IllegalStateException("Repository was closed during loading.");
}
return id;
}
use of org.dcache.pool.repository.ReplicaState in project dcache by dCache.
the class CacheRepositoryEntryImpl method incrementLinkCount.
@Override
public synchronized int incrementLinkCount() {
ReplicaState state = getState();
if (state == REMOVED || state == DESTROYED) {
throw new IllegalStateException("Entry is marked as removed");
}
_linkCount++;
return _linkCount;
}
use of org.dcache.pool.repository.ReplicaState 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;
}
}
Aggregations