Index: src/test/java/org/apache/hadoop/hbase/TestKeyValue.java =================================================================== --- src/test/java/org/apache/hadoop/hbase/TestKeyValue.java (revision 1355999) +++ src/test/java/org/apache/hadoop/hbase/TestKeyValue.java (working copy) @@ -435,4 +435,19 @@ // check cache state (getRow() return the cached value if the cache is set) 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); + } } Index: src/main/java/org/apache/hadoop/hbase/KeyValue.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/KeyValue.java (revision 1355999) +++ src/main/java/org/apache/hadoop/hbase/KeyValue.java (working copy) @@ -869,6 +869,8 @@ 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;