You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by mb...@apache.org on 2016/07/22 23:36:30 UTC

[6/6] hbase git commit: HBASE-16272 Overflow in ServerName's compareTo method (Huaxiang Sun)

HBASE-16272 Overflow in ServerName's compareTo method (Huaxiang Sun)


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

Branch: refs/heads/0.98
Commit: 6e54ac352ae2a7aae9cc804132126aee0c44b971
Parents: 10e06ca
Author: Matteo Bertozzi <ma...@cloudera.com>
Authored: Fri Jul 22 16:34:21 2016 -0700
Committer: Matteo Bertozzi <ma...@cloudera.com>
Committed: Fri Jul 22 16:34:21 2016 -0700

----------------------------------------------------------------------
 .../main/java/org/apache/hadoop/hbase/ServerName.java   |  2 +-
 .../org/apache/hadoop/hbase/io/hfile/LruBlockCache.java |  7 +++----
 .../hadoop/hbase/io/hfile/bucket/BucketCache.java       | 12 ++++--------
 .../java/org/apache/hadoop/hbase/util/HBaseFsck.java    |  2 +-
 4 files changed, 9 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/6e54ac35/hbase-client/src/main/java/org/apache/hadoop/hbase/ServerName.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/ServerName.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/ServerName.java
index ec8fcb2..ad03816 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/ServerName.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/ServerName.java
@@ -290,7 +290,7 @@ public class ServerName implements Comparable<ServerName>, Serializable {
     if (compare != 0) return compare;
     compare = this.getPort() - other.getPort();
     if (compare != 0) return compare;
-    return (int)(this.getStartcode() - other.getStartcode());
+    return Long.compare(this.getStartcode(), other.getStartcode());
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/hbase/blob/6e54ac35/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/LruBlockCache.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/LruBlockCache.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/LruBlockCache.java
index 06fa08e..b7cbbf8 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/LruBlockCache.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/LruBlockCache.java
@@ -714,8 +714,7 @@ public class LruBlockCache implements BlockCache, HeapSize {
     }
 
     public int compareTo(BlockBucket that) {
-      if(this.overflow() == that.overflow()) return 0;
-      return this.overflow() > that.overflow() ? 1 : -1;
+      return Long.compare(this.overflow(), that.overflow());
     }
 
     @Override
@@ -950,13 +949,13 @@ public class LruBlockCache implements BlockCache, HeapSize {
           public int compareTo(CachedBlock other) {
             int diff = this.getFilename().compareTo(other.getFilename());
             if (diff != 0) return diff;
-            diff = (int)(this.getOffset() - other.getOffset());
+            diff = Long.compare(this.getOffset(), other.getOffset());
             if (diff != 0) return diff;
             if (other.getCachedTime() < 0 || this.getCachedTime() < 0) {
               throw new IllegalStateException("" + this.getCachedTime() + ", " +
                 other.getCachedTime());
             }
-            return (int)(other.getCachedTime() - this.getCachedTime());
+            return Long.compare(other.getCachedTime(), this.getCachedTime());
           }
 
           @Override

http://git-wip-us.apache.org/repos/asf/hbase/blob/6e54ac35/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/BucketCache.java
----------------------------------------------------------------------
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 137a909..319d9c4 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
@@ -1090,9 +1090,7 @@ public class BucketCache implements BlockCache, HeapSize {
 
       @Override
       public int compare(BucketEntry o1, BucketEntry o2) {
-        long accessCounter1 = o1.accessCounter;
-        long accessCounter2 = o2.accessCounter;
-        return accessCounter1 < accessCounter2 ? 1 : accessCounter1 == accessCounter2 ? 0 : -1;
+        return Long.compare(o2.accessCounter, o1.accessCounter);
       }
     };
 
@@ -1213,9 +1211,7 @@ public class BucketCache implements BlockCache, HeapSize {
 
     @Override
     public int compareTo(BucketEntryGroup that) {
-      if (this.overflow() == that.overflow())
-        return 0;
-      return this.overflow() > that.overflow() ? 1 : -1;
+      return Long.compare(this.overflow(), that.overflow());
     }
 
     @Override
@@ -1362,13 +1358,13 @@ public class BucketCache implements BlockCache, HeapSize {
           public int compareTo(CachedBlock other) {
             int diff = this.getFilename().compareTo(other.getFilename());
             if (diff != 0) return diff;
-            diff = (int)(this.getOffset() - other.getOffset());
+            diff = Long.compare(this.getOffset(), other.getOffset());
             if (diff != 0) return diff;
             if (other.getCachedTime() < 0 || this.getCachedTime() < 0) {
               throw new IllegalStateException("" + this.getCachedTime() + ", " +
                 other.getCachedTime());
             }
-            return (int)(other.getCachedTime() - this.getCachedTime());
+            return Long.compare(other.getCachedTime(), this.getCachedTime());
           }
 
           @Override

http://git-wip-us.apache.org/repos/asf/hbase/blob/6e54ac35/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java
index 5a1f84f..67d4a4e 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java
@@ -3118,7 +3118,7 @@ public class HBaseFsck extends Configured {
       final Comparator<Cell> comp = new Comparator<Cell>() {
         @Override
         public int compare(Cell k1, Cell k2) {
-          return (int)(k1.getTimestamp() - k2.getTimestamp());
+          return Long.compare(k1.getTimestamp(), k2.getTimestamp());
         }
       };