You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by la...@apache.org on 2012/07/02 19:57:18 UTC

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

Author: larsh
Date: Mon Jul  2 17:57:17 2012
New Revision: 1356379

URL: http://svn.apache.org/viewvc?rev=1356379&view=rev
Log:
HBASE-5955 Guava 11 drops MapEvictionListener and Hadoop 2.0.0-alpha requires it

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

Modified: hbase/branches/0.94/pom.xml
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/pom.xml?rev=1356379&r1=1356378&r2=1356379&view=diff
==============================================================================
--- hbase/branches/0.94/pom.xml (original)
+++ hbase/branches/0.94/pom.xml Mon Jul  2 17:57:17 2012
@@ -977,7 +977,7 @@
     <commons-math.version>2.1</commons-math.version>
     <commons-configuration.version>1.6</commons-configuration.version>
     <metrics-core.version>2.1.2</metrics-core.version>
-    <guava.version>r09</guava.version>
+    <guava.version>11.0.2</guava.version>
     <jackson.version>1.8.8</jackson.version>
     <jasper.version>5.5.23</jasper.version>
     <jaxb-api.version>2.1</jaxb-api.version>

Modified: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/io/hfile/slab/SingleSizeCache.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/io/hfile/slab/SingleSizeCache.java?rev=1356379&r1=1356378&r2=1356379&view=diff
==============================================================================
--- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/io/hfile/slab/SingleSizeCache.java (original)
+++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/io/hfile/slab/SingleSizeCache.java Mon Jul  2 17:57:17 2012
@@ -38,8 +38,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
@@ -91,18 +92,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();
 
   }