@Override @SuppressWarnings("unchecked") public R build() throws IllegalArgumentException, DhtException, RepositoryNotFoundException { return (R) new DhtRepository(setup()); }
@Override public ObjectReader newReader() { return new DhtReader(repository.getObjectDatabase()); }
@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(); }
@Override public boolean exists() { return repository.getRepositoryKey() != null; }
@Override public void create(boolean bare) throws IOException { if (!bare) throw new IllegalArgumentException( DhtText.get().repositoryMustBeBare); if (getObjectDatabase().exists()) throw new DhtException(MessageFormat.format( DhtText.get().repositoryAlreadyExists, name.asString())); try { key = db.repository().nextKey(); db.repositoryIndex().putUnique(name, key); } catch (TimeoutException err) { throw new DhtTimeoutException(MessageFormat.format( DhtText.get().timeoutLocatingRepository, name), err); } String master = Constants.R_HEADS + Constants.MASTER; RefUpdate.Result result = updateRef(Constants.HEAD, true).link(master); if (result != RefUpdate.Result.NEW) throw new IOException(result.name()); }
@Override public boolean exists() { return repository.getRepositoryKey() != null; }
@Override public void create(boolean bare) throws IOException { if (!bare) throw new IllegalArgumentException( DhtText.get().repositoryMustBeBare); if (getObjectDatabase().exists()) throw new DhtException(MessageFormat.format( DhtText.get().repositoryAlreadyExists, name.asString())); try { key = db.repository().nextKey(); db.repositoryIndex().putUnique(name, key); } catch (TimeoutException err) { throw new DhtTimeoutException(MessageFormat.format( DhtText.get().timeoutLocatingRepository, name), err); } String master = Constants.R_HEADS + Constants.MASTER; RefUpdate.Result result = updateRef(Constants.HEAD, true).link(master); if (result != RefUpdate.Result.NEW) throw new IOException(result.name()); }
private Set<Map.Entry<RefKey, RefData>> scan() throws DhtException, TimeoutException { // TODO(spearce) Do we need to perform READ_REPAIR here? RepositoryKey repo = repository.getRepositoryKey(); return db.ref().getAll(Context.LOCAL, repo).entrySet(); }
@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(); }
@Override @SuppressWarnings("unchecked") public R build() throws IllegalArgumentException, DhtException, RepositoryNotFoundException { return (R) new DhtRepository(setup()); }
@Override public ObjectReader newReader() { return new DhtReader(repository.getObjectDatabase()); }
private Set<Map.Entry<RefKey, RefData>> scan() throws DhtException, TimeoutException { // TODO(spearce) Do we need to perform READ_REPAIR here? RepositoryKey repo = repository.getRepositoryKey(); return db.ref().getAll(Context.LOCAL, repo).entrySet(); }
ChunkKey findChunk(AnyObjectId objId) throws DhtException { if (objId instanceof RefDataUtil.IdWithChunk) return ((RefDataUtil.IdWithChunk) objId).getChunkKey(); ChunkKey key = repository.getRefDatabase().findChunk(objId); if (key != null) return key; ChunkAndOffset r = recentChunks.find(repo, objId); if (r != null) return r.chunk.getChunkKey(); for (ObjectInfo link : find(objId)) return link.getChunkKey(); return null; }
DhtInserter(DhtObjDatabase objdb) { this.objdb = objdb; this.repo = objdb.getRepository().getRepositoryKey(); this.db = objdb.getDatabase(); this.options = objdb.getInserterOptions(); }
ChunkKey findChunk(AnyObjectId objId) throws DhtException { if (objId instanceof RefDataUtil.IdWithChunk) return ((RefDataUtil.IdWithChunk) objId).getChunkKey(); ChunkKey key = repository.getRefDatabase().findChunk(objId); if (key != null) return key; ChunkAndOffset r = recentChunks.find(repo, objId); if (r != null) return r.chunk.getChunkKey(); for (ObjectInfo link : find(objId)) return link.getChunkKey(); return null; }
DhtInserter(DhtObjDatabase objdb) { this.objdb = objdb; this.repo = objdb.getRepository().getRepositoryKey(); this.db = objdb.getDatabase(); this.options = objdb.getInserterOptions(); }
key = ((RefDataUtil.IdWithChunk) objId).getChunkKey(); else key = repository.getRefDatabase().findChunk(objId);
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. } }
key = ((RefDataUtil.IdWithChunk) objId).getChunkKey(); else key = repository.getRefDatabase().findChunk(objId);
this.repo = objdb.getRepository().getRepositoryKey(); this.db = objdb.getDatabase(); this.options = objdb.getInserterOptions();