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:52:01 UTC

svn commit: r1310068 - in /hbase/branches/0.92: 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:52:01 2012
New Revision: 1310068

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

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

Modified: hbase/branches/0.92/CHANGES.txt
URL: http://svn.apache.org/viewvc/hbase/branches/0.92/CHANGES.txt?rev=1310068&r1=1310067&r2=1310068&view=diff
==============================================================================
--- hbase/branches/0.92/CHANGES.txt (original)
+++ hbase/branches/0.92/CHANGES.txt Thu Apr  5 20:52:01 2012
@@ -28,6 +28,8 @@ Release 0.92.2 - Unreleased
                (Prakash)
    HBASE-5711  Tests are failing with incorrect data directory permissions
                (Uma Maheswara Rao G)
+   HBASE-5724  Row cache of KeyValue should be cleared in readFields().
+               (Teruyoshi Zenmyo)
 
   IMPROVEMENTS
    HBASE-5592  Make it easier to get a table from shell (Ben West)

Modified: hbase/branches/0.92/src/main/java/org/apache/hadoop/hbase/KeyValue.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.92/src/main/java/org/apache/hadoop/hbase/KeyValue.java?rev=1310068&r1=1310067&r2=1310068&view=diff
==============================================================================
--- hbase/branches/0.92/src/main/java/org/apache/hadoop/hbase/KeyValue.java (original)
+++ hbase/branches/0.92/src/main/java/org/apache/hadoop/hbase/KeyValue.java Thu Apr  5 20:52:01 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.  This is the fundamental HBase Type.
  *
@@ -2005,6 +2006,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.92/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.92/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java?rev=1310068&r1=1310067&r2=1310068&view=diff
==============================================================================
--- hbase/branches/0.92/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java (original)
+++ hbase/branches/0.92/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java Thu Apr  5 20:52:01 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;
@@ -385,4 +387,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()));
+  }
 }