DfsBlock quickCopy(DfsPackFile p, long pos, long cnt) throws IOException { pin(p, pos); if (block.contains(p.key, pos + (cnt - 1))) return block; return null; }
void pin(BlockBasedFile file, long position) throws IOException { if (block == null || !block.contains(file.key, position)) { // If memory is low, we may need what is in our window field to // be cleaned up by the GC during the get for the next window. // So we always clear it, even though we are just going to set // it again. block = null; block = file.getOrLoadBlock(position, this); } }
/** * Quickly check if the cache contains block 0 of the given stream. * <p> * This can be useful for sophisticated pre-read algorithms to quickly * determine if a file is likely already in cache, especially small * reftables which may be smaller than a typical DFS block size. * * @param key * the file to check. * @return true if block 0 (the first block) is in the cache. */ public boolean hasBlock0(DfsStreamKey key) { HashEntry e1 = table.get(slot(key, 0)); DfsBlock v = scan(e1, key, 0); return v != null && v.contains(key, 0); }
if (readBlock == null || !readBlock.contains(packKey, readPos)) { long start = toBlockStart(readPos); readBlock = blockCache.get(packKey, start);
HashEntry e1 = table.get(slot); DfsBlock v = scan(e1, key, position); if (v != null && v.contains(key, requestedPosition)) { ctx.stats.blockCacheHit++; getStat(statHit, key).incrementAndGet(); if (v.contains(file.key, requestedPosition)) return v; return getOrLoad(file, requestedPosition, ctx, fileChannel);
DfsBlock quickCopy(DfsPackFile p, long pos, long cnt) throws IOException { pin(p, pos); if (block.contains(p.key, pos + (cnt - 1))) return block; return null; }
void pin(DfsPackFile pack, long position) throws IOException { DfsBlock b = block; if (b == null || !b.contains(pack.key, position)) { // If memory is low, we may need what is in our window field to // be cleaned up by the GC during the get for the next window. // So we always clear it, even though we are just going to set // it again. block = null; block = pack.getOrLoadBlock(position, this); } }
DfsBlock quickCopy(DfsPackFile p, long pos, long cnt) throws IOException { pin(p, pos); if (block.contains(p.key, pos + (cnt - 1))) return block; return null; }
void pin(BlockBasedFile file, long position) throws IOException { if (block == null || !block.contains(file.key, position)) { // If memory is low, we may need what is in our window field to // be cleaned up by the GC during the get for the next window. // So we always clear it, even though we are just going to set // it again. block = null; block = file.getOrLoadBlock(position, this); } }
/** * Quickly check if the cache contains block 0 of the given stream. * <p> * This can be useful for sophisticated pre-read algorithms to quickly * determine if a file is likely already in cache, especially small * reftables which may be smaller than a typical DFS block size. * * @param key * the file to check. * @return true if block 0 (the first block) is in the cache. */ public boolean hasBlock0(DfsStreamKey key) { HashEntry e1 = table.get(slot(key, 0)); DfsBlock v = scan(e1, key, 0); return v != null && v.contains(key, 0); }
@Override protected int readDatabase(byte[] dst, int pos, int cnt) throws IOException { if (cnt == 0) return 0; if (currPos <= readPos) { // Requested read is still buffered. Copy direct from buffer. int p = (int) (readPos - currPos); int n = Math.min(cnt, currEnd - p); if (n == 0) throw new EOFException(); System.arraycopy(currBuf, p, dst, pos, n); readPos += n; return n; } if (readBlock == null || !readBlock.contains(packKey, readPos)) { long start = toBlockStart(readPos); readBlock = blockCache.get(packKey, start); if (readBlock == null) { int size = (int) Math.min(blockSize, packEnd - start); byte[] buf = new byte[size]; if (read(start, buf, 0, size) != size) throw new EOFException(); readBlock = new DfsBlock(packKey, start, buf); blockCache.put(readBlock); } } int n = readBlock.copy(readPos, dst, pos, cnt); readPos += n; return n; }
if (readBlock == null || !readBlock.contains(packKey, readPos)) { long start = toBlockStart(readPos); readBlock = blockCache.get(packKey, start);
if (v.contains(pack.key, requestedPosition)) return v; return getOrLoad(pack, requestedPosition, ctx);
HashEntry e1 = table.get(slot); DfsBlock v = scan(e1, key, position); if (v != null && v.contains(key, requestedPosition)) { ctx.stats.blockCacheHit++; getStat(statHit, key).incrementAndGet(); if (v.contains(file.key, requestedPosition)) return v; return getOrLoad(file, requestedPosition, ctx, fileChannel);