/** * @param repo * @param name * @return the key */ public static RefKey create(RepositoryKey repo, String name) { return new RefKey(repo.asInt(), name); }
@Override public String toString() { return "ref:" + asString(); } }
public String asString() { return getRepositoryKey().asString() + ":" + name; }
public boolean compareAndRemove(RefKey refKey, RefData oldData) throws DhtException, TimeoutException { RepositoryKey repo = refKey.getRepositoryKey(); return table.compareAndSet( // repo.asBytes(), // colRef.append(refKey.asBytes()), // oldData != RefDataUtil.NONE ? oldData.toByteArray() : null, // null); } }
private void cachePeeledState(Ref oldLeaf, Ref newLeaf) { // TODO(spearce) Use an ExecutorService here try { RepositoryKey repo = repository.getRepositoryKey(); RefKey key = RefKey.create(repo, newLeaf.getName()); RefData oldData = ((DhtRef) oldLeaf).getRefData(); RefData newData = ((DhtRef) newLeaf).getRefData(); db.ref().compareAndPut(key, oldData, newData); } catch (TimeoutException e) { // Ignore a timeout here, we were only trying to update // a cached value to save peeling costs in the future. } catch (DhtException e) { // Ignore a database error, this was only an attempt to // fix a value that could be cached to save time later. } }
public Map<RefKey, RefData> getAll(Context options, RepositoryKey repository) throws DhtException, TimeoutException { Map<RefKey, RefData> out = new HashMap<RefKey, RefData>(); for (MemTable.Cell cell : table.scanFamily(repository.asBytes(), colRef)) { RefKey ref = RefKey.fromBytes(colRef.suffix(cell.getName())); try { out.put(ref, RefData.parseFrom(cell.getValue())); } catch (InvalidProtocolBufferException badCell) { throw new DhtException(MessageFormat.format( DhtText.get().invalidRefData, ref), badCell); } } return out; }
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); }
public boolean compareAndRemove(RefKey refKey, RefData oldData) throws DhtException, TimeoutException { RepositoryKey repo = refKey.getRepositoryKey(); return table.compareAndSet( // repo.asBytes(), // colRef.append(refKey.asBytes()), // oldData != RefDataUtil.NONE ? oldData.toByteArray() : null, // null); } }
private void cachePeeledState(Ref oldLeaf, Ref newLeaf) { // TODO(spearce) Use an ExecutorService here try { RepositoryKey repo = repository.getRepositoryKey(); RefKey key = RefKey.create(repo, newLeaf.getName()); RefData oldData = ((DhtRef) oldLeaf).getRefData(); RefData newData = ((DhtRef) newLeaf).getRefData(); db.ref().compareAndPut(key, oldData, newData); } catch (TimeoutException e) { // Ignore a timeout here, we were only trying to update // a cached value to save peeling costs in the future. } catch (DhtException e) { // Ignore a database error, this was only an attempt to // fix a value that could be cached to save time later. } }
public Map<RefKey, RefData> getAll(Context options, RepositoryKey repository) throws DhtException, TimeoutException { Map<RefKey, RefData> out = new HashMap<RefKey, RefData>(); for (MemTable.Cell cell : table.scanFamily(repository.asBytes(), colRef)) { RefKey ref = RefKey.fromBytes(colRef.suffix(cell.getName())); try { out.put(ref, RefData.parseFrom(cell.getValue())); } catch (InvalidProtocolBufferException badCell) { throw new DhtException(MessageFormat.format( DhtText.get().invalidRefData, ref), badCell); } } return out; }
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); }
public boolean compareAndPut(RefKey refKey, RefData oldData, RefData newData) throws DhtException, TimeoutException { RepositoryKey repo = refKey.getRepositoryKey(); return table.compareAndSet( // repo.asBytes(), // colRef.append(refKey.asBytes()), // oldData != RefDataUtil.NONE ? oldData.toByteArray() : null, // newData.toByteArray()); }
/** * @param repo * @param name * @return the key */ public static RefKey create(RepositoryKey repo, String name) { return new RefKey(repo.asInt(), name); }
@Override protected boolean tryLock(boolean deref) throws IOException { dstRef = getRef(); if (deref) dstRef = dstRef.getLeaf(); refKey = RefKey.create(repo, dstRef.getName()); oldData = ((DhtRef) dstRef).getRefData(); if (dstRef.isSymbolic()) setOldObjectId(null); else setOldObjectId(dstRef.getObjectId()); return true; }
@Override public String toString() { return "ref:" + asString(); } }
public String asString() { return getRepositoryKey().asString() + ":" + name; }
public boolean compareAndPut(RefKey refKey, RefData oldData, RefData newData) throws DhtException, TimeoutException { RepositoryKey repo = refKey.getRepositoryKey(); return table.compareAndSet( // repo.asBytes(), // colRef.append(refKey.asBytes()), // oldData != RefDataUtil.NONE ? oldData.toByteArray() : null, // newData.toByteArray()); }
/** * @param key * @return the key */ public static RefKey fromString(String key) { int c = key.indexOf(':'); int repo = parse32(Constants.encodeASCII(key.substring(0, c)), 0); String name = key.substring(c + 1); return new RefKey(repo, name); }
@Override protected boolean tryLock(boolean deref) throws IOException { dstRef = getRef(); if (deref) dstRef = dstRef.getLeaf(); refKey = RefKey.create(repo, dstRef.getName()); oldData = ((DhtRef) dstRef).getRefData(); if (dstRef.isSymbolic()) setOldObjectId(null); else setOldObjectId(dstRef.getObjectId()); return true; }
/** * @param key * @return the key */ public static RefKey fromString(String key) { int c = key.indexOf(':'); int repo = parse32(Constants.encodeASCII(key.substring(0, c)), 0); String name = key.substring(c + 1); return new RefKey(repo, name); }