hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject svn commit: r1310067 - in /hbase/branches/0.94/src: main/java/org/apache/hadoop/hbase/KeyValue.java test/java/org/apache/hadoop/hbase/TestKeyValue.java
Date Thu, 05 Apr 2012 20:48:03 GMT
Author: stack
Date: Thu Apr  5 20:48:03 2012
New Revision: 1310067

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

Modified:
    hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/KeyValue.java
    hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java

Modified: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/KeyValue.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/KeyValue.java?rev=1310067&r1=1310066&r2=1310067&view=diff
==============================================================================
--- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/KeyValue.java (original)
+++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/KeyValue.java Thu Apr  5 20:48:03
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.
  *
@@ -2231,6 +2232,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.94/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java?rev=1310067&r1=1310066&r2=1310067&view=diff
==============================================================================
--- hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java (original)
+++ hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java Thu Apr  5
20:48:03 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;
@@ -31,6 +33,7 @@ import org.apache.hadoop.hbase.KeyValue.
 import org.apache.hadoop.hbase.KeyValue.MetaComparator;
 import org.apache.hadoop.hbase.KeyValue.Type;
 import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.io.WritableUtils;
 import org.junit.experimental.categories.Category;
 
 @Category(SmallTests.class)
@@ -407,6 +410,25 @@ public class TestKeyValue extends TestCa
         kv.toString().replaceAll("=[0-9]+", "=0"));
   }
 
+  /**
+   * 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()));
+  }
+
   @org.junit.Rule
   public org.apache.hadoop.hbase.ResourceCheckerJUnitRule cu =
     new org.apache.hadoop.hbase.ResourceCheckerJUnitRule();



Mime
View raw message