From 7e1e818bbc0bed59c12fbd8c003eaed702cf16ad Mon Sep 17 00:00:00 2001 From: Nick Dimiduk Date: Wed, 13 Aug 2014 21:07:31 -0700 Subject: [PATCH] HBASE-11550 Custom value for BUCKET_CACHE_BUCKETS_KEY should be sorted (Gustavo Anatoly) --- .../main/java/org/apache/hadoop/hbase/io/hfile/CacheConfig.java | 2 +- .../org/apache/hadoop/hbase/io/hfile/bucket/BucketAllocator.java | 9 ++++----- .../org/apache/hadoop/hbase/io/hfile/bucket/BucketCache.java | 6 ++---- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/CacheConfig.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/CacheConfig.java index 03d11ae..9153c8a 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/CacheConfig.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/CacheConfig.java @@ -426,7 +426,7 @@ public class CacheConfig { if (configuredBucketSizes != null) { bucketSizes = new int[configuredBucketSizes.length]; for (int i = 0; i < configuredBucketSizes.length; i++) { - bucketSizes[i] = Integer.parseInt(configuredBucketSizes[i]); + bucketSizes[i] = Integer.parseInt(configuredBucketSizes[i].trim()); } } if (combinedWithLru) { 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 1cfb408..db50e75 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 @@ -20,6 +20,7 @@ package org.apache.hadoop.hbase.io.hfile.bucket; +import java.util.Arrays; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -27,6 +28,7 @@ import java.util.concurrent.atomic.AtomicLong; import com.google.common.base.Objects; import com.google.common.base.Preconditions; +import com.google.common.primitives.Ints; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.classification.InterfaceAudience; @@ -298,11 +300,8 @@ public final class BucketAllocator { BucketAllocator(long availableSpace, int[] bucketSizes) throws BucketAllocatorException { this.bucketSizes = bucketSizes == null ? DEFAULT_BUCKET_SIZES : bucketSizes; - int largestBucket = this.bucketSizes[0]; - for (int i : this.bucketSizes) { - largestBucket = Math.max(largestBucket, i); - } - this.bigItemSize = largestBucket; + Arrays.sort(this.bucketSizes); + this.bigItemSize = Ints.max(this.bucketSizes); this.bucketCapacity = FEWEST_ITEMS_IN_BUCKET * bigItemSize; buckets = new Bucket[(int) (availableSpace / bucketCapacity)]; if (buckets.length < this.bucketSizes.length) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/BucketCache.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/BucketCache.java index acf43f3..981d575 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/BucketCache.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/BucketCache.java @@ -169,7 +169,6 @@ public class BucketCache implements BlockCache, HeapSize { private long cacheCapacity; /** Approximate block size */ private final long blockSize; - private final int[] bucketSizes; /** Duration of IO errors tolerated before we disable cache, 1 min as default */ private final int ioErrorsTolerationDuration; @@ -235,7 +234,6 @@ public class BucketCache implements BlockCache, HeapSize { this.cacheCapacity = capacity; this.persistencePath = persistencePath; this.blockSize = blockSize; - this.bucketSizes = bucketSizes; this.ioErrorsTolerationDuration = ioErrorsTolerationDuration; bucketAllocator = new BucketAllocator(capacity, bucketSizes); @@ -251,7 +249,7 @@ public class BucketCache implements BlockCache, HeapSize { if (ioEngine.isPersistent() && persistencePath != null) { try { - retrieveFromFile(); + retrieveFromFile(bucketSizes); } catch (IOException ioex) { LOG.error("Can't restore from file because of", ioex); } catch (ClassNotFoundException cnfe) { @@ -869,7 +867,7 @@ public class BucketCache implements BlockCache, HeapSize { } @SuppressWarnings("unchecked") - private void retrieveFromFile() throws IOException, BucketAllocatorException, + private void retrieveFromFile(int[] bucketSizes) throws IOException, BucketAllocatorException, ClassNotFoundException { File persistenceFile = new File(persistencePath); if (!persistenceFile.exists()) { -- 1.9.0