hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From te...@apache.org
Subject hbase git commit: HBASE-18757 Fix improper bitwise & in bucketcache offset calculation
Date Tue, 05 Sep 2017 22:11:04 GMT
Repository: hbase
Updated Branches:
  refs/heads/branch-1 8eacd32be -> 4733aa465


HBASE-18757 Fix improper bitwise & in bucketcache offset calculation

This correctly casts the operand to a long to avoid negative offsets created by sign extending
the integer operand.

Signed-off-by: tedyu <yuzhihong@gmail.com>


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

Branch: refs/heads/branch-1
Commit: 4733aa465531fc43d3448d47e2d1e0af70a86399
Parents: 8eacd32
Author: Zach York <zyork@amazon.com>
Authored: Thu Aug 31 10:25:32 2017 -0700
Committer: tedyu <yuzhihong@gmail.com>
Committed: Tue Sep 5 15:10:08 2017 -0700

----------------------------------------------------------------------
 .../apache/hadoop/hbase/io/hfile/bucket/BucketCache.java    | 4 ++--
 .../hadoop/hbase/io/hfile/bucket/TestBucketCache.java       | 9 +++++++++
 2 files changed, 11 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/4733aa46/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 c12a826..0aef1e8 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
@@ -1212,8 +1212,8 @@ public class BucketCache implements BlockCache, HeapSize {
     }
 
     long offset() { // Java has no unsigned numbers
-      long o = ((long) offsetBase) & 0xFFFFFFFF;
-      o += (((long) (offset1)) & 0xFF) << 32;
+      long o = ((long) offsetBase) & 0xFFFFFFFFL; //This needs the L cast otherwise it
will be sign extended as a negative number.
+      o += (((long) (offset1)) & 0xFF) << 32; //The 0xFF here does not need the
L cast because it is treated as a positive int.
       return o << 8;
     }
 

http://git-wip-us.apache.org/repos/asf/hbase/blob/4733aa46/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestBucketCache.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestBucketCache.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestBucketCache.java
index 186bb7f..49b3fe3 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestBucketCache.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestBucketCache.java
@@ -379,4 +379,13 @@ public class TestBucketCache {
     long expectedOutput = (long) Math.floor(bucketCache.getAllocator().getTotalSize() * partitionFactor
* minFactor);
     assertEquals(expectedOutput, bucketCache.getPartitionSize(partitionFactor));
   }
+
+  @Test
+  public void testOffsetProducesPositiveOutput() {
+    //This number is picked because it produces negative output if the values isn't ensured
to be positive.
+    //See HBASE-18757 for more information.
+    long testValue = 549888460800L;
+    BucketCache.BucketEntry bucketEntry = new BucketCache.BucketEntry(testValue, 10, 10L,
true);
+    assertEquals(testValue, bucketEntry.offset());
+  }
 }


Mime
View raw message