You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by bu...@apache.org on 2017/09/11 07:42:32 UTC
[05/50] [abbrv] hbase git commit: HBASE-18757 Fix improper bitwise &
in bucketcache offset calculation
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 <yu...@gmail.com>
Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/f36fb11e
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/f36fb11e
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/f36fb11e
Branch: refs/heads/HBASE-18467
Commit: f36fb11eaff538cf54e1fe6497b26363a8d35c0a
Parents: f362ef7
Author: Zach York <zy...@amazon.com>
Authored: Thu Aug 31 10:25:32 2017 -0700
Committer: tedyu <yu...@gmail.com>
Committed: Tue Sep 5 14:11:54 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/f36fb11e/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 2a8afa7..58f3223 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
@@ -1285,8 +1285,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/f36fb11e/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 8cd665e..5a2a51c 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
@@ -388,4 +388,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());
+ }
}