Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id A554C200D0C for ; Wed, 6 Sep 2017 01:16:12 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id A3B29160DDD; Tue, 5 Sep 2017 23:16:12 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id D41621609EF for ; Wed, 6 Sep 2017 01:16:11 +0200 (CEST) Received: (qmail 18735 invoked by uid 500); 5 Sep 2017 23:16:09 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 18726 invoked by uid 99); 5 Sep 2017 23:16:09 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 05 Sep 2017 23:16:09 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id BCC23F3347; Tue, 5 Sep 2017 23:16:08 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: tedyu@apache.org To: commits@hbase.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: hbase git commit: HBASE-18757 Fix improper bitwise & in bucketcache offset calculation Date: Tue, 5 Sep 2017 23:16:08 +0000 (UTC) archived-at: Tue, 05 Sep 2017 23:16:12 -0000 Repository: hbase Updated Branches: refs/heads/branch-1.3 e43857d87 -> 6fcb15fd3 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 Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/6fcb15fd Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/6fcb15fd Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/6fcb15fd Branch: refs/heads/branch-1.3 Commit: 6fcb15fd3899a683577f7246b9967011fbd1c76b Parents: e43857d Author: Zach York Authored: Thu Aug 31 10:25:32 2017 -0700 Committer: tedyu Committed: Tue Sep 5 16:15:59 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/6fcb15fd/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 7aabb5c..c9081d4 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 @@ -1156,8 +1156,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/6fcb15fd/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 7aef1d6..5a2eb01 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 @@ -267,4 +267,13 @@ public class TestBucketCache { TEST_UTIL.cleanupTestDir(); } + + @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()); + } }