HBASE-10366: 0.94 filterRow() may be skipped in 0.96(or onwards) code

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1559547 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
jeffreyz 2014-01-19 18:52:43 +00:00
parent fa298a9573
commit 8eeb7f3d9a
2 changed files with 59 additions and 2 deletions

View File

@ -3880,10 +3880,12 @@ public class HRegion implements HeapSize { // , Writable{
if (filter != null && filter.hasFilterRow()) {
filter.filterRowCells(results);
}
if (isEmptyRow) {
if (isEmptyRow || filterRow()) {
results.clear();
boolean moreRows = nextRow(currentRow, offset, length);
if (!moreRows) return false;
results.clear();
// This row was totally filtered out, if this is NOT the last row,
// we should continue on. Otherwise, nothing else to do.
if (!stopRow) continue;
@ -3933,6 +3935,20 @@ public class HRegion implements HeapSize { // , Writable{
}
}
/**
* This function is to maintain backward compatibility for 0.94 filters. HBASE-6429 combines
* both filterRow & filterRow(List<KeyValue> kvs) functions. While 0.94 code or older, it may
* not implement hasFilterRow as HBase-6429 expects because 0.94 hasFilterRow() only returns
* true when filterRow(List<KeyValue> kvs) is overridden not the filterRow(). Therefore, the
* filterRow() will be skipped.
*/
private boolean filterRow() throws IOException {
// when hasFilterRow returns true, filter.filterRow() will be called automatically inside
// filterRowCells(List<Cell> kvs) so we skip that scenario here.
return filter != null && (!filter.hasFilterRow())
&& filter.filterRow();
}
private boolean filterRowKey(byte[] row, int offset, short length) throws IOException {
return filter != null
&& filter.filterRowKey(row, offset, length);

View File

@ -579,6 +579,47 @@ public class TestFilter {
assertEquals("The page filter returned more rows than expected", pageSize, scannerCounter);
}
/**
* The following filter simulates a pre-0.96 filter where filterRow() is defined while
* hasFilterRow() returns false
*/
static class OldTestFilter extends FilterBase {
@Override
public byte [] toByteArray() {return null;}
@Override
public boolean hasFilterRow() {
return false;
}
@Override
public boolean filterRow() {
// always filter out rows
return true;
}
}
/**
* The following test is to ensure old(such as hbase0.94) filterRow() can be correctly fired in
* 0.96+ code base.
*
* See HBASE-10366
*
* @throws Exception
*/
@Test
public void tes94FilterRowCompatibility() throws Exception {
Scan s = new Scan();
OldTestFilter filter = new OldTestFilter();
s.setFilter(filter);
InternalScanner scanner = this.region.getScanner(s);
ArrayList<Cell> values = new ArrayList<Cell>();
scanner.next(values);
assertTrue("All rows should be filtered out", values.isEmpty());
}
/**
* Tests the the {@link WhileMatchFilter} works in combination with a
* {@link Filter} that uses the