hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From syuanji...@apache.org
Subject [11/14] hbase git commit: HBASE-14624 BucketCache.freeBlock is too expensive
Date Mon, 26 Oct 2015 17:34:17 GMT
HBASE-14624 BucketCache.freeBlock is too expensive


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/95978477
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/95978477
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/95978477

Branch: refs/heads/hbase-12439
Commit: 95978477f8565defb3c4792f901e833abf63f768
Parents: f8528f6
Author: tedyu <yuzhihong@gmail.com>
Authored: Sat Oct 24 18:45:21 2015 -0700
Committer: tedyu <yuzhihong@gmail.com>
Committed: Sat Oct 24 18:45:21 2015 -0700

----------------------------------------------------------------------
 .../hbase/io/hfile/bucket/BucketAllocator.java  | 36 +++++++++++---------
 1 file changed, 19 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/95978477/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/BucketAllocator.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/BucketAllocator.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/BucketAllocator.java
index faa8724..1e8cb7d 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/BucketAllocator.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/BucketAllocator.java
@@ -21,11 +21,10 @@
 package org.apache.hadoop.hbase.io.hfile.bucket;
 
 import java.util.Arrays;
-import java.util.LinkedList;
-import java.util.List;
 import java.util.Map;
 import java.util.concurrent.atomic.AtomicLong;
 
+import org.apache.commons.collections.map.LinkedMap;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.hbase.classification.InterfaceAudience;
@@ -173,22 +172,22 @@ public final class BucketAllocator {
   final class BucketSizeInfo {
     // Free bucket means it has space to allocate a block;
     // Completely free bucket means it has no block.
-    private List<Bucket> bucketList, freeBuckets, completelyFreeBuckets;
+    private LinkedMap bucketList, freeBuckets, completelyFreeBuckets;
     private int sizeIndex;
 
     BucketSizeInfo(int sizeIndex) {
-      bucketList = new LinkedList<Bucket>();
-      freeBuckets = new LinkedList<Bucket>();
-      completelyFreeBuckets = new LinkedList<Bucket>();
+      bucketList = new LinkedMap();
+      freeBuckets = new LinkedMap();
+      completelyFreeBuckets = new LinkedMap();
       this.sizeIndex = sizeIndex;
     }
 
     public synchronized void instantiateBucket(Bucket b) {
       assert b.isUninstantiated() || b.isCompletelyFree();
       b.reconfigure(sizeIndex, bucketSizes, bucketCapacity);
-      bucketList.add(b);
-      freeBuckets.add(b);
-      completelyFreeBuckets.add(b);
+      bucketList.put(b, b);
+      freeBuckets.put(b, b);
+      completelyFreeBuckets.put(b, b);
     }
 
     public int sizeIndex() {
@@ -201,8 +200,10 @@ public final class BucketAllocator {
      */
     public long allocateBlock() {
       Bucket b = null;
-      if (freeBuckets.size() > 0) // Use up an existing one first...
-        b = freeBuckets.get(freeBuckets.size() - 1);
+      if (freeBuckets.size() > 0) {
+        // Use up an existing one first...
+        b = (Bucket) freeBuckets.lastKey();
+      }
       if (b == null) {
         b = grabGlobalCompletelyFreeBucket();
         if (b != null) instantiateBucket(b);
@@ -227,7 +228,7 @@ public final class BucketAllocator {
       }
 
       if (completelyFreeBuckets.size() > 0) {
-        b = completelyFreeBuckets.get(0);
+        b = (Bucket) completelyFreeBuckets.firstKey();
         removeBucket(b);
       }
       return b;
@@ -241,17 +242,18 @@ public final class BucketAllocator {
     }
 
     public void freeBlock(Bucket b, long offset) {
-      assert bucketList.contains(b);
+      assert bucketList.containsKey(b);
       // else we shouldn't have anything to free...
-      assert (!completelyFreeBuckets.contains(b));
+      assert (!completelyFreeBuckets.containsKey(b));
       b.free(offset);
-      if (!freeBuckets.contains(b)) freeBuckets.add(b);
-      if (b.isCompletelyFree()) completelyFreeBuckets.add(b);
+      if (!freeBuckets.containsKey(b)) freeBuckets.put(b, b);
+      if (b.isCompletelyFree()) completelyFreeBuckets.put(b, b);
     }
 
     public synchronized IndexStatistics statistics() {
       long free = 0, used = 0;
-      for (Bucket b : bucketList) {
+      for (Object obj : bucketList.keySet()) {
+        Bucket b = (Bucket) obj;
         free += b.freeCount();
         used += b.usedCount();
       }


Mime
View raw message