public boolean fetch(BlockCacheKey blockCacheKey, byte[] buffer) { checkLength(buffer); return fetch(blockCacheKey, buffer, 0, 0, _blockSize); }
@Override public long size() { return _blockCache.getSize(); } }
long totalMemory = 2 * slabSize; BlockCache blockCache = new BlockCache(new BlurMetrics(new Configuration()), true,totalMemory,slabSize,blockSize); byte[] buffer = new byte[1024]; Random random = new Random(); blockCacheKey.setFile(file); if (blockCache.fetch(blockCacheKey, buffer)) { hitsInCache.incrementAndGet(); } else { blockCache.store(blockCacheKey, testData); storeTime += (System.nanoTime() - t1); if (blockCache.fetch(blockCacheKey, buffer)) { fetchTime += (System.nanoTime() - t3); assertTrue(Arrays.equals(testData, buffer)); System.out.println("Store = " + (storeTime / (double) passes) / 1000000.0); System.out.println("Fetch = " + (fetchTime / (double) passes) / 1000000.0); System.out.println("# of Elements = " + blockCache.getSize());
public boolean store(BlockCacheKey blockCacheKey, byte[] data) { checkLength(data); BlockCacheLocation location = _cache.get(blockCacheKey); boolean newLocation = false; if (location == null) { newLocation = true; location = new BlockCacheLocation(); if (!findEmptyLocation(location)) { return false; } } if (location.isRemoved()) { return false; } int slabId = location.getSlabId(); int offset = location.getBlock() * _blockSize; ByteBuffer slab = getSlab(slabId); slab.position(offset); slab.put(data, 0, _blockSize); if (newLocation) { releaseLocation(_cache.put(blockCacheKey.clone(), location)); _metrics.blockCacheSize.incrementAndGet(); } return true; }
@Override public void update(String name, long blockId, byte[] buffer) { Integer file = _names.get(name); if (file == null) { file = _counter.incrementAndGet(); _names.put(name, file); } BlockCacheKey blockCacheKey = new BlockCacheKey(); blockCacheKey.setBlock(blockId); blockCacheKey.setFile(file); _blockCache.store(blockCacheKey, buffer); }
@Override public boolean fetch(String name, long blockId, int blockOffset, byte[] b, int off, int lengthToReadInBlock) { Integer file = _names.get(name); if (file == null) { return false; } BlockCacheKey blockCacheKey = new BlockCacheKey(); blockCacheKey.setBlock(blockId); blockCacheKey.setFile(file); boolean fetch = _blockCache.fetch(blockCacheKey, b, blockOffset, off, lengthToReadInBlock); if (fetch) { _blurMetrics.blockCacheHit.incrementAndGet(); } else { _blurMetrics.blockCacheMiss.incrementAndGet(); } return fetch; }
int slabSize = (int) (totalMemory / 2); BlockCache blockCache = new BlockCache(new BlurMetrics(new Configuration()), true, totalMemory, slabSize, blockSize); BlurMetrics metrics = new BlurMetrics(new Configuration()); BlockDirectoryCache cache = new BlockDirectoryCache(blockCache, metrics);
public boolean fetch(BlockCacheKey blockCacheKey, byte[] buffer, int blockOffset, int off, int length) { BlockCacheLocation location = _cache.get(blockCacheKey); if (location == null) { return false; } if (location.isRemoved()) { return false; } int slabId = location.getSlabId(); int offset = location.getBlock() * _blockSize; location.touch(); ByteBuffer slab = getSlab(slabId); slab.position(offset + blockOffset); slab.get(buffer, off, length); return true; }
int slabSize = (int) (totalMemory / 2); BlockCache blockCache = new BlockCache(new BlurMetrics(new Configuration()), true, totalMemory, slabSize, blockSize); BlurMetrics metrics = new BlurMetrics(new Configuration()); BlockDirectoryCache cache = new BlockDirectoryCache(blockCache, metrics);