From d47242247552bbad2df578c89501a6c6789c89c8 Mon Sep 17 00:00:00 2001 From: Peter Somogyi Date: Tue, 30 Jan 2018 10:14:08 +0100 Subject: [PATCH] HBASE-19884 BucketEntryGroup's equals, hashCode and compareTo methods are not consistent Move back to default equals and hashCode. Remove compareTo and Comparator to PriorityQueue. Signed-off-by: Michael Stack --- .../hbase/io/hfile/bucket/BucketCache.java | 29 ++----------------- 1 file changed, 3 insertions(+), 26 deletions(-) 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 bd2b9c8797f..e9129d2f5b2 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 @@ -36,7 +36,6 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.NavigableSet; -import java.util.Objects; import java.util.PriorityQueue; import java.util.Set; import java.util.concurrent.ArrayBlockingQueue; @@ -821,7 +820,8 @@ public class BucketCache implements BlockCache, HeapSize { } } - PriorityQueue bucketQueue = new PriorityQueue<>(3); + PriorityQueue bucketQueue = new PriorityQueue<>(3, + Comparator.comparingLong(BucketEntryGroup::overflow)); bucketQueue.add(bucketSingle); bucketQueue.add(bucketMulti); @@ -1350,7 +1350,7 @@ public class BucketCache implements BlockCache, HeapSize { * the eviction algorithm takes the appropriate number of elements out of each * according to configuration parameters and their relative sizes. */ - private class BucketEntryGroup implements Comparable { + private class BucketEntryGroup { private CachedEntryQueue queue; private long totalSize = 0; @@ -1390,29 +1390,6 @@ public class BucketCache implements BlockCache, HeapSize { public long totalSize() { return totalSize; } - - @Override - public int compareTo(BucketEntryGroup that) { - return Long.compare(this.overflow(), that.overflow()); - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - BucketEntryGroup that = (BucketEntryGroup) o; - return totalSize == that.totalSize && bucketSize == that.bucketSize - && Objects.equals(queue, that.queue); - } - - @Override - public int hashCode() { - return Objects.hash(queue, totalSize, bucketSize); - } } /**