HBASE-15410 Utilize the max seek value when all Filters in MUST_PASS_ALL FilterList return SEEK_NEXT_USING_HINT

This commit is contained in:
tedyu 2017-10-13 15:15:12 -07:00
parent a4bc3c6db7
commit 77bfe05503
2 changed files with 27 additions and 9 deletions

View File

@ -21,6 +21,7 @@ package org.apache.hadoop.hbase.filter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@ -64,7 +65,7 @@ final public class FilterList extends FilterBase {
private static final int MAX_LOG_FILTERS = 5;
private Operator operator = Operator.MUST_PASS_ALL;
private final List<Filter> filters;
private Filter seekHintFilter = null;
private Collection<Filter> seekHintFilters = new ArrayList<Filter>();
/** Reference Cell used by {@link #transformCell(Cell)} for validation purpose. */
private Cell referenceCell = null;
@ -201,7 +202,7 @@ final public class FilterList extends FilterBase {
for (int i = 0; i < listize; i++) {
filters.get(i).reset();
}
seekHintFilter = null;
seekHintFilters.clear();
}
@Override
@ -290,6 +291,7 @@ final public class FilterList extends FilterBase {
return ReturnCode.INCLUDE;
}
this.referenceCell = c;
seekHintFilters.clear();
// Accumulates successive transformation of every filter that includes the Cell:
Cell transformed = c;
@ -321,11 +323,13 @@ final public class FilterList extends FilterBase {
transformed = filter.transformCell(transformed);
continue;
case SEEK_NEXT_USING_HINT:
seekHintFilter = filter;
return code;
seekHintFilters.add(filter);
continue;
default:
if (seekHintFilters.isEmpty()) {
return code;
}
}
} else if (operator == Operator.MUST_PASS_ONE) {
if (filter.filterAllRemaining()) {
seenNonHintReturnCode = true;
@ -362,6 +366,10 @@ final public class FilterList extends FilterBase {
}
}
if (!seekHintFilters.isEmpty()) {
return ReturnCode.SEEK_NEXT_USING_HINT;
}
// Save the transformed Cell for transform():
this.transformedCell = transformed;
@ -485,7 +493,17 @@ final public class FilterList extends FilterBase {
}
Cell keyHint = null;
if (operator == Operator.MUST_PASS_ALL) {
keyHint = seekHintFilter.getNextCellHint(currentCell);
for (Filter filter : seekHintFilters) {
if (filter.filterAllRemaining()) continue;
Cell curKeyHint = filter.getNextCellHint(currentCell);
if (keyHint == null) {
keyHint = curKeyHint;
continue;
}
if (CellComparator.COMPARATOR.compare(keyHint, curKeyHint) < 0) {
keyHint = curKeyHint;
}
}
return keyHint;
}

View File

@ -525,7 +525,7 @@ public class TestFilterList {
Arrays.asList(new Filter [] { filterMinHint, filterMaxHint } ));
filterList.filterKeyValue(null);
assertEquals(0, CellComparator.COMPARATOR.compare(filterList.getNextCellHint(null),
minKeyValue));
maxKeyValue));
filterList = new FilterList(Operator.MUST_PASS_ALL,
Arrays.asList(new Filter [] { filterMaxHint, filterMinHint } ));
@ -539,7 +539,7 @@ public class TestFilterList {
new Filter [] { filterNoHint, filterMinHint, filterMaxHint } ));
filterList.filterKeyValue(null);
assertEquals(0, CellComparator.COMPARATOR.compare(filterList.getNextCellHint(null),
minKeyValue));
maxKeyValue));
filterList = new FilterList(Operator.MUST_PASS_ALL,
Arrays.asList(new Filter [] { filterNoHint, filterMaxHint } ));
filterList.filterKeyValue(null);