Search in sources :

Example 1 with FileInCacheException

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);
        }
    }
}
Also used : ReplicaDescriptor(org.dcache.pool.repository.ReplicaDescriptor) FileInCacheException(diskCacheV111.util.FileInCacheException) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException) FileInCacheException(diskCacheV111.util.FileInCacheException) CacheException(diskCacheV111.util.CacheException) Checksum(org.dcache.util.Checksum)

Example 2 with FileInCacheException

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);
        }
    };
}
Also used : StickyRecord(org.dcache.pool.repository.StickyRecord) ReplicaDescriptor(org.dcache.pool.repository.ReplicaDescriptor) OpenFlags(org.dcache.pool.repository.Repository.OpenFlags) PnfsSetFileAttributes(org.dcache.vehicles.PnfsSetFileAttributes) PnfsClearCacheLocationMessage(diskCacheV111.vehicles.PnfsClearCacheLocationMessage) CellStubHelper(org.dcache.tests.cells.CellStubHelper) PnfsAddCacheLocationMessage(diskCacheV111.vehicles.PnfsAddCacheLocationMessage)

Example 3 with FileInCacheException

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();
    }
}
Also used : FileInCacheException(diskCacheV111.util.FileInCacheException) PnfsId(diskCacheV111.util.PnfsId) DuplicateEntryException(org.dcache.pool.repository.DuplicateEntryException) ReplicaRecord(org.dcache.pool.repository.ReplicaRecord) PnfsAddCacheLocationMessage(diskCacheV111.vehicles.PnfsAddCacheLocationMessage)

Example 4 with FileInCacheException

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

Aggregations

FileInCacheException (diskCacheV111.util.FileInCacheException)3 ReplicaDescriptor (org.dcache.pool.repository.ReplicaDescriptor)3 PnfsId (diskCacheV111.util.PnfsId)2 PnfsAddCacheLocationMessage (diskCacheV111.vehicles.PnfsAddCacheLocationMessage)2 StickyRecord (org.dcache.pool.repository.StickyRecord)2 CacheException (diskCacheV111.util.CacheException)1 FileNotInCacheException (diskCacheV111.util.FileNotInCacheException)1 TimeoutCacheException (diskCacheV111.util.TimeoutCacheException)1 DCapProtocolInfo (diskCacheV111.vehicles.DCapProtocolInfo)1 PnfsClearCacheLocationMessage (diskCacheV111.vehicles.PnfsClearCacheLocationMessage)1 PoolAcceptFileMessage (diskCacheV111.vehicles.PoolAcceptFileMessage)1 ProtocolInfo (diskCacheV111.vehicles.ProtocolInfo)1 CellPath (dmg.cells.nucleus.CellPath)1 OptionalLong (java.util.OptionalLong)1 MoverFactory (org.dcache.pool.movers.MoverFactory)1 DuplicateEntryException (org.dcache.pool.repository.DuplicateEntryException)1 ReplicaRecord (org.dcache.pool.repository.ReplicaRecord)1 ReplicaState (org.dcache.pool.repository.ReplicaState)1 OpenFlags (org.dcache.pool.repository.Repository.OpenFlags)1 CellStubHelper (org.dcache.tests.cells.CellStubHelper)1