hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From larsgeo...@apache.org
Subject svn commit: r1356106 - in /hbase/trunk: hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java hbase-server/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java
Date Mon, 02 Jul 2012 08:26:32 GMT
Author: larsgeorge
Date: Mon Jul  2 08:26:31 2012
New Revision: 1356106

URL: http://svn.apache.org/viewvc?rev=1356106&view=rev
Log:
HBASE-6265 Calling getTimestamp() on a KV in cp.prePut() causes KV not to be flushed

Modified:
    hbase/trunk/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java

Modified: hbase/trunk/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java?rev=1356106&r1=1356105&r2=1356106&view=diff
==============================================================================
--- hbase/trunk/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java (original)
+++ hbase/trunk/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java Mon Jul 
2 08:26:31 2012
@@ -1165,6 +1165,8 @@ public class KeyValue implements Writabl
     if (this.isLatestTimestamp()) {
       int tsOffset = getTimestampOffset();
       System.arraycopy(now, 0, this.bytes, tsOffset, Bytes.SIZEOF_LONG);
+      // clear cache or else getTimestamp() possibly returns an old value
+      timestampCache = -1L;
       return true;
     }
     return false;
@@ -2460,7 +2462,7 @@ public class KeyValue implements Writabl
       int lfamilylength = left[lfamilyoffset - 1];
       int rfamilylength = right[rfamilyoffset - 1];
       // If left family size is not equal to right family size, we need not
-      // compare the qualifiers. 
+      // compare the qualifiers.
       boolean sameFamilySize = (lfamilylength == rfamilylength);
       int common = 0;
       if (commonPrefix > 0) {

Modified: hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java?rev=1356106&r1=1356105&r2=1356106&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java (original)
+++ hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java Mon Jul
 2 08:26:31 2012
@@ -59,7 +59,7 @@ public class TestKeyValue extends TestCa
     assertFalse(aaa.matchingColumn(family2,qualifier2));
   }
 
-  /** 
+  /**
    * Test a corner case when the family qualifier is a prefix of the
    *  column qualifier.
    */
@@ -173,13 +173,13 @@ public class TestKeyValue extends TestCa
   public void testBadMetaCompareSingleDelim() {
     MetaComparator c = new KeyValue.MetaComparator();
     long now = System.currentTimeMillis();
-    // meta keys values are not quite right.  A users can enter illegal values 
+    // meta keys values are not quite right.  A users can enter illegal values
     // from shell when scanning meta.
     KeyValue a = new KeyValue(Bytes.toBytes("table,a1"), now);
     KeyValue b = new KeyValue(Bytes.toBytes("table,a2"), now);
     try {
       c.compare(a, b);
-    } catch (IllegalArgumentException iae) { 
+    } catch (IllegalArgumentException iae) {
       assertEquals(".META. key must have two ',' delimiters and have the following" +
       		" format: '<table>,<key>,<etc>'", iae.getMessage());
       return;
@@ -190,13 +190,13 @@ public class TestKeyValue extends TestCa
   public void testMetaComparatorTableKeysWithCommaOk() {
     MetaComparator c = new KeyValue.MetaComparator();
     long now = System.currentTimeMillis();
-    // meta keys values are not quite right.  A users can enter illegal values 
+    // meta keys values are not quite right.  A users can enter illegal values
     // from shell when scanning meta.
     KeyValue a = new KeyValue(Bytes.toBytes("table,key,with,commas1,1234"), now);
     KeyValue b = new KeyValue(Bytes.toBytes("table,key,with,commas2,0123"), now);
     assertTrue(c.compare(a, b) < 0);
   }
-  
+
   /**
    * Tests cases where rows keys have characters below the ','.
    * See HBASE-832
@@ -504,6 +504,21 @@ public class TestKeyValue extends TestCa
     assertTrue(Bytes.equals(kv1.getRow(), kv2.getRow()));
   }
 
+  /**
+   * Tests that getTimestamp() does always return the proper timestamp, even after updating
it.
+   * See HBASE-6265.
+   */
+  public void testGetTimestamp() {
+    KeyValue kv = new KeyValue(Bytes.toBytes("myRow"), Bytes.toBytes("myCF"),
+      Bytes.toBytes("myQualifier"), HConstants.LATEST_TIMESTAMP,
+      Bytes.toBytes("myValue"));
+    long time1 = kv.getTimestamp();
+    kv.updateLatestStamp(Bytes.toBytes(12345L));
+    long time2 = kv.getTimestamp();
+    assertEquals(HConstants.LATEST_TIMESTAMP, time1);
+    assertEquals(12345L, time2);
+  }
+
   @org.junit.Rule
   public org.apache.hadoop.hbase.ResourceCheckerJUnitRule cu =
     new org.apache.hadoop.hbase.ResourceCheckerJUnitRule();



Mime
View raw message