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; }
private void releaseLocation(BlockCacheLocation location) { if (location == null) { return; } int slabId = location.getSlabId(); int block = location.getBlock(); location.setRemoved(true); _locks[slabId].clear(block); _lockCounters[slabId].decrementAndGet(); _metrics.blockCacheEviction.incrementAndGet(); _metrics.blockCacheSize.decrementAndGet(); }
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; }