HBASE-6265 Calling getTimestamp() on a KV in cp.prePut() causes KV not to be flushed

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1356106 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Lars George 2012-07-02 08:26:31 +00:00
parent cbd82f0440
commit 40dc5d71f8
2 changed files with 23 additions and 6 deletions

View File

@ -1165,6 +1165,8 @@ public class KeyValue implements Writable, HeapSize {
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 Writable, HeapSize {
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) {

View File

@ -59,7 +59,7 @@ public class TestKeyValue extends TestCase {
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 TestCase {
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 TestCase {
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 TestCase {
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();