You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by st...@apache.org on 2012/04/05 22:53:24 UTC

svn commit: r1310069 - in /hbase/branches/0.90: CHANGES.txt src/main/java/org/apache/hadoop/hbase/KeyValue.java src/test/java/org/apache/hadoop/hbase/TestKeyValue.java

Author: stack
Date: Thu Apr  5 20:53:23 2012
New Revision: 1310069

URL: http://svn.apache.org/viewvc?rev=1310069&view=rev
Log:
HBASE-5724 Row cache of KeyValue should be cleared in readFields()

Modified:
    hbase/branches/0.90/CHANGES.txt
    hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/KeyValue.java
    hbase/branches/0.90/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java

Modified: hbase/branches/0.90/CHANGES.txt
URL: http://svn.apache.org/viewvc/hbase/branches/0.90/CHANGES.txt?rev=1310069&r1=1310068&r2=1310069&view=diff
==============================================================================
--- hbase/branches/0.90/CHANGES.txt (original)
+++ hbase/branches/0.90/CHANGES.txt Thu Apr  5 20:53:23 2012
@@ -13,6 +13,8 @@ Release 0.90.7 - Unreleased
    HBASE-5637  Fix failing 0.90 TestHMsg testcase introduced by HBASE-5563
    HBASE-5638  Backport HBASE-5633: NPE reading ZK config in HBase (Matteo Bertozzi)
    HBASE-5213  "hbase master stop" does not bring down backup masters (Gregory) 
+   HBASE-5724  Row cache of KeyValue should be cleared in readFields().
+               (Teruyoshi Zenmyo)
 
   IMPROVEMENT
    HBASE-5588  Deprecate/remove AssignmentManager#clearRegionFromTransition

Modified: hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/KeyValue.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/KeyValue.java?rev=1310069&r1=1310068&r2=1310069&view=diff
==============================================================================
--- hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/KeyValue.java (original)
+++ hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/KeyValue.java Thu Apr  5 20:53:23 2012
@@ -27,7 +27,6 @@ import java.util.Comparator;
 import java.util.HashMap;
 import java.util.Map;
 
-import com.google.common.primitives.Longs;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.hbase.io.HeapSize;
@@ -37,6 +36,8 @@ import org.apache.hadoop.hbase.util.Clas
 import org.apache.hadoop.io.RawComparator;
 import org.apache.hadoop.io.Writable;
 
+import com.google.common.primitives.Longs;
+
 /**
  * An HBase Key/Value.
  *
@@ -1992,6 +1993,7 @@ public class KeyValue implements Writabl
   // and it expects the length of the KeyValue to be explicitly passed
   // to it.
   public void readFields(int length, final DataInput in) throws IOException {
+    this.rowCache = null;
     this.length = length;
     this.offset = 0;
     this.bytes = new byte[this.length];

Modified: hbase/branches/0.90/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java?rev=1310069&r1=1310068&r2=1310069&view=diff
==============================================================================
--- hbase/branches/0.90/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java (original)
+++ hbase/branches/0.90/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java Thu Apr  5 20:53:23 2012
@@ -19,6 +19,8 @@
  */
 package org.apache.hadoop.hbase;
 
+import java.io.ByteArrayInputStream;
+import java.io.DataInputStream;
 import java.io.IOException;
 import java.util.Set;
 import java.util.TreeSet;
@@ -387,4 +389,23 @@ public class TestKeyValue extends TestCa
       }
     }
   }
+
+  /**
+   * The row cache is cleared and re-read for the new value
+   *
+   * @throws IOException
+   */
+  public void testReadFields() throws IOException {
+    KeyValue kv1 = new KeyValue(Bytes.toBytes("row1"), Bytes.toBytes("cf1"),
+        Bytes.toBytes("qualifier1"), 12345L, Bytes.toBytes("value1"));
+    kv1.getRow(); // set row cache of kv1
+    KeyValue kv2 = new KeyValue(Bytes.toBytes("row2"), Bytes.toBytes("cf2"),
+        Bytes.toBytes("qualifier2"), 12345L, Bytes.toBytes("value2"));
+    kv1.readFields(new DataInputStream(new ByteArrayInputStream(WritableUtils
+        .toByteArray(kv2))));
+    // check equality
+    assertEquals(kv1, kv2);
+    // check cache state (getRow() return the cached value if the cache is set)
+    assertTrue(Bytes.equals(kv1.getRow(), kv2.getRow()));
+  }
 }