private Iterable<T> lookInCache(Iterable<T> objects) { RecentInfoCache infoCache = reader.getRecentInfoCache(); List<T> missing = null; for (T obj : objects) { if (needChunkOnly && obj instanceof RefDataUtil.IdWithChunk) { push(obj, ((RefDataUtil.IdWithChunk) obj).getChunkKey()); continue; } List<ObjectInfo> info = infoCache.get(obj); if (info != null && !info.isEmpty()) { push(obj, info.get(0)); } else { if (missing == null) { if (objects instanceof List<?>) missing = new ArrayList<T>(((List<?>) objects).size()); else missing = new ArrayList<T>(); } missing.add(obj); } } if (missing != null) return missing; return Collections.emptyList(); }
key = ((RefDataUtil.IdWithChunk) objId).getChunkKey(); else key = repository.getRefDatabase().findChunk(objId);
key = ((RefDataUtil.IdWithChunk) objId).getChunkKey(); else key = repository.getRefDatabase().findChunk(objId);
ObjectLoader open(RepositoryKey repo, AnyObjectId objId, int typeHint) throws IOException { if (objId instanceof IdWithChunk) { PackChunk chunk = get(((IdWithChunk) objId).getChunkKey()); if (chunk != null) { int pos = chunk.findOffset(repo, objId); if (0 <= pos) return PackChunk.read(chunk, pos, reader, typeHint); } // 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 PackChunk.read(n.chunk, pos, reader, typeHint); } } return null; }
ObjectLoader open(RepositoryKey repo, AnyObjectId objId, int typeHint) throws IOException { if (objId instanceof IdWithChunk) { PackChunk chunk = get(((IdWithChunk) objId).getChunkKey()); if (chunk != null) { int pos = chunk.findOffset(repo, objId); if (0 <= pos) return PackChunk.read(chunk, pos, reader, typeHint); } // 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 PackChunk.read(n.chunk, pos, reader, typeHint); } } return null; }
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; }
private Iterable<T> lookInCache(Iterable<T> objects) { RecentInfoCache infoCache = reader.getRecentInfoCache(); List<T> missing = null; for (T obj : objects) { if (needChunkOnly && obj instanceof RefDataUtil.IdWithChunk) { push(obj, ((RefDataUtil.IdWithChunk) obj).getChunkKey()); continue; } List<ObjectInfo> info = infoCache.get(obj); if (info != null && !info.isEmpty()) { push(obj, info.get(0)); } else { if (missing == null) { if (objects instanceof List<?>) missing = new ArrayList<T>(((List<?>) objects).size()); else missing = new ArrayList<T>(); } missing.add(obj); } } if (missing != null) return missing; return Collections.emptyList(); }
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; }
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; }
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; }
ChunkKey findChunk(AnyObjectId id) { RefCache c = cache.get(); if (c != null) { IdWithChunk i = c.hints.get(id); if (i != null) return i.getChunkKey(); } return null; }
@Override public String toString() { return name() + "->" + chunkKey; } }
@Override public String toString() { return name() + "->" + chunkKey; } }
private static ObjectId idFrom(RefData.Id src) { ObjectId id = ObjectId.fromString(src.getObjectName()); if (!src.hasChunkKey()) return id; return new IdWithChunk(id, ChunkKey.fromString(src.getChunkKey())); }
ChunkKey findChunk(AnyObjectId id) { RefCache c = cache.get(); if (c != null) { IdWithChunk i = c.hints.get(id); if (i != null) return i.getChunkKey(); } return null; }
private static ObjectId idFrom(RefData.Id src) { ObjectId id = ObjectId.fromString(src.getObjectName()); if (!src.hasChunkKey()) return id; return new IdWithChunk(id, ChunkKey.fromString(src.getChunkKey())); }