Index: src/test/java/org/apache/hadoop/hbase/io/TestHalfStoreFileReader.java =================================================================== --- src/test/java/org/apache/hadoop/hbase/io/TestHalfStoreFileReader.java (revision 1333302) +++ src/test/java/org/apache/hadoop/hbase/io/TestHalfStoreFileReader.java (revision ) @@ -20,6 +20,8 @@ package org.apache.hadoop.hbase.io; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import java.io.IOException; @@ -121,7 +123,59 @@ assertTrue( ret > 0 ); halfreader.close(true); + } + + @Test + public void testHalfScanSeekBefore() throws IOException { + HBaseTestingUtility test_util = new HBaseTestingUtility(); + String root_dir = test_util.getDataTestDir("TestHalfStoreFileSeekBefore").toString(); + Path p = new Path(root_dir, "test"); + + Configuration conf = test_util.getConfiguration(); + FileSystem fs = FileSystem.get(conf); + CacheConfig cacheConf = new CacheConfig(conf); + + HFile.Writer w = HFile.getWriterFactory(conf, cacheConf) + .withPath(fs, p) + .withBlockSize(1024) + .withComparator(KeyValue.KEY_COMPARATOR) + .create(); + + // write some things. + List items = genSomeKeys(); + for (KeyValue kv : items) { + w.append(kv); + } + w.close(); + + HFile.Reader r = HFile.createReader(fs, p, cacheConf); + r.loadFileInfo(); + byte [] midkey = r.midkey(); + KeyValue midKV = KeyValue.createKeyValueFromKey(midkey); + midkey = midKV.getRow(); + + Reference bottom = new Reference(midkey, Reference.Range.bottom); + KeyValue foundKeyValue = doTestOfSeekBefore(p, fs, bottom, items.get(1),cacheConf); + assertEquals(items.get(0), foundKeyValue); + // Ensure that a key out of range of the bottom returns null. + assertNull(doTestOfSeekBefore(p, fs, bottom, items.get(items.size() -1), cacheConf)); + + Reference top = new Reference(midkey, Reference.Range.top); + foundKeyValue = doTestOfSeekBefore(p, fs, top, items.get(items.size() - 1), cacheConf); + assertEquals(items.get(items.size() - 2), foundKeyValue); + + } + + private KeyValue doTestOfSeekBefore(Path p, FileSystem fs, Reference bottom, KeyValue seekBefore, + CacheConfig cacheConfig) + throws IOException { + final HalfStoreFileReader halfreader = new HalfStoreFileReader(fs, p, + cacheConfig, bottom, DataBlockEncoding.NONE); + halfreader.loadFileInfo(); + final HFileScanner scanner = halfreader.getScanner(false, false); + scanner.seekBefore(seekBefore.getKey()); + return scanner.getKeyValue(); - } + } private KeyValue getLastOnCol(KeyValue curr) { return KeyValue.createLastOnRow( Index: src/main/java/org/apache/hadoop/hbase/io/HalfStoreFileReader.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/io/HalfStoreFileReader.java (revision 1333302) +++ src/main/java/org/apache/hadoop/hbase/io/HalfStoreFileReader.java (revision ) @@ -150,7 +150,7 @@ } else { if (getComparator().compare(key, offset, length, splitkey, 0, splitkey.length) >= 0) { - return seekBefore(splitkey, 0, splitkey.length); + return false; } } return this.delegate.seekBefore(key, offset, length);