Return-Path: X-Original-To: apmail-hbase-commits-archive@www.apache.org Delivered-To: apmail-hbase-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B6B4C17E8C for ; Tue, 17 Feb 2015 20:41:25 +0000 (UTC) Received: (qmail 40485 invoked by uid 500); 17 Feb 2015 20:41:25 -0000 Delivered-To: apmail-hbase-commits-archive@hbase.apache.org Received: (qmail 40439 invoked by uid 500); 17 Feb 2015 20:41:25 -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 40430 invoked by uid 99); 17 Feb 2015 20:41:25 -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, 17 Feb 2015 20:41:25 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 70A13E0779; Tue, 17 Feb 2015 20:41:25 +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: <7e6065b4936e45509b93cb434204b93b@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: hbase git commit: HBASE-12948 Calling Increment#addColumn on the same column multiple times produces wrong result (hongyu bi) Date: Tue, 17 Feb 2015 20:41:25 +0000 (UTC) Repository: hbase Updated Branches: refs/heads/branch-1 ea0bdd3df -> d10639dcc HBASE-12948 Calling Increment#addColumn on the same column multiple times produces wrong result (hongyu bi) Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/d10639dc Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/d10639dc Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/d10639dc Branch: refs/heads/branch-1 Commit: d10639dcc2049bb882c0d6429e0e324c59383c1c Parents: ea0bdd3 Author: tedyu Authored: Tue Feb 17 12:41:18 2015 -0800 Committer: tedyu Committed: Tue Feb 17 12:41:18 2015 -0800 ---------------------------------------------------------------------- .../hadoop/hbase/regionserver/HRegion.java | 21 ++++++---- .../hadoop/hbase/client/TestFromClientSide.java | 43 ++++++++++++++++++++ 2 files changed, 55 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/d10639dc/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java index 5c9c64a..1c80de8 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java @@ -3541,7 +3541,7 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver { // protected void checkReadsEnabled() throws IOException { if (!this.writestate.readsEnabled) { - throw new IOException ("The region's reads are disabled. Cannot serve the request"); + throw new IOException("The region's reads are disabled. Cannot serve the request"); } } @@ -6661,17 +6661,19 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver { // // Iterate the input columns and update existing values if they were // found, otherwise add new column initialized to the increment amount int idx = 0; - for (Cell cell: family.getValue()) { + List edits = family.getValue(); + for (int i = 0; i < edits.size(); i++) { + Cell cell = edits.get(i); long amount = Bytes.toLong(CellUtil.cloneValue(cell)); boolean noWriteBack = (amount == 0); List newTags = new ArrayList(); // Carry forward any tags that might have been added by a coprocessor if (cell.getTagsLength() > 0) { - Iterator i = CellUtil.tagsIterator(cell.getTagsArray(), + Iterator itr = CellUtil.tagsIterator(cell.getTagsArray(), cell.getTagsOffset(), cell.getTagsLength()); - while (i.hasNext()) { - newTags.add(i.next()); + while (itr.hasNext()) { + newTags.add(itr.next()); } } @@ -6689,13 +6691,14 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver { // } // Carry tags forward from previous version if (c.getTagsLength() > 0) { - Iterator i = CellUtil.tagsIterator(c.getTagsArray(), + Iterator itr = CellUtil.tagsIterator(c.getTagsArray(), c.getTagsOffset(), c.getTagsLength()); - while (i.hasNext()) { - newTags.add(i.next()); + while (itr.hasNext()) { + newTags.add(itr.next()); } } - idx++; + if (i < ( edits.size() - 1) && !CellUtil.matchingQualifier(cell, edits.get(i + 1))) + idx++; } // Append new incremented KeyValue to list http://git-wip-us.apache.org/repos/asf/hbase/blob/d10639dc/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java index 9bae599..b16d41a 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java @@ -4607,6 +4607,49 @@ public class TestFromClientSide { } @Test + public void testIncrementOnSameColumn() throws Exception { + LOG.info("Starting testIncrementOnSameColumn"); + final byte[] TABLENAME = Bytes.toBytes("testIncrementOnSameColumn"); + HTable ht = TEST_UTIL.createTable(TABLENAME, FAMILY); + + byte[][] QUALIFIERS = + new byte[][] { Bytes.toBytes("A"), Bytes.toBytes("B"), Bytes.toBytes("C") }; + + Increment inc = new Increment(ROW); + for (int i = 0; i < QUALIFIERS.length; i++) { + inc.addColumn(FAMILY, QUALIFIERS[i], 1); + inc.addColumn(FAMILY, QUALIFIERS[i], 1); + } + ht.increment(inc); + + // Verify expected results + Result r = ht.get(new Get(ROW)); + Cell[] kvs = r.rawCells(); + assertEquals(3, kvs.length); + assertIncrementKey(kvs[0], ROW, FAMILY, QUALIFIERS[0], 1); + assertIncrementKey(kvs[1], ROW, FAMILY, QUALIFIERS[1], 1); + assertIncrementKey(kvs[2], ROW, FAMILY, QUALIFIERS[2], 1); + + // Now try multiple columns again + inc = new Increment(ROW); + for (int i = 0; i < QUALIFIERS.length; i++) { + inc.addColumn(FAMILY, QUALIFIERS[i], 1); + inc.addColumn(FAMILY, QUALIFIERS[i], 1); + } + ht.increment(inc); + + // Verify + r = ht.get(new Get(ROW)); + kvs = r.rawCells(); + assertEquals(3, kvs.length); + assertIncrementKey(kvs[0], ROW, FAMILY, QUALIFIERS[0], 2); + assertIncrementKey(kvs[1], ROW, FAMILY, QUALIFIERS[1], 2); + assertIncrementKey(kvs[2], ROW, FAMILY, QUALIFIERS[2], 2); + + ht.close(); + } + + @Test public void testIncrement() throws Exception { LOG.info("Starting testIncrement"); final TableName TABLENAME = TableName.valueOf("testIncrement");