use of diskCacheV111.util.FileInCacheException in project dcache by dCache.
the class Companion method transfer.
private void transfer(String uri) {
ReplicaDescriptor handle;
synchronized (this) {
try {
handle = createReplicaEntry();
} catch (FileInCacheException e) {
_fsm.fileExists();
return;
} catch (CacheException e) {
_fsm.createEntryFailed(e.getRc(), e.getMessage());
return;
}
setThread(Thread.currentThread());
}
Throwable error = null;
try {
try {
Set<Checksum> actualChecksums = copy(uri, handle);
_checksumModule.enforcePostTransferPolicy(handle, actualChecksums);
} finally {
setThread(null);
Thread.interrupted();
}
if (_atime != null) {
handle.setLastAccessTime(_atime);
}
handle.commit();
} catch (Throwable e) {
error = e;
} finally {
handle.close();
synchronized (this) {
_fsm.transferEnded(error);
}
}
}
use of diskCacheV111.util.FileInCacheException in project dcache by dCache.
the class RepositorySubsystemTest method createEntry4.
/* Helper method for creating a fourth entry in the repository.
*/
private void createEntry4(final boolean failSetAttributes, final boolean cancel, final ReplicaState transferState, final ReplicaState finalState) throws Throwable {
new CellStubHelper(cell) {
boolean setAttr;
boolean addCache;
@Message(required = false, step = 1, cell = "pnfs")
public Object whenFileIsGarbageCollected(PnfsClearCacheLocationMessage msg) {
msg.setSucceeded();
return msg;
}
@Message(required = false, step = 3, cell = "pnfs")
public Object whenDescriptorIsCommitted(PnfsSetFileAttributes msg) {
assertEquals(size4, msg.getFileAttributes().getSize());
if (failSetAttributes) {
msg.setFailed(1, null);
} else {
msg.setSucceeded();
}
setAttr = true;
return msg;
}
@Message(required = false, step = 5, cell = "pnfs")
public Object whenDescriptorFails(PnfsAddCacheLocationMessage msg) {
assertTrue(failSetAttributes || cancel);
msg.setSucceeded();
addCache = true;
return msg;
}
@Message(required = false, step = 5, cell = "pnfs")
public Object whenDescriptorFails(PnfsSetFileAttributes msg) {
assertTrue(failSetAttributes || cancel);
msg.setSucceeded();
return msg;
}
@Override
protected void run() throws FileInCacheException, CacheException, InterruptedException, IOException {
List<StickyRecord> stickyRecords = Collections.emptyList();
ReplicaDescriptor handle = repository.createEntry(attributes4, transferState, finalState, stickyRecords, EnumSet.noneOf(OpenFlags.class), OptionalLong.empty());
try {
assertStep("No clear after this point", 2);
createFile(handle, size4);
if (!cancel) {
handle.commit();
}
} finally {
assertStep("Only failure registration after this point", 4);
handle.close();
}
assertEquals("SetFileAttributes must be sent unless we don't try to commit", !cancel, setAttr);
assertEquals("AddCacheLocation must be sent if not committed", cancel || failSetAttributes, addCache);
}
};
}
use of diskCacheV111.util.FileInCacheException in project dcache by dCache.
the class ReplicaRepository method createEntry.
@Override
public ReplicaDescriptor createEntry(FileAttributes fileAttributes, ReplicaState transferState, ReplicaState targetState, List<StickyRecord> stickyRecords, Set<? extends OpenOption> flags, OptionalLong maximumSize) throws CacheException {
if (!fileAttributes.isDefined(EnumSet.of(PNFSID, STORAGEINFO))) {
throw new IllegalArgumentException("PNFSID and STORAGEINFO are required, only got " + fileAttributes.getDefinedAttributes());
}
if (stickyRecords == null) {
throw new IllegalArgumentException("List of sticky records must not be null");
}
PnfsId id = fileAttributes.getPnfsId();
_stateLock.readLock().lock();
try {
checkOpen();
switch(transferState) {
case FROM_CLIENT:
case FROM_STORE:
case FROM_POOL:
break;
default:
throw new IllegalArgumentException("Invalid initial state");
}
switch(targetState) {
case PRECIOUS:
case CACHED:
break;
default:
throw new IllegalArgumentException("Invalid target state");
}
LOGGER.info("Creating new entry for {}", id);
ReplicaRecord entry = _store.create(id, flags);
return entry.update("Creating new replica", r -> {
r.setFileAttributes(fileAttributes);
r.setState(transferState);
return new WriteHandleImpl(this, buildAllocator(flags, maximumSize), _pnfs, entry, fileAttributes, targetState, stickyRecords);
});
} catch (DuplicateEntryException e) {
/* Somebody got the idea that we don't have the file, so we make
* sure to register it.
*/
_pnfs.notify(new PnfsAddCacheLocationMessage(id, getPoolName()));
throw new FileInCacheException("Entry already exists: " + id);
} finally {
_stateLock.readLock().unlock();
}
}
use of diskCacheV111.util.FileInCacheException 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