hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From te...@apache.org
Subject svn commit: r1567514 - in /hbase/branches/0.98/hbase-server/src: main/java/org/apache/hadoop/hbase/regionserver/HRegion.java test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java
Date Wed, 12 Feb 2014 03:43:07 GMT
Author: tedyu
Date: Wed Feb 12 03:43:07 2014
New Revision: 1567514

URL: http://svn.apache.org/r1567514
Log:
HBASE-10487 Avoid allocating new KeyValue and according bytes-copying for appended kvs which
don't have existing values (Honghua)


Modified:
    hbase/branches/0.98/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
    hbase/branches/0.98/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java

Modified: hbase/branches/0.98/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.98/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java?rev=1567514&r1=1567513&r2=1567514&view=diff
==============================================================================
--- hbase/branches/0.98/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
(original)
+++ hbase/branches/0.98/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
Wed Feb 12 03:43:07 2014
@@ -5023,30 +5023,22 @@ public class HRegion implements HeapSize
                     newKV.getTagsOffset(), oldKv.getTagsLength());
                 System.arraycopy(kv.getBuffer(), kv.getTagsOffset(), newKV.getBuffer(),
                     newKV.getTagsOffset() + oldKv.getTagsLength(), kv.getTagsLength());
+                // copy in row, family, and qualifier
+                System.arraycopy(kv.getBuffer(), kv.getRowOffset(),
+                    newKV.getBuffer(), newKV.getRowOffset(), kv.getRowLength());
+                System.arraycopy(kv.getBuffer(), kv.getFamilyOffset(),
+                    newKV.getBuffer(), newKV.getFamilyOffset(),
+                    kv.getFamilyLength());
+                System.arraycopy(kv.getBuffer(), kv.getQualifierOffset(),
+                    newKV.getBuffer(), newKV.getQualifierOffset(),
+                    kv.getQualifierLength());
                 idx++;
               } else {
-                // allocate an empty kv once
-                newKV = new KeyValue(row.length, kv.getFamilyLength(),
-                    kv.getQualifierLength(), now, KeyValue.Type.Put,
-                    kv.getValueLength(), kv.getTagsLength());
-                // copy in the value
-                System.arraycopy(kv.getBuffer(), kv.getValueOffset(),
-                    newKV.getBuffer(), newKV.getValueOffset(),
-                    kv.getValueLength());
-                // copy in tags
-                System.arraycopy(kv.getBuffer(), kv.getTagsOffset(), newKV.getBuffer(),
-                    newKV.getTagsOffset(), kv.getTagsLength());
+                newKV = kv;
+                // Append's KeyValue.Type==Put and ts==HConstants.LATEST_TIMESTAMP,
+                // so only need to update the timestamp to 'now'
+                newKV.updateLatestStamp(Bytes.toBytes(now));
               }
-              // copy in row, family, and qualifier
-              System.arraycopy(kv.getBuffer(), kv.getRowOffset(),
-                  newKV.getBuffer(), newKV.getRowOffset(), kv.getRowLength());
-              System.arraycopy(kv.getBuffer(), kv.getFamilyOffset(),
-                  newKV.getBuffer(), newKV.getFamilyOffset(),
-                  kv.getFamilyLength());
-              System.arraycopy(kv.getBuffer(), kv.getQualifierOffset(),
-                  newKV.getBuffer(), newKV.getQualifierOffset(),
-                  kv.getQualifierLength());
-
               newKV.setMvccVersion(w.getWriteNumber());
               // Give coprocessors a chance to update the new cell
               if (coprocessorHost != null) {

Modified: hbase/branches/0.98/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.98/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java?rev=1567514&r1=1567513&r2=1567514&view=diff
==============================================================================
--- hbase/branches/0.98/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java
(original)
+++ hbase/branches/0.98/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java
Wed Feb 12 03:43:07 2014
@@ -4422,7 +4422,7 @@ public class TestFromClientSide {
     byte[] v1 = Bytes.toBytes("42");
     byte[] v2 = Bytes.toBytes("23");
     byte [][] QUALIFIERS = new byte [][] {
-        Bytes.toBytes("b"), Bytes.toBytes("a")
+        Bytes.toBytes("b"), Bytes.toBytes("a"), Bytes.toBytes("c")
     };
     Append a = new Append(ROW);
     a.add(FAMILY, QUALIFIERS[0], v1);
@@ -4433,9 +4433,14 @@ public class TestFromClientSide {
     a = new Append(ROW);
     a.add(FAMILY, QUALIFIERS[0], v2);
     a.add(FAMILY, QUALIFIERS[1], v1);
+    a.add(FAMILY, QUALIFIERS[2], v2);
     Result r = t.append(a);
     assertEquals(0, Bytes.compareTo(Bytes.add(v1,v2), r.getValue(FAMILY, QUALIFIERS[0])));
     assertEquals(0, Bytes.compareTo(Bytes.add(v2,v1), r.getValue(FAMILY, QUALIFIERS[1])));
+    // QUALIFIERS[2] previously not exist, verify both value and timestamp are correct
+    assertEquals(0, Bytes.compareTo(v2, r.getValue(FAMILY, QUALIFIERS[2])));
+    assertEquals(r.getColumnLatest(FAMILY, QUALIFIERS[0]).getTimestamp(),
+        r.getColumnLatest(FAMILY, QUALIFIERS[2]).getTimestamp());
   }
 
   @Test



Mime
View raw message