HBASE-4289 Move spinlock to SingleSizeCache rather than the slab allocator

(Li Pi)


git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1163215 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Zhihong Yu 2011-08-30 14:00:58 +00:00
parent 5a7215a451
commit 7cac21df9c
3 changed files with 17 additions and 6 deletions

View File

@ -435,6 +435,8 @@ Release 0.91.0 - Unreleased
modifying TableMapReduceUtil.initTableMapperJob() (Brock Noland)
HBASE-4185 Add doc for new hfilev2 format
HBASE-4315 RS requestsPerSecond counter seems to be off (subramanian raghunathan)
HBASE-4289 Move spinlock to SingleSizeCache rather than the slab allocator
(Li Pi)
NEW FEATURES
HBASE-2001 Coprocessors: Colocate user code with regions (Mingjie Lai via

View File

@ -118,8 +118,16 @@ public class SingleSizeCache implements BlockCache {
@Override
public synchronized void cacheBlock(String blockName, Cacheable toBeCached) {
ByteBuffer storedBlock = backingStore.alloc(toBeCached
.getSerializedLength());
ByteBuffer storedBlock;
/*
* Spinlock if empty, Guava Mapmaker guarantees that we will not store more
* items than the memory we have allocated, but the Slab Allocator may still
* be empty if we have not yet completed eviction
*/
do {
storedBlock = backingStore.alloc(toBeCached.getSerializedLength());
} while (storedBlock == null);
CacheablePair newEntry = new CacheablePair(toBeCached.getDeserializer(),
storedBlock);

View File

@ -108,16 +108,17 @@ class Slab implements org.apache.hadoop.hbase.io.HeapSize {
}
/*
* This spinlocks if empty. Make sure your program can deal with that, and
* will complete eviction on time.
* This returns null if empty. Throws an exception if you try to allocate a
* bigger size than the allocator can handle.
*/
ByteBuffer alloc(int bufferSize) {
int newCapacity = Preconditions.checkPositionIndex(bufferSize, blockSize);
ByteBuffer returnedBuffer = buffers.poll();
while(returnedBuffer == null){
returnedBuffer = buffers.poll();
if (returnedBuffer == null) {
return null;
}
returnedBuffer.clear().limit(newCapacity);
return returnedBuffer;
}