@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); }
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 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 passes = 10000; BlockCacheKey blockCacheKey = new BlockCacheKey(); blockCacheKey.setBlock(block); blockCacheKey.setFile(file);