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-09-07 08:15:29 -07:00
parent 7592cb8d34
commit 743f3ae221
2 changed files with 28 additions and 9 deletions

View File

@ -22,7 +22,9 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellComparator; import org.apache.hadoop.hbase.CellComparator;
@ -65,7 +67,7 @@ final public class FilterList extends FilterBase {
private static final int MAX_LOG_FILTERS = 5; private static final int MAX_LOG_FILTERS = 5;
private Operator operator = Operator.MUST_PASS_ALL; private Operator operator = Operator.MUST_PASS_ALL;
private final List<Filter> filters; private final List<Filter> filters;
private Filter seekHintFilter = null; private Set<Filter> seekHintFilter = new HashSet<>();
/** /**
* Save previous return code and previous cell for every filter in filter list. For MUST_PASS_ONE, * Save previous return code and previous cell for every filter in filter list. For MUST_PASS_ONE,
@ -234,7 +236,7 @@ final public class FilterList extends FilterBase {
prevCellList.set(i, null); prevCellList.set(i, null);
} }
} }
seekHintFilter = null; seekHintFilter.clear();
} }
@Override @Override
@ -358,6 +360,7 @@ final public class FilterList extends FilterBase {
return ReturnCode.INCLUDE; return ReturnCode.INCLUDE;
} }
this.referenceCell = c; this.referenceCell = c;
seekHintFilter.clear();
// Accumulates successive transformation of every filter that includes the Cell: // Accumulates successive transformation of every filter that includes the Cell:
Cell transformed = c; Cell transformed = c;
@ -389,10 +392,12 @@ final public class FilterList extends FilterBase {
transformed = filter.transformCell(transformed); transformed = filter.transformCell(transformed);
continue; continue;
case SEEK_NEXT_USING_HINT: case SEEK_NEXT_USING_HINT:
seekHintFilter = filter; seekHintFilter.add(filter);
return code; continue;
default: default:
return code; if (seekHintFilter.isEmpty()) {
return code;
}
} }
} else if (operator == Operator.MUST_PASS_ONE) { } else if (operator == Operator.MUST_PASS_ONE) {
Cell prevCell = this.prevCellList.get(i); Cell prevCell = this.prevCellList.get(i);
@ -442,6 +447,10 @@ final public class FilterList extends FilterBase {
} }
} }
if (!seekHintFilter.isEmpty()) {
return ReturnCode.SEEK_NEXT_USING_HINT;
}
// Save the transformed Cell for transform(): // Save the transformed Cell for transform():
this.transformedCell = transformed; this.transformedCell = transformed;
@ -565,7 +574,17 @@ final public class FilterList extends FilterBase {
} }
Cell keyHint = null; Cell keyHint = null;
if (operator == Operator.MUST_PASS_ALL) { if (operator == Operator.MUST_PASS_ALL) {
if (seekHintFilter != null) keyHint = seekHintFilter.getNextCellHint(currentCell); for (Filter filter : seekHintFilter) {
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; return keyHint;
} }

View File

@ -501,7 +501,7 @@ public class TestFilterList {
FilterList filterList = new FilterList(Operator.MUST_PASS_ONE, FilterList filterList = new FilterList(Operator.MUST_PASS_ONE,
Arrays.asList(new Filter [] { filterMinHint, filterMaxHint } )); Arrays.asList(new Filter [] { filterMinHint, filterMaxHint } ));
assertEquals(0, CellComparator.COMPARATOR.compare(filterList.getNextCellHint(null), assertEquals(0, CellComparator.COMPARATOR.compare(filterList.getNextCellHint(null),
minKeyValue)); minKeyValue));
// Should have no hint if any filter has no hint // Should have no hint if any filter has no hint
filterList = new FilterList(Operator.MUST_PASS_ONE, filterList = new FilterList(Operator.MUST_PASS_ONE,
@ -525,7 +525,7 @@ public class TestFilterList {
Arrays.asList(new Filter [] { filterMinHint, filterMaxHint } )); Arrays.asList(new Filter [] { filterMinHint, filterMaxHint } ));
filterList.filterKeyValue(null); filterList.filterKeyValue(null);
assertEquals(0, CellComparator.COMPARATOR.compare(filterList.getNextCellHint(null), assertEquals(0, CellComparator.COMPARATOR.compare(filterList.getNextCellHint(null),
minKeyValue)); maxKeyValue));
filterList = new FilterList(Operator.MUST_PASS_ALL, filterList = new FilterList(Operator.MUST_PASS_ALL,
Arrays.asList(new Filter [] { filterMaxHint, filterMinHint } )); Arrays.asList(new Filter [] { filterMaxHint, filterMinHint } ));
@ -539,7 +539,7 @@ public class TestFilterList {
new Filter [] { filterNoHint, filterMinHint, filterMaxHint } )); new Filter [] { filterNoHint, filterMinHint, filterMaxHint } ));
filterList.filterKeyValue(null); filterList.filterKeyValue(null);
assertEquals(0, CellComparator.COMPARATOR.compare(filterList.getNextCellHint(null), assertEquals(0, CellComparator.COMPARATOR.compare(filterList.getNextCellHint(null),
minKeyValue)); maxKeyValue));
filterList = new FilterList(Operator.MUST_PASS_ALL, filterList = new FilterList(Operator.MUST_PASS_ALL,
Arrays.asList(new Filter [] { filterNoHint, filterMaxHint } )); Arrays.asList(new Filter [] { filterNoHint, filterMaxHint } ));
filterList.filterKeyValue(null); filterList.filterKeyValue(null);