hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apurt...@apache.org
Subject hbase git commit: HBASE-16272 Overflow in ServerName's compareTo method (Huaxiang Sun and Andrew Purtell)
Date Mon, 01 Aug 2016 23:29:36 GMT
Repository: hbase
Updated Branches:
  refs/heads/0.98 6dfdc0d89 -> e8a146a78


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


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

Branch: refs/heads/0.98
Commit: e8a146a7845d3a6f86bba8f6dbee7c23054d8107
Parents: 6dfdc0d
Author: Andrew Purtell <apurtell@apache.org>
Authored: Mon Aug 1 16:15:00 2016 -0700
Committer: Andrew Purtell <apurtell@apache.org>
Committed: Mon Aug 1 16:21:24 2016 -0700

----------------------------------------------------------------------
 .../org/apache/hadoop/hbase/ServerName.java     |  3 +-
 .../org/apache/hadoop/hbase/util/LongUtils.java | 37 ++++++++++++++++++++
 .../hadoop/hbase/io/hfile/LruBlockCache.java    |  8 ++---
 .../hbase/io/hfile/bucket/BucketCache.java      | 13 +++----
 .../org/apache/hadoop/hbase/util/HBaseFsck.java |  2 +-
 5 files changed, 49 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/e8a146a7/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..feb9cc4 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
@@ -29,6 +29,7 @@ import org.apache.hadoop.hbase.protobuf.generated.ZooKeeperProtos;
 import org.apache.hadoop.hbase.protobuf.generated.ZooKeeperProtos.MetaRegionServer;
 import org.apache.hadoop.hbase.util.Addressing;
 import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.util.LongUtils;
 
 import java.io.Serializable;
 import java.util.ArrayList;
@@ -290,7 +291,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 LongUtils.compare(this.getStartcode(), other.getStartcode());
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/hbase/blob/e8a146a7/hbase-common/src/main/java/org/apache/hadoop/hbase/util/LongUtils.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/LongUtils.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/LongUtils.java
new file mode 100644
index 0000000..7dd2a2a
--- /dev/null
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/LongUtils.java
@@ -0,0 +1,37 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hbase.util;
+
+public class LongUtils {
+
+  /**
+   * Compare two longs numerically.
+   *
+   * @param x the first long to compare
+   * @param y the second  long to compare
+   * @return 0 if equal, -1 if x < y, +1 if x > y
+   */  
+  public static int compare(long x, long y) {
+    if (x < y) return -1;
+    if (x == y) return 0;
+    return 1;
+  }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/hbase/blob/e8a146a7/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 4afd556..147561d 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
@@ -45,6 +45,7 @@ import org.apache.hadoop.hbase.io.hfile.bucket.BucketCache;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.ClassSize;
 import org.apache.hadoop.hbase.util.HasThread;
+import org.apache.hadoop.hbase.util.LongUtils;
 import org.apache.hadoop.hbase.util.Threads;
 import org.apache.hadoop.util.StringUtils;
 import org.codehaus.jackson.annotate.JsonIgnoreProperties;
@@ -714,8 +715,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 LongUtils.compare(this.overflow(), that.overflow());
     }
 
     @Override
@@ -950,13 +950,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 = LongUtils.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 LongUtils.compare(other.getCachedTime(), this.getCachedTime());
           }
 
           @Override

http://git-wip-us.apache.org/repos/asf/hbase/blob/e8a146a7/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..1292124 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
@@ -67,6 +67,7 @@ import org.apache.hadoop.hbase.util.ConcurrentIndex;
 import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
 import org.apache.hadoop.hbase.util.HasThread;
 import org.apache.hadoop.hbase.util.IdLock;
+import org.apache.hadoop.hbase.util.LongUtils;
 import org.apache.hadoop.util.StringUtils;
 
 import com.google.common.annotations.VisibleForTesting;
@@ -1090,9 +1091,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 LongUtils.compare(o2.accessCounter, o1.accessCounter);
       }
     };
 
@@ -1213,9 +1212,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 LongUtils.compare(this.overflow(), that.overflow());
     }
 
     @Override
@@ -1362,13 +1359,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 = LongUtils.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 LongUtils.compare(other.getCachedTime(), this.getCachedTime());
           }
 
           @Override

http://git-wip-us.apache.org/repos/asf/hbase/blob/e8a146a7/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..8eb6dbc 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 LongUtils.compare(k1.getTimestamp(), k2.getTimestamp());
         }
       };
 


Mime
View raw message