You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by te...@apache.org on 2011/08/30 16:00:59 UTC

svn commit: r1163215 - in /hbase/trunk: CHANGES.txt src/main/java/org/apache/hadoop/hbase/io/hfile/slab/SingleSizeCache.java src/main/java/org/apache/hadoop/hbase/io/hfile/slab/Slab.java

Author: tedyu
Date: Tue Aug 30 14:00:58 2011
New Revision: 1163215

URL: http://svn.apache.org/viewvc?rev=1163215&view=rev
Log:
HBASE-4289  Move spinlock to SingleSizeCache rather than the slab allocator 
               (Li Pi)

Modified:
    hbase/trunk/CHANGES.txt
    hbase/trunk/src/main/java/org/apache/hadoop/hbase/io/hfile/slab/SingleSizeCache.java
    hbase/trunk/src/main/java/org/apache/hadoop/hbase/io/hfile/slab/Slab.java

Modified: hbase/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hbase/trunk/CHANGES.txt?rev=1163215&r1=1163214&r2=1163215&view=diff
==============================================================================
--- hbase/trunk/CHANGES.txt (original)
+++ hbase/trunk/CHANGES.txt Tue Aug 30 14:00:58 2011
@@ -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

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/io/hfile/slab/SingleSizeCache.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/io/hfile/slab/SingleSizeCache.java?rev=1163215&r1=1163214&r2=1163215&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/io/hfile/slab/SingleSizeCache.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/io/hfile/slab/SingleSizeCache.java Tue Aug 30 14:00:58 2011
@@ -118,8 +118,16 @@ public class SingleSizeCache implements 
 
   @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);

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/io/hfile/slab/Slab.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/io/hfile/slab/Slab.java?rev=1163215&r1=1163214&r2=1163215&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/io/hfile/slab/Slab.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/io/hfile/slab/Slab.java Tue Aug 30 14:00:58 2011
@@ -108,16 +108,17 @@ class Slab implements org.apache.hadoop.
   }
 
   /*
-   * 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;
   }