@Override protected int readDatabase(byte[] dst, int pos, int cnt) throws IOException { int n = dbChunk.read(dbPtr, dst, pos, cnt); if (0 < n) { dbPtr += n; return n; } // ChunkMeta for fragments is delayed writing, so it isn't available // on the chunk if the chunk was read-back from the database. Use // our copy of ChunkMeta instead of the PackChunk's copy. ChunkMeta meta = chunkMeta.get(dbChunk.getChunkKey()); if (meta == null) return 0; ChunkKey next = ChunkMetaUtil.getNextFragment(meta, dbChunk.getChunkKey()); if (next == null) return 0; seekChunk(next, false); n = dbChunk.read(0, dst, pos, cnt); dbPtr = n; return n; }
@Override public int read(byte[] dstbuf, int dstptr, int dstlen) throws IOException { if (0 == dstlen) return 0; int n = pc.read(ptr, dstbuf, dstptr, dstlen); if (n == 0) { if (fragment == meta.getFragmentCount()) return -1; pc = ctx.getChunk(ChunkKey.fromString( meta.getFragment(++fragment))); ptr = 0; n = pc.read(ptr, dstbuf, dstptr, dstlen); if (n == 0) return -1; } ptr += n; return n; }
@Override protected int readDatabase(byte[] dst, int pos, int cnt) throws IOException { int n = dbChunk.read(dbPtr, dst, pos, cnt); if (0 < n) { dbPtr += n; return n; } // ChunkMeta for fragments is delayed writing, so it isn't available // on the chunk if the chunk was read-back from the database. Use // our copy of ChunkMeta instead of the PackChunk's copy. ChunkMeta meta = chunkMeta.get(dbChunk.getChunkKey()); if (meta == null) return 0; ChunkKey next = ChunkMetaUtil.getNextFragment(meta, dbChunk.getChunkKey()); if (next == null) return 0; seekChunk(next, false); n = dbChunk.read(0, dst, pos, cnt); dbPtr = n; return n; }
@Override public int read(byte[] dstbuf, int dstptr, int dstlen) throws IOException { if (0 == dstlen) return 0; int n = pc.read(ptr, dstbuf, dstptr, dstlen); if (n == 0) { if (fragment == meta.getFragmentCount()) return -1; pc = ctx.getChunk(ChunkKey.fromString( meta.getFragment(++fragment))); ptr = 0; n = pc.read(ptr, dstbuf, dstptr, dstlen); if (n == 0) return -1; } ptr += n; return n; }
@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 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; }
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; }
public ObjectLoader open() throws IOException { ChunkKey chunkKey = current.chunkKey; // Objects returned by the queue are clustered by chunk. This object // is either in the current chunk, or are the next chunk ready on the // prefetcher. Anything else is a programming error. // PackChunk chunk; if (currChunk != null && chunkKey.equals(currChunk.getChunkKey())) chunk = currChunk; else { chunk = prefetcher.get(chunkKey); if (chunk == null) throw new DhtMissingChunkException(chunkKey); currChunk = chunk; reader.recentChunk(chunk); } if (current.info != null) { int ptr = current.info.getOffset(); int type = current.info.getType(); return PackChunk.read(chunk, ptr, reader, type); } else { int ptr = chunk.findOffset(repo, current.object); if (ptr < 0) throw DhtReader.missing(current.object, ObjectReader.OBJ_ANY); return PackChunk.read(chunk, ptr, reader, ObjectReader.OBJ_ANY); } }
public ObjectLoader open() throws IOException { ChunkKey chunkKey = current.chunkKey; // Objects returned by the queue are clustered by chunk. This object // is either in the current chunk, or are the next chunk ready on the // prefetcher. Anything else is a programming error. // PackChunk chunk; if (currChunk != null && chunkKey.equals(currChunk.getChunkKey())) chunk = currChunk; else { chunk = prefetcher.get(chunkKey); if (chunk == null) throw new DhtMissingChunkException(chunkKey); currChunk = chunk; reader.recentChunk(chunk); } if (current.info != null) { int ptr = current.info.getOffset(); int type = current.info.getType(); return PackChunk.read(chunk, ptr, reader, type); } else { int ptr = chunk.findOffset(repo, current.object); if (ptr < 0) throw DhtReader.missing(current.object, ObjectReader.OBJ_ANY); return PackChunk.read(chunk, ptr, reader, ObjectReader.OBJ_ANY); } }