HBASE-16404 Make DeleteBloomFilters work with BloomContext (Ram)

This commit is contained in:
Ramkrishna 2016-08-12 15:09:31 +05:30
parent 285e104176
commit 65c03b058c
3 changed files with 23 additions and 35 deletions

View File

@ -58,9 +58,9 @@ public class StoreFileWriter implements Compactor.CellSink {
private final BloomFilterWriter deleteFamilyBloomFilterWriter; private final BloomFilterWriter deleteFamilyBloomFilterWriter;
private final BloomType bloomType; private final BloomType bloomType;
private long earliestPutTs = HConstants.LATEST_TIMESTAMP; private long earliestPutTs = HConstants.LATEST_TIMESTAMP;
private Cell lastDeleteFamilyCell = null;
private long deleteFamilyCnt = 0; private long deleteFamilyCnt = 0;
private BloomContext bloomContext = null; private BloomContext bloomContext = null;
private BloomContext deleteFamilyBloomContext = null;
/** /**
* timeRangeTrackerSet is used to figure if we were passed a filled-out TimeRangeTracker or not. * timeRangeTrackerSet is used to figure if we were passed a filled-out TimeRangeTracker or not.
@ -137,6 +137,18 @@ public class StoreFileWriter implements Compactor.CellSink {
LOG.trace("Bloom filter type for " + path + ": " + this.bloomType + ", " + LOG.trace("Bloom filter type for " + path + ": " + this.bloomType + ", " +
generalBloomFilterWriter.getClass().getSimpleName()); generalBloomFilterWriter.getClass().getSimpleName());
} }
// init bloom context
switch (bloomType) {
case ROW:
bloomContext = new RowBloomContext(generalBloomFilterWriter);
break;
case ROWCOL:
bloomContext = new RowColBloomContext(generalBloomFilterWriter);
break;
default:
throw new IOException(
"Invalid Bloom filter type: " + bloomType + " (ROW or ROWCOL expected)");
}
} else { } else {
// Not using Bloom filters. // Not using Bloom filters.
this.bloomType = BloomType.NONE; this.bloomType = BloomType.NONE;
@ -148,6 +160,7 @@ public class StoreFileWriter implements Compactor.CellSink {
this.deleteFamilyBloomFilterWriter = BloomFilterFactory this.deleteFamilyBloomFilterWriter = BloomFilterFactory
.createDeleteBloomAtWrite(conf, cacheConf, .createDeleteBloomAtWrite(conf, cacheConf,
(int) Math.min(maxKeys, Integer.MAX_VALUE), writer); (int) Math.min(maxKeys, Integer.MAX_VALUE), writer);
deleteFamilyBloomContext = new RowBloomContext(deleteFamilyBloomFilterWriter);
} else { } else {
deleteFamilyBloomFilterWriter = null; deleteFamilyBloomFilterWriter = null;
} }
@ -213,22 +226,6 @@ public class StoreFileWriter implements Compactor.CellSink {
private void appendGeneralBloomfilter(final Cell cell) throws IOException { private void appendGeneralBloomfilter(final Cell cell) throws IOException {
if (this.generalBloomFilterWriter != null) { if (this.generalBloomFilterWriter != null) {
// only add to the bloom filter on a new, unique key
if (this.bloomContext == null) {
// init bloom context
switch (bloomType) {
case ROW:
bloomContext = new RowBloomContext(generalBloomFilterWriter);
break;
case ROWCOL:
bloomContext = new RowColBloomContext(generalBloomFilterWriter);
break;
default:
throw new IOException(
"Invalid Bloom filter type: " + bloomType + " (ROW or ROWCOL expected)");
}
}
/* /*
* http://2.bp.blogspot.com/_Cib_A77V54U/StZMrzaKufI/AAAAAAAAADo/ZhK7bGoJdMQ/s400/KeyValue.png * http://2.bp.blogspot.com/_Cib_A77V54U/StZMrzaKufI/AAAAAAAAADo/ZhK7bGoJdMQ/s400/KeyValue.png
* Key = RowLen + Row + FamilyLen + Column [Family + Qualifier] + TimeStamp * Key = RowLen + Row + FamilyLen + Column [Family + Qualifier] + TimeStamp
@ -249,18 +246,8 @@ public class StoreFileWriter implements Compactor.CellSink {
// increase the number of delete family in the store file // increase the number of delete family in the store file
deleteFamilyCnt++; deleteFamilyCnt++;
if (null != this.deleteFamilyBloomFilterWriter) { if (this.deleteFamilyBloomFilterWriter != null) {
boolean newKey = true; deleteFamilyBloomContext.writeBloom(cell);
if (lastDeleteFamilyCell != null) {
// hbase:meta does not have blooms. So we need not have special interpretation
// of the hbase:meta cells
newKey = !CellUtil.matchingRows(cell, lastDeleteFamilyCell);
}
// TODO : Use bloom context for delete family bloom filter also
if (newKey) {
this.deleteFamilyBloomFilterWriter.add(cell);
this.lastDeleteFamilyCell = cell;
}
} }
} }

View File

@ -33,10 +33,10 @@ public abstract class BloomContext {
// TODO : Avoid holding references to lastCell // TODO : Avoid holding references to lastCell
protected Cell lastCell; protected Cell lastCell;
protected BloomFilterWriter generalBloomFilterWriter; protected BloomFilterWriter bloomFilterWriter;
public BloomContext(BloomFilterWriter generalBloomFilterWriter) { public BloomContext(BloomFilterWriter bloomFilterWriter) {
this.generalBloomFilterWriter = generalBloomFilterWriter; this.bloomFilterWriter = bloomFilterWriter;
} }
public Cell getLastCell() { public Cell getLastCell() {
@ -49,8 +49,9 @@ public abstract class BloomContext {
* @throws IOException * @throws IOException
*/ */
public void writeBloom(Cell cell) throws IOException { public void writeBloom(Cell cell) throws IOException {
// only add to the bloom filter on a new, unique key
if (isNewKey(cell)) { if (isNewKey(cell)) {
generalBloomFilterWriter.add(cell); bloomFilterWriter.add(cell);
this.lastCell = cell; this.lastCell = cell;
} }
} }

View File

@ -31,8 +31,8 @@ import org.apache.hadoop.hbase.regionserver.StoreFile;
@InterfaceAudience.Private @InterfaceAudience.Private
public class RowBloomContext extends BloomContext { public class RowBloomContext extends BloomContext {
public RowBloomContext(BloomFilterWriter generalBloomFilterWriter) { public RowBloomContext(BloomFilterWriter bloomFilterWriter) {
super(generalBloomFilterWriter); super(bloomFilterWriter);
} }
public void addLastBloomKey(Writer writer) throws IOException { public void addLastBloomKey(Writer writer) throws IOException {