use of org.dcache.pool.repository.StickyRecord in project dcache by dCache.
the class RepositorySubsystemTest method setUp.
@Before
public void setUp() throws Throwable {
id1 = new PnfsId("000000000001");
id2 = new PnfsId("000000000002");
id3 = new PnfsId("000000000003");
id4 = new PnfsId("000000000004");
id5 = new PnfsId("000000000005");
info1 = new GenericStorageInfo();
info2 = new GenericStorageInfo();
info3 = new GenericStorageInfo();
info4 = new GenericStorageInfo();
info5 = new GenericStorageInfo();
attributes1 = createFileAttributes(id1, size1, info1);
attributes2 = createFileAttributes(id2, size2, info2);
attributes3 = createFileAttributes(id3, size3, info3);
attributes4 = createFileAttributes(id4, 0, info4);
attributes5 = createFileAttributes(id5, size5, info5);
dataRoot = Jimfs.newFileSystem(Configuration.unix()).getPath("/");
metaRoot = Files.createTempDirectory("dtest");
dataDir = dataRoot.resolve("data");
metaDir = metaRoot.resolve("meta");
Files.createDirectory(dataDir);
Files.createDirectory(metaDir);
cell = new CellEndpointHelper(address);
pnfs = new PnfsHandler(new CellPath("pnfs"), "pool");
pnfs.setCellEndpoint(cell);
/* Create test data. Notice that the repository automatically
* applies a short lived sticky record if we don't request
* one. That is fine for normal operation, but for testing it
* is not what we want. So we explicitly specify an expired
* sticky record to avoid that the automatic sticky record is
* created.
*/
initRepository();
repository.init();
repository.load();
createEntry(attributes1, ReplicaState.PRECIOUS, Arrays.asList(new StickyRecord("system", 0)));
createEntry(attributes2, ReplicaState.CACHED, Arrays.asList(new StickyRecord("system", 0)));
createEntry(attributes3, ReplicaState.CACHED, Arrays.asList(new StickyRecord("system", -1)));
repository.shutdown();
replicaStore.close();
/* Create repository.
*/
initRepository();
sweeper.setAccount(account);
sweeper.setRepository(repository);
sweeper.start();
}
use of org.dcache.pool.repository.StickyRecord in project dcache by dCache.
the class CacheRepositoryEntryImpl method update.
@Override
public synchronized <T> T update(String why, Update<T> update) throws CacheException {
AtomicReference<T> result = new AtomicReference<>();
ReplicaState state = _state;
ImmutableList<StickyRecord> sticky = _sticky;
try {
_repository.run(() -> {
UpdatableRecordImpl record = new UpdatableRecordImpl();
result.set(update.apply(record));
record.save();
});
} catch (Exception e) {
_state = state;
_sticky = sticky;
if (e instanceof EnvironmentFailureException && !_repository.isValid()) {
throw new DiskErrorCacheException("Meta data update failed and a pool restart is required: " + e.getMessage(), e);
}
Throwables.propagateIfPossible(e, CacheException.class);
throw new CacheException("Meta data update failed: " + e.getMessage(), e);
}
return result.get();
}
Aggregations