ChunkAndOffset getChunkGently(AnyObjectId objId) { return recentChunks.find(repo, objId); }
ChunkAndOffset find(RepositoryKey repo, AnyObjectId objId) { if (objId instanceof IdWithChunk) { PackChunk chunk = get(((IdWithChunk) objId).getChunkKey()); if (chunk != null) { int pos = chunk.findOffset(repo, objId); if (0 <= pos) return new ChunkAndOffset(chunk, pos); } // IdWithChunk is only a hint, and can be wrong. Locally // searching is faster than looking in the Database. } for (Node n = lruHead; n != null; n = n.next) { int pos = n.chunk.findOffset(repo, objId); if (0 <= pos) { hit(n); stats.recentChunks_Hits++; return new ChunkAndOffset(n.chunk, pos); } } return null; }
PackChunk getChunk(ChunkKey key) throws DhtException { PackChunk chunk = recentChunks.get(key); if (chunk != null) return chunk; chunk = load(key); if (chunk != null) return chunk; throw new DhtMissingChunkException(key); }
PackChunk get(ChunkKey key) { Node n = byKey.get(key); if (n != null) { hit(n); stats.recentChunks_Hits++; return n.chunk; } stats.recentChunks_Miss++; return null; }
@Override public ObjectLoader open(AnyObjectId objId, int typeHint) throws MissingObjectException, IncorrectObjectTypeException, IOException { ObjectLoader ldr = recentChunks.open(repo, objId, typeHint); if (ldr != null) return ldr; ChunkAndOffset p = getChunk(objId, typeHint, false); ldr = PackChunk.read(p.chunk, p.offset, this, typeHint); recentChunk(p.chunk); return ldr; }
@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(); }
DhtReader(DhtObjDatabase objdb) { this.repository = objdb.getRepository(); this.repo = objdb.getRepository().getRepositoryKey(); this.db = objdb.getDatabase(); this.readerOptions = objdb.getReaderOptions(); this.inserterOptions = objdb.getInserterOptions(); this.stats = new Statistics(); this.recentInfo = new RecentInfoCache(getOptions()); this.recentChunks = new RecentChunks(this); this.deltaBaseCache = new DeltaBaseCache(this); }
@Override public void release() { recentChunks.clear(); endPrefetch(); InflaterCache.release(inflater); inflater = null; super.release(); }
void recentChunk(PackChunk chunk) { recentChunks.put(chunk); }
ChunkAndOffset find(RepositoryKey repo, AnyObjectId objId) { if (objId instanceof IdWithChunk) { PackChunk chunk = get(((IdWithChunk) objId).getChunkKey()); if (chunk != null) { int pos = chunk.findOffset(repo, objId); if (0 <= pos) return new ChunkAndOffset(chunk, pos); } // IdWithChunk is only a hint, and can be wrong. Locally // searching is faster than looking in the Database. } for (Node n = lruHead; n != null; n = n.next) { int pos = n.chunk.findOffset(repo, objId); if (0 <= pos) { hit(n); stats.recentChunks_Hits++; return new ChunkAndOffset(n.chunk, pos); } } return null; }
PackChunk getChunk(ChunkKey key) throws DhtException { PackChunk chunk = recentChunks.get(key); if (chunk != null) return chunk; chunk = load(key); if (chunk != null) return chunk; throw new DhtMissingChunkException(key); }
PackChunk get(ChunkKey key) { Node n = byKey.get(key); if (n != null) { hit(n); stats.recentChunks_Hits++; return n.chunk; } stats.recentChunks_Miss++; return null; }
@Override public ObjectLoader open(AnyObjectId objId, int typeHint) throws MissingObjectException, IncorrectObjectTypeException, IOException { ObjectLoader ldr = recentChunks.open(repo, objId, typeHint); if (ldr != null) return ldr; ChunkAndOffset p = getChunk(objId, typeHint, false); ldr = PackChunk.read(p.chunk, p.offset, this, typeHint); recentChunk(p.chunk); return ldr; }
@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(); }
DhtReader(DhtObjDatabase objdb) { this.repository = objdb.getRepository(); this.repo = objdb.getRepository().getRepositoryKey(); this.db = objdb.getDatabase(); this.readerOptions = objdb.getReaderOptions(); this.inserterOptions = objdb.getInserterOptions(); this.stats = new Statistics(); this.recentInfo = new RecentInfoCache(getOptions()); this.recentChunks = new RecentChunks(this); this.deltaBaseCache = new DeltaBaseCache(this); }
@Override public void release() { recentChunks.clear(); endPrefetch(); InflaterCache.release(inflater); inflater = null; super.release(); }