@Override public void scanForRepoChanges() { refdb.clearCache(); }
@Override protected DhtRepository getRepository() { return refdb.getRepository(); }
@Override public Ref peel(Ref ref) throws IOException { final Ref oldLeaf = ref.getLeaf(); if (oldLeaf.isPeeled() || oldLeaf.getObjectId() == null) return ref; DhtRef newLeaf = doPeel(oldLeaf); RefCache cur = readRefs(); int idx = cur.ids.find(oldLeaf.getName()); if (0 <= idx && cur.ids.get(idx) == oldLeaf) { RefList<DhtRef> newList = cur.ids.set(idx, newLeaf); if (cache.compareAndSet(cur, new RefCache(newList, cur))) cachePeeledState(oldLeaf, newLeaf); } return recreate(ref, newLeaf); }
@Override protected Result doUpdate(Result desiredResult) throws IOException { try { newData = newData(); boolean r = db.ref().compareAndPut(refKey, oldData, newData); if (r) { getRefDatabase().stored(dstRef.getName(), newData); return desiredResult; } else { getRefDatabase().clearCache(); return Result.LOCK_FAILURE; } } catch (TimeoutException e) { return Result.IO_FAILURE; } }
@Override protected Result doDelete(Result desiredResult) throws IOException { try { boolean r = db.ref().compareAndRemove(refKey, oldData); if (r) { getRefDatabase().removed(dstRef.getName()); return desiredResult; } else { getRefDatabase().clearCache(); return Result.LOCK_FAILURE; } } catch (TimeoutException e) { return Result.IO_FAILURE; } }
private RefCache read() throws DhtException, TimeoutException { RefList.Builder<DhtRef> id = new RefList.Builder<DhtRef>(); RefList.Builder<DhtRef> sym = new RefList.Builder<DhtRef>(); ObjectIdSubclassMap<IdWithChunk> hints = new ObjectIdSubclassMap<IdWithChunk>(); for (Map.Entry<RefKey, RefData> e : scan()) { DhtRef ref = fromData(e.getKey().getName(), e.getValue()); if (ref.isSymbolic()) sym.add(ref); id.add(ref); if (ref.getObjectId() instanceof IdWithChunk && !hints.contains(ref.getObjectId())) hints.add((IdWithChunk) ref.getObjectId()); if (ref.getPeeledObjectId() instanceof IdWithChunk && !hints.contains(ref.getPeeledObjectId())) hints.add((IdWithChunk) ref.getPeeledObjectId()); } id.sort(); sym.sort(); return new RefCache(id.toRefList(), sym.toRefList(), hints); }
@Override public boolean has(AnyObjectId objId, int typeHint) throws IOException { if (objId instanceof RefDataUtil.IdWithChunk) return true; if (recentChunks.has(repo, objId)) return true; if (repository.getRefDatabase().findChunk(objId) != null) return true; return !find(objId).isEmpty(); }
private RefCache readRefs() throws DhtException { RefCache c = cache.get(); if (c == null) { try { c = read(); } catch (TimeoutException e) { throw new DhtTimeoutException(e); } cache.set(c); } return c; }
/** * Initialize an in-memory representation of a DHT backed repository. * * @param builder * description of the repository and its data storage. */ public DhtRepository(DhtRepositoryBuilder builder) { super(builder); this.name = RepositoryName.create(builder.getRepositoryName()); this.key = builder.getRepositoryKey(); this.db = builder.getDatabase(); this.refdb = new DhtRefDatabase(this, db); this.objdb = new DhtObjDatabase(this, builder); this.config = new DhtConfig(); }
@Override public DhtRefUpdate newUpdate(String refName, boolean detach) throws IOException { boolean detachingSymbolicRef = false; DhtRef ref = getOneRef(refName); if (ref == null) ref = new DhtObjectIdRef(refName, NONE); else detachingSymbolicRef = detach && ref.isSymbolic(); if (detachingSymbolicRef) { RefData src = ((DhtRef) ref.getLeaf()).getRefData(); RefData.Builder b = RefData.newBuilder(ref.getRefData()); b.clearSymref(); b.setTarget(src.getTarget()); ref = new DhtObjectIdRef(refName, b.build()); } RepositoryKey repo = repository.getRepositoryKey(); DhtRefUpdate update = new DhtRefUpdate(this, repo, db, ref); if (detachingSymbolicRef) update.setDetachingSymbolicRef(); return update; }
void stored(String refName, RefData newData) { DhtRef ref = fromData(refName, newData); RefCache oldCache, newCache; do { oldCache = cache.get(); if (oldCache == null) return; RefList<DhtRef> ids = oldCache.ids.put(ref); RefList<DhtRef> sym = oldCache.sym; if (ref.isSymbolic()) { sym = sym.put(ref); } else { int p = sym.find(refName); if (0 <= p) sym = sym.remove(p); } newCache = new RefCache(ids, sym, oldCache.hints); } while (!cache.compareAndSet(oldCache, newCache)); }
@Override public Ref peel(Ref ref) throws IOException { final Ref oldLeaf = ref.getLeaf(); if (oldLeaf.isPeeled() || oldLeaf.getObjectId() == null) return ref; DhtRef newLeaf = doPeel(oldLeaf); RefCache cur = readRefs(); int idx = cur.ids.find(oldLeaf.getName()); if (0 <= idx && cur.ids.get(idx) == oldLeaf) { RefList<DhtRef> newList = cur.ids.set(idx, newLeaf); if (cache.compareAndSet(cur, new RefCache(newList, cur))) cachePeeledState(oldLeaf, newLeaf); } return recreate(ref, newLeaf); }
@Override protected Result doUpdate(Result desiredResult) throws IOException { try { newData = newData(); boolean r = db.ref().compareAndPut(refKey, oldData, newData); if (r) { getRefDatabase().stored(dstRef.getName(), newData); return desiredResult; } else { getRefDatabase().clearCache(); return Result.LOCK_FAILURE; } } catch (TimeoutException e) { return Result.IO_FAILURE; } }
@Override protected Result doDelete(Result desiredResult) throws IOException { try { boolean r = db.ref().compareAndRemove(refKey, oldData); if (r) { getRefDatabase().removed(dstRef.getName()); return desiredResult; } else { getRefDatabase().clearCache(); return Result.LOCK_FAILURE; } } catch (TimeoutException e) { return Result.IO_FAILURE; } }
private RefCache read() throws DhtException, TimeoutException { RefList.Builder<DhtRef> id = new RefList.Builder<DhtRef>(); RefList.Builder<DhtRef> sym = new RefList.Builder<DhtRef>(); ObjectIdSubclassMap<IdWithChunk> hints = new ObjectIdSubclassMap<IdWithChunk>(); for (Map.Entry<RefKey, RefData> e : scan()) { DhtRef ref = fromData(e.getKey().getName(), e.getValue()); if (ref.isSymbolic()) sym.add(ref); id.add(ref); if (ref.getObjectId() instanceof IdWithChunk && !hints.contains(ref.getObjectId())) hints.add((IdWithChunk) ref.getObjectId()); if (ref.getPeeledObjectId() instanceof IdWithChunk && !hints.contains(ref.getPeeledObjectId())) hints.add((IdWithChunk) ref.getPeeledObjectId()); } id.sort(); sym.sort(); return new RefCache(id.toRefList(), sym.toRefList(), hints); }
@Override public boolean has(AnyObjectId objId, int typeHint) throws IOException { if (objId instanceof RefDataUtil.IdWithChunk) return true; if (recentChunks.has(repo, objId)) return true; if (repository.getRefDatabase().findChunk(objId) != null) return true; return !find(objId).isEmpty(); }
private RefCache readRefs() throws DhtException { RefCache c = cache.get(); if (c == null) { try { c = read(); } catch (TimeoutException e) { throw new DhtTimeoutException(e); } cache.set(c); } return c; }
/** * Initialize an in-memory representation of a DHT backed repository. * * @param builder * description of the repository and its data storage. */ public DhtRepository(DhtRepositoryBuilder builder) { super(builder); this.name = RepositoryName.create(builder.getRepositoryName()); this.key = builder.getRepositoryKey(); this.db = builder.getDatabase(); this.refdb = new DhtRefDatabase(this, db); this.objdb = new DhtObjDatabase(this, builder); this.config = new DhtConfig(); }
@Override public DhtRefUpdate newUpdate(String refName, boolean detach) throws IOException { boolean detachingSymbolicRef = false; DhtRef ref = getOneRef(refName); if (ref == null) ref = new DhtObjectIdRef(refName, NONE); else detachingSymbolicRef = detach && ref.isSymbolic(); if (detachingSymbolicRef) { RefData src = ((DhtRef) ref.getLeaf()).getRefData(); RefData.Builder b = RefData.newBuilder(ref.getRefData()); b.clearSymref(); b.setTarget(src.getTarget()); ref = new DhtObjectIdRef(refName, b.build()); } RepositoryKey repo = repository.getRepositoryKey(); DhtRefUpdate update = new DhtRefUpdate(this, repo, db, ref); if (detachingSymbolicRef) update.setDetachingSymbolicRef(); return update; }