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-12948 Calling Increment#addColumn on the same column multiple times produces wrong result (hongyu bi)
Date Tue, 17 Feb 2015 21:19:29 GMT
Repository: hbase
Updated Branches:
  refs/heads/0.98 358440e54 -> e34ee5838


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/e34ee583
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/e34ee583
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/e34ee583

Branch: refs/heads/0.98
Commit: e34ee5838ecac5281bbf0c1053302b4aa1fb5e72
Parents: 358440e
Author: tedyu <yuzhihong@gmail.com>
Authored: Tue Feb 17 13:19:16 2015 -0800
Committer: tedyu <yuzhihong@gmail.com>
Committed: Tue Feb 17 13:19:16 2015 -0800

----------------------------------------------------------------------
 .../hadoop/hbase/regionserver/HRegion.java      | 19 +++++----
 .../hadoop/hbase/client/TestFromClientSide.java | 43 ++++++++++++++++++++
 2 files changed, 54 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/e34ee583/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 01875c9..cf927c3 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
@@ -5600,17 +5600,19 @@ public class HRegion implements HeapSize { // , Writable{
             // 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<Cell> 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<Tag> newTags = new ArrayList<Tag>();
 
               // Carry forward any tags that might have been added by a coprocessor
               if (cell.getTagsLengthUnsigned() > 0) {
-                Iterator<Tag> i = CellUtil.tagsIterator(cell.getTagsArray(),
+                Iterator<Tag> itr = CellUtil.tagsIterator(cell.getTagsArray(),
                   cell.getTagsOffset(), cell.getTagsLengthUnsigned());
-                while (i.hasNext()) {
-                  newTags.add(i.next());
+                while (itr.hasNext()) {
+                  newTags.add(itr.next());
                 }
               }
 
@@ -5628,13 +5630,14 @@ public class HRegion implements HeapSize { // , Writable{
                 }
                 // Carry tags forward from previous version
                 if (c.getTagsLength() > 0) {
-                  Iterator<Tag> i = CellUtil.tagsIterator(c.getTagsArray(),
+                  Iterator<Tag> 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/e34ee583/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 c25de66..7eae85a 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
@@ -4690,6 +4690,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 byte [] TABLENAME = Bytes.toBytes("testIncrement");


Mime
View raw message