HBASE-8012 - Reseek should position to the beginning of file for the first time it is invoked with a KV smaller than the first KV in file (Raymond Liu)
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1455993 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
afcfbd1a8a
commit
64cdeb630c
|
@ -53,11 +53,6 @@ public class StoreFileScanner implements KeyValueScanner {
|
||||||
|
|
||||||
private boolean enforceMVCC = false;
|
private boolean enforceMVCC = false;
|
||||||
|
|
||||||
//The variable, realSeekDone, may cheat on store file scanner for the
|
|
||||||
// multi-column bloom-filter optimization.
|
|
||||||
// So this flag shows whether this storeFileScanner could do a reseek.
|
|
||||||
private boolean isReseekable = false;
|
|
||||||
|
|
||||||
private static final AtomicLong seekCount = new AtomicLong();
|
private static final AtomicLong seekCount = new AtomicLong();
|
||||||
|
|
||||||
private ScanQueryMatcher matcher;
|
private ScanQueryMatcher matcher;
|
||||||
|
@ -148,7 +143,6 @@ public class StoreFileScanner implements KeyValueScanner {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.isReseekable = true;
|
|
||||||
cur = hfs.getKeyValue();
|
cur = hfs.getKeyValue();
|
||||||
|
|
||||||
return skipKVsNewerThanReadpoint();
|
return skipKVsNewerThanReadpoint();
|
||||||
|
@ -242,6 +236,12 @@ public class StoreFileScanner implements KeyValueScanner {
|
||||||
//This function is similar to seekAtOrAfter function
|
//This function is similar to seekAtOrAfter function
|
||||||
int result = s.reseekTo(k.getBuffer(), k.getKeyOffset(), k.getKeyLength());
|
int result = s.reseekTo(k.getBuffer(), k.getKeyOffset(), k.getKeyLength());
|
||||||
if (result <= 0) {
|
if (result <= 0) {
|
||||||
|
// If up to now scanner is not seeked yet, this means passed KV is smaller
|
||||||
|
// than first KV in file, and it is the first time we seek on this file.
|
||||||
|
// So we also need to work from the start of file.
|
||||||
|
if (!s.isSeeked()) {
|
||||||
|
return s.seekTo();
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
// passed KV is larger than current KV in file, if there is a next
|
// passed KV is larger than current KV in file, if there is a next
|
||||||
|
@ -346,7 +346,7 @@ public class StoreFileScanner implements KeyValueScanner {
|
||||||
if (realSeekDone)
|
if (realSeekDone)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (delayedReseek && this.isReseekable) {
|
if (delayedReseek) {
|
||||||
reseek(delayedSeekKV);
|
reseek(delayedSeekKV);
|
||||||
} else {
|
} else {
|
||||||
seek(delayedSeekKV);
|
seek(delayedSeekKV);
|
||||||
|
|
|
@ -586,6 +586,33 @@ public class TestStoreFile extends HBaseTestCase {
|
||||||
+ ", expected no more than " + maxFalsePos, falsePos <= maxFalsePos);
|
+ ", expected no more than " + maxFalsePos, falsePos <= maxFalsePos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for HBASE-8012
|
||||||
|
*/
|
||||||
|
public void testReseek() throws Exception {
|
||||||
|
// write the file
|
||||||
|
Path f = new Path(ROOT_DIR, getName());
|
||||||
|
|
||||||
|
// Make a store file and write data to it.
|
||||||
|
StoreFile.Writer writer = new StoreFile.WriterBuilder(conf, cacheConf,
|
||||||
|
this.fs, 8 * 1024)
|
||||||
|
.withFilePath(f)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
writeStoreFile(writer);
|
||||||
|
writer.close();
|
||||||
|
|
||||||
|
StoreFile.Reader reader = new StoreFile.Reader(fs, f, cacheConf, DataBlockEncoding.NONE);
|
||||||
|
|
||||||
|
// Now do reseek with empty KV to position to the beginning of the file
|
||||||
|
|
||||||
|
KeyValue k = KeyValue.createFirstOnRow(HConstants.EMPTY_BYTE_ARRAY);
|
||||||
|
StoreFileScanner s = reader.getStoreFileScanner(false, false);
|
||||||
|
s.reseek(k);
|
||||||
|
|
||||||
|
assertNotNull("Intial reseek should position at the beginning of the file", s.peek());
|
||||||
|
}
|
||||||
|
|
||||||
public void testBloomTypes() throws Exception {
|
public void testBloomTypes() throws Exception {
|
||||||
float err = (float) 0.01;
|
float err = (float) 0.01;
|
||||||
FileSystem fs = FileSystem.getLocal(conf);
|
FileSystem fs = FileSystem.getLocal(conf);
|
||||||
|
|
Loading…
Reference in New Issue