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