Search in sources :

Example 1 with ReplicaDescriptor

use of org.dcache.pool.repository.ReplicaDescriptor 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 ReplicaDescriptor

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

the class DefaultPostTransferService method execute.

@Override
public void execute(final Mover<?> mover, final CompletionHandler<Void, Void> completionHandler) {
    _executor.execute(new FireAndForgetTask(() -> {
        ReplicaDescriptor handle = mover.getIoHandle();
        try {
            try {
                if (mover.getIoMode().contains(StandardOpenOption.WRITE)) {
                    handle.addChecksums(mover.getExpectedChecksums());
                    _checksumModule.enforcePostTransferPolicy(handle, mover.getActualChecksums());
                }
                handle.commit();
            } finally {
                handle.close();
            }
            completionHandler.completed(null, null);
        } catch (InterruptedIOException | InterruptedException e) {
            LOGGER.warn("Transfer was forcefully killed during post-processing");
            mover.setTransferStatus(CacheException.DEFAULT_ERROR_CODE, "Transfer was forcefully killed");
            completionHandler.failed(e, null);
        } catch (CacheException e) {
            LOGGER.warn("Transfer failed in post-processing: {}", e.getMessage());
            mover.setTransferStatus(e.getRc(), "Post-processing failed: " + e.getMessage());
            completionHandler.failed(e, null);
        } catch (IOException e) {
            LOGGER.warn("Transfer failed in post-processing: {}", e.toString());
            mover.setTransferStatus(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, "Transfer failed in post-processing: " + messageOrClassName(e));
            completionHandler.failed(e, null);
        } catch (RuntimeException e) {
            LOGGER.error("Transfer failed in post-processing. Please report this bug to support@dcache.org.", e);
            mover.setTransferStatus(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, "Transfer failed due to unexpected exception: " + e.getMessage());
            completionHandler.failed(e, null);
        } catch (Throwable e) {
            Thread t = Thread.currentThread();
            t.getUncaughtExceptionHandler().uncaughtException(t, e);
            mover.setTransferStatus(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, "Transfer failed due to unexpected exception: " + e.getMessage());
            completionHandler.failed(e, null);
        }
        MoverInfoMessage moverInfoMessage = generateBillingMessage(mover, handle.getReplicaSize());
        // as current thread is used to serialize the message, send finish to the door before notifying the billing.
        sendFinished(mover, moverInfoMessage);
        sendBillingInfo(moverInfoMessage);
    }));
}
Also used : MoverInfoMessage(diskCacheV111.vehicles.MoverInfoMessage) ReplicaDescriptor(org.dcache.pool.repository.ReplicaDescriptor) CacheException(diskCacheV111.util.CacheException) FireAndForgetTask(org.dcache.util.FireAndForgetTask) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException)

Example 3 with ReplicaDescriptor

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

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

the class RepositorySubsystemTest method testRemoveOpenAgain.

@Test(expected = LockedCacheException.class)
public void testRemoveOpenAgain() throws Throwable {
    repository.init();
    repository.load();
    stateChangeEvents.clear();
    new CellStubHelper(cell) {

        @Message(required = true, step = 1, cell = "pnfs")
        public Object message(PnfsClearCacheLocationMessage msg) {
            msg.setSucceeded();
            return msg;
        }

        @Override
        protected void run() throws CacheException, InterruptedException, IllegalTransitionException {
            ReplicaDescriptor h1 = repository.openEntry(id1, EnumSet.noneOf(OpenFlags.class));
            repository.setState(id1, REMOVED, "test");
            expectStateChangeEvent(id1, PRECIOUS, REMOVED);
            assertStep("Cache location should have been cleared", 1);
            ReplicaDescriptor h2 = repository.openEntry(id1, EnumSet.noneOf(OpenFlags.class));
        }
    };
}
Also used : ReplicaDescriptor(org.dcache.pool.repository.ReplicaDescriptor) OpenFlags(org.dcache.pool.repository.Repository.OpenFlags) PnfsClearCacheLocationMessage(diskCacheV111.vehicles.PnfsClearCacheLocationMessage) CellStubHelper(org.dcache.tests.cells.CellStubHelper) Test(org.junit.Test)

Example 5 with ReplicaDescriptor

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

the class RepositorySubsystemTest method testCreateEntryFromStore.

@Test
public void testCreateEntryFromStore() throws Throwable {
    repository.init();
    repository.load();
    stateChangeEvents.clear();
    new CellStubHelper(cell) {

        @Message(required = true, step = 1, cell = "pnfs")
        public Object message(PnfsSetFileAttributes msg) {
            if (msg.getFileAttributes().isDefined(FileAttribute.SIZE)) {
                return new CacheException("");
            }
            msg.setSucceeded();
            return msg;
        }

        @Override
        protected void run() throws CacheException, InterruptedException {
            List<StickyRecord> stickyRecords = Collections.emptyList();
            ReplicaDescriptor handle = repository.createEntry(attributes5, FROM_STORE, CACHED, stickyRecords, EnumSet.noneOf(OpenFlags.class), OptionalLong.empty());
            try {
                createFile(handle, attributes5.getSize());
                handle.commit();
            } catch (IOException e) {
                throw new DiskErrorCacheException(e.getMessage());
            } finally {
                handle.close();
            }
        }
    };
}
Also used : StickyRecord(org.dcache.pool.repository.StickyRecord) ReplicaDescriptor(org.dcache.pool.repository.ReplicaDescriptor) OpenFlags(org.dcache.pool.repository.Repository.OpenFlags) DiskErrorCacheException(diskCacheV111.util.DiskErrorCacheException) LockedCacheException(diskCacheV111.util.LockedCacheException) FileInCacheException(diskCacheV111.util.FileInCacheException) CacheException(diskCacheV111.util.CacheException) FileNotInCacheException(diskCacheV111.util.FileNotInCacheException) PnfsSetFileAttributes(org.dcache.vehicles.PnfsSetFileAttributes) CellStubHelper(org.dcache.tests.cells.CellStubHelper) IOException(java.io.IOException) DiskErrorCacheException(diskCacheV111.util.DiskErrorCacheException) Test(org.junit.Test)

Aggregations

ReplicaDescriptor (org.dcache.pool.repository.ReplicaDescriptor)13 OpenFlags (org.dcache.pool.repository.Repository.OpenFlags)9 Test (org.junit.Test)7 CellStubHelper (org.dcache.tests.cells.CellStubHelper)5 CacheException (diskCacheV111.util.CacheException)4 FileInCacheException (diskCacheV111.util.FileInCacheException)4 StickyRecord (org.dcache.pool.repository.StickyRecord)4 PnfsSetFileAttributes (org.dcache.vehicles.PnfsSetFileAttributes)4 FileNotInCacheException (diskCacheV111.util.FileNotInCacheException)3 PnfsClearCacheLocationMessage (diskCacheV111.vehicles.PnfsClearCacheLocationMessage)3 DiskErrorCacheException (diskCacheV111.util.DiskErrorCacheException)2 LockedCacheException (diskCacheV111.util.LockedCacheException)2 PnfsId (diskCacheV111.util.PnfsId)2 PnfsAddCacheLocationMessage (diskCacheV111.vehicles.PnfsAddCacheLocationMessage)2 CellPath (dmg.cells.nucleus.CellPath)2 IOException (java.io.IOException)2 FileAttributes (org.dcache.vehicles.FileAttributes)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 Stopwatch (com.google.common.base.Stopwatch)1