You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by st...@apache.org on 2012/04/10 21:23:39 UTC

svn commit: r1311942 - in /hbase/trunk: pom.xml src/main/java/org/apache/hadoop/hbase/io/hfile/slab/SingleSizeCache.java

Author: stack
Date: Tue Apr 10 19:23:38 2012
New Revision: 1311942

URL: http://svn.apache.org/viewvc?rev=1311942&view=rev
Log:
HBASE-5739 Upgrade guava to 11.0.2

Modified:
    hbase/trunk/pom.xml
    hbase/trunk/src/main/java/org/apache/hadoop/hbase/io/hfile/slab/SingleSizeCache.java

Modified: hbase/trunk/pom.xml
URL: http://svn.apache.org/viewvc/hbase/trunk/pom.xml?rev=1311942&r1=1311941&r2=1311942&view=diff
==============================================================================
--- hbase/trunk/pom.xml (original)
+++ hbase/trunk/pom.xml Tue Apr 10 19:23:38 2012
@@ -986,7 +986,7 @@
     <commons-logging.version>1.1.1</commons-logging.version>
     <commons-math.version>2.1</commons-math.version>
     <commons-configuration.version>1.6</commons-configuration.version>
-    <guava.version>r09</guava.version>
+    <guava.version>11.0.2</guava.version>
     <jackson.version>1.5.5</jackson.version>
     <jasper.version>5.5.23</jasper.version>
     <jaxb-api.version>2.1</jaxb-api.version>

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=1311942&r1=1311941&r2=1311942&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 Apr 10 19:23:38 2012
@@ -39,8 +39,9 @@ import org.apache.hadoop.hbase.util.Byte
 import org.apache.hadoop.hbase.util.ClassSize;
 import org.apache.hadoop.util.StringUtils;
 
-import com.google.common.collect.MapEvictionListener;
-import com.google.common.collect.MapMaker;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.RemovalListener;
+import com.google.common.cache.RemovalNotification;
 
 /**
  * SingleSizeCache is a slab allocated cache that caches elements up to a single
@@ -93,18 +94,30 @@ public class SingleSizeCache implements 
     // This evictionListener is called whenever the cache automatically
     // evicts
     // something.
-    MapEvictionListener<BlockCacheKey, CacheablePair> listener = new MapEvictionListener<BlockCacheKey, CacheablePair>() {
-      @Override
-      public void onEviction(BlockCacheKey key, CacheablePair value) {
-        timeSinceLastAccess.set(System.nanoTime()
-            - value.recentlyAccessed.get());
-        stats.evict();
-        doEviction(key, value);
-      }
-    };
+    RemovalListener<BlockCacheKey, CacheablePair> listener =
+      new RemovalListener<BlockCacheKey, CacheablePair>() {
+        @Override
+        public void onRemoval(
+            RemovalNotification<BlockCacheKey, CacheablePair> notification) {
+          if (!notification.wasEvicted()) {
+            // Only process removals by eviction, not by replacement or
+            // explicit removal
+            return;
+          }
+          CacheablePair value = notification.getValue();
+          timeSinceLastAccess.set(System.nanoTime()
+              - value.recentlyAccessed.get());
+          stats.evict();
+          doEviction(notification.getKey(), value);
+        }
+      };
+
+    backingMap = CacheBuilder.newBuilder()
+        .maximumSize(numBlocks - 1)
+        .removalListener(listener)
+        .<BlockCacheKey, CacheablePair>build()
+        .asMap();
 
-    backingMap = new MapMaker().maximumSize(numBlocks - 1)
-        .evictionListener(listener).makeMap();
 
   }