HBASE-11234 FastDiffDeltaEncoder#getFirstKeyInBlock returns wrong result

This commit is contained in:
zjusch 2014-05-23 12:57:10 +08:00
parent 41691e469a
commit edae564856
3 changed files with 28 additions and 21 deletions

View File

@ -360,7 +360,8 @@ public class FastDiffDeltaEncoder extends BufferedDataBlockEncoder {
ByteBufferUtils.readCompressedInt(block); // commonLength ByteBufferUtils.readCompressedInt(block); // commonLength
int pos = block.position(); int pos = block.position();
block.reset(); block.reset();
return ByteBuffer.wrap(block.array(), pos, keyLength).slice(); return ByteBuffer.wrap(block.array(), block.arrayOffset() + pos, keyLength)
.slice();
} }
@Override @Override

View File

@ -137,7 +137,8 @@ public class PrefixKeyDeltaEncoder extends BufferedDataBlockEncoder {
} }
int pos = block.position(); int pos = block.position();
block.reset(); block.reset();
return ByteBuffer.wrap(block.array(), pos, keyLength).slice(); return ByteBuffer.wrap(block.array(), block.arrayOffset() + pos, keyLength)
.slice();
} }
@Override @Override

View File

@ -51,6 +51,7 @@ import org.apache.hadoop.hbase.filter.FilterList;
import org.apache.hadoop.hbase.filter.FilterList.Operator; import org.apache.hadoop.hbase.filter.FilterList.Operator;
import org.apache.hadoop.hbase.filter.PageFilter; import org.apache.hadoop.hbase.filter.PageFilter;
import org.apache.hadoop.hbase.filter.SingleColumnValueFilter; import org.apache.hadoop.hbase.filter.SingleColumnValueFilter;
import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding;
import org.apache.hadoop.hbase.io.hfile.CacheConfig; import org.apache.hadoop.hbase.io.hfile.CacheConfig;
import org.apache.hadoop.hbase.io.hfile.HFileContext; import org.apache.hadoop.hbase.io.hfile.HFileContext;
import org.apache.hadoop.hbase.io.hfile.HFileContextBuilder; import org.apache.hadoop.hbase.io.hfile.HFileContextBuilder;
@ -88,28 +89,32 @@ public class TestReversibleScanners {
TEST_UTIL.getDataTestDir("testReversibleStoreFileScanner"), TEST_UTIL.getDataTestDir("testReversibleStoreFileScanner"),
"regionname"), "familyname"); "regionname"), "familyname");
CacheConfig cacheConf = new CacheConfig(TEST_UTIL.getConfiguration()); CacheConfig cacheConf = new CacheConfig(TEST_UTIL.getConfiguration());
HFileContextBuilder hcBuilder = new HFileContextBuilder(); for (DataBlockEncoding encoding : DataBlockEncoding.values()) {
hcBuilder.withBlockSize(2 * 1024); HFileContextBuilder hcBuilder = new HFileContextBuilder();
HFileContext hFileContext = hcBuilder.build(); hcBuilder.withBlockSize(2 * 1024);
StoreFile.Writer writer = new StoreFile.WriterBuilder( hcBuilder.withDataBlockEncoding(encoding);
TEST_UTIL.getConfiguration(), cacheConf, fs).withOutputDir( HFileContext hFileContext = hcBuilder.build();
hfilePath).withFileContext(hFileContext).build(); StoreFile.Writer writer = new StoreFile.WriterBuilder(
writeStoreFile(writer); TEST_UTIL.getConfiguration(), cacheConf, fs).withOutputDir(hfilePath)
.withFileContext(hFileContext).build();
writeStoreFile(writer);
StoreFile sf = new StoreFile(fs, writer.getPath(), StoreFile sf = new StoreFile(fs, writer.getPath(),
TEST_UTIL.getConfiguration(), cacheConf, BloomType.NONE); TEST_UTIL.getConfiguration(), cacheConf, BloomType.NONE);
List<StoreFileScanner> scanners = StoreFileScanner List<StoreFileScanner> scanners = StoreFileScanner
.getScannersForStoreFiles(Collections.singletonList(sf), false, true, .getScannersForStoreFiles(Collections.singletonList(sf), false, true,
false, Long.MAX_VALUE); false, Long.MAX_VALUE);
StoreFileScanner scanner = scanners.get(0); StoreFileScanner scanner = scanners.get(0);
seekTestOfReversibleKeyValueScanner(scanner); seekTestOfReversibleKeyValueScanner(scanner);
for (int readPoint = 0; readPoint < MAXMVCC; readPoint++) { for (int readPoint = 0; readPoint < MAXMVCC; readPoint++) {
LOG.info("Setting read point to " + readPoint); LOG.info("Setting read point to " + readPoint);
scanners = StoreFileScanner.getScannersForStoreFiles( scanners = StoreFileScanner.getScannersForStoreFiles(
Collections.singletonList(sf), false, true, false, readPoint); Collections.singletonList(sf), false, true, false, readPoint);
seekTestOfReversibleKeyValueScannerWithMVCC(scanners.get(0), readPoint); seekTestOfReversibleKeyValueScannerWithMVCC(scanners.get(0), readPoint);
}
} }
} }
@Test @Test