-
Notifications
You must be signed in to change notification settings - Fork 3.4k
HBASE-29672 Handle runtime comparison failures during filtering gracefully #7397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
droudnitsky
wants to merge
8
commits into
apache:master
Choose a base branch
from
droudnitsky:HBASE-29672
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+269
−24
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6c9d5c1
HBASE-29672 Handle runtime comparison failures during filtering grace…
e4a0acd
spotless + docstring
b2751bd
fix typos in text
adc5a67
Update hbase-client/src/test/java/org/apache/hadoop/hbase/filter/Test…
droudnitsky cb2846d
Update hbase-client/src/test/java/org/apache/hadoop/hbase/filter/Test…
droudnitsky 1b817e8
Move to junit 5 , add filterTests tag
0b39438
Merge branch 'HBASE-29672' of https://github.com/droudnitsky/hbase in…
23f2311
spotless
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
205 changes: 205 additions & 0 deletions
205
...ient/src/test/java/org/apache/hadoop/hbase/filter/TestFiltersWithComparatorException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,205 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.hadoop.hbase.filter; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
| import static org.junit.jupiter.api.Assertions.fail; | ||
|
|
||
| import java.io.IOException; | ||
| import java.nio.ByteBuffer; | ||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import org.apache.hadoop.hbase.Cell; | ||
| import org.apache.hadoop.hbase.CompareOperator; | ||
| import org.apache.hadoop.hbase.HBaseIOException; | ||
| import org.apache.hadoop.hbase.KeyValue; | ||
| import org.apache.hadoop.hbase.testclassification.FilterTests; | ||
| import org.apache.hadoop.hbase.testclassification.SmallTests; | ||
| import org.apache.hadoop.hbase.util.Bytes; | ||
| import org.junit.jupiter.api.Tag; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| @Tag(SmallTests.TAG) | ||
| @Tag(FilterTests.TAG) | ||
| public class TestFiltersWithComparatorException { | ||
|
|
||
| /** | ||
| * Tests that filters which take a ByteArrayComparable comparator handle runtime exceptions in the | ||
| * comparator layer, see HBASE-29672 | ||
| */ | ||
|
|
||
| final byte[] cf = Bytes.toBytes("cf"); | ||
| final byte[] row = Bytes.toBytes("row1"); | ||
| final byte[] cq = Bytes.toBytes("q"); | ||
| final long ts = 12345L; | ||
| final byte[] value = Bytes.toBytes("value"); | ||
| final Cell testCell = new KeyValue(row, cf, cq, ts, value); | ||
|
|
||
| @FunctionalInterface | ||
| interface FilterFunctionThrowable { | ||
| void run(Filter filter) throws IOException; | ||
| } | ||
|
|
||
| // Every filterX method that Filter implements to test | ||
| final List<FilterFunctionThrowable> filterFunctionsToTest = Arrays.asList((Filter filter) -> { | ||
| filter.filterRowKey(testCell); | ||
| }, (Filter filter) -> { | ||
| filter.filterAllRemaining(); | ||
| }, (Filter filter) -> { | ||
| filter.filterCell(testCell); | ||
| }, (Filter filter) -> { | ||
| filter.filterRowCells(new ArrayList<>(Collections.singletonList(testCell))); | ||
| }, (Filter filter) -> { | ||
| filter.filterRow(); | ||
| }); | ||
|
|
||
| /** | ||
| * Comparator which throws RuntimeException for every `compareTo` method that | ||
| * `ByteArrayComparable` implements + keeps a counter for number of compareTo invocations / | ||
| * RuntimeExceptions thrown | ||
| */ | ||
| static class BadComparator extends ByteArrayComparable { | ||
|
|
||
| public int compareToInvocations = 0; | ||
|
|
||
| public BadComparator() { | ||
| super(new byte[1]); | ||
| } | ||
|
|
||
| @Override | ||
| public byte[] toByteArray() { | ||
| return new byte[1]; | ||
| } | ||
|
|
||
| @Override | ||
| public int compareTo(byte[] value, int offset, int length) { | ||
| compareToInvocations++; | ||
| throw new RuntimeException("comparator runtime exception"); | ||
| } | ||
|
|
||
| @Override | ||
| public int compareTo(ByteBuffer value, int offset, int length) { | ||
| compareToInvocations++; | ||
| throw new RuntimeException("comparator runtime exception"); | ||
| } | ||
|
|
||
| @Override | ||
| public int compareTo(byte[] value) { | ||
| compareToInvocations++; | ||
| throw new RuntimeException("comparator runtime exception"); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * Verifies that a given {@link Filter} correctly triggers comparator logic and wraps any runtime | ||
| * exceptions happening at comparison time in {@link org.apache.hadoop.hbase.HBaseIOException} | ||
| * <p> | ||
| * This method runs a set of predefined filter functions against the provided filter instance and | ||
| * checks that if a comparator invocation occurs which throws a RuntimeException, it gets wrapped | ||
| * in a {@code HBaseIOException} by the filter implementation The test fails if: | ||
| * <ul> | ||
| * <li>The comparator is never invoked by any tested function, or</li> | ||
| * <li>A comparator invocation does not result in the expected exception.</li> | ||
| * </ul> | ||
| * @param filter the filter instance under test | ||
| * @param badComparator the comparator the filter was constructed with | ||
| **/ | ||
| private void testFilter(Filter filter, BadComparator badComparator) { | ||
| for (FilterFunctionThrowable filterFunction : filterFunctionsToTest) { | ||
| int invocationsBefore = badComparator.compareToInvocations; | ||
| boolean ioExceptionThrown = false; | ||
| try { | ||
| filterFunction.run(filter); | ||
| } catch (HBaseIOException e) { | ||
| ioExceptionThrown = true; | ||
| } catch (IOException ignored) { | ||
| } | ||
| if (invocationsBefore != badComparator.compareToInvocations) { | ||
| assertTrue(ioExceptionThrown, "IOException should have been thrown"); | ||
| } | ||
| } | ||
| if (badComparator.compareToInvocations == 0) { | ||
| fail(String.format("Filter %s never invoked the comparator for any of the functions tested - " | ||
| + "intended behavior was not tested, this is not expected", filter.getClass().getName())); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testColumnValueFilter() { | ||
| BadComparator comparator = new BadComparator(); | ||
| ColumnValueFilter columnValueFilter = | ||
| new ColumnValueFilter(cf, cq, CompareOperator.EQUAL, comparator); | ||
| testFilter(columnValueFilter, comparator); | ||
| } | ||
|
|
||
| @Test | ||
| public void testRowFilter() { | ||
| BadComparator comparator = new BadComparator(); | ||
| RowFilter rowFilter = new RowFilter(CompareOperator.EQUAL, comparator); | ||
| testFilter(rowFilter, comparator); | ||
| } | ||
|
|
||
| @Test | ||
| public void testDependentColumnFilter() { | ||
| BadComparator comparator = new BadComparator(); | ||
| DependentColumnFilter filter = | ||
| new DependentColumnFilter(cf, cq, false, CompareOperator.EQUAL, comparator); | ||
| testFilter(filter, comparator); | ||
| } | ||
|
|
||
| @Test | ||
| public void testFamilyFilter() { | ||
| BadComparator comparator = new BadComparator(); | ||
| FamilyFilter filter = new FamilyFilter(CompareOperator.EQUAL, comparator); | ||
| testFilter(filter, comparator); | ||
| } | ||
|
|
||
| @Test | ||
| public void testQualifierFilter() { | ||
| BadComparator comparator = new BadComparator(); | ||
| QualifierFilter filter = new QualifierFilter(CompareOperator.EQUAL, comparator); | ||
| testFilter(filter, comparator); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSingleColumnValueExcludeFilter() { | ||
| BadComparator comparator = new BadComparator(); | ||
| SingleColumnValueExcludeFilter filter = | ||
| new SingleColumnValueExcludeFilter(cf, cq, CompareOperator.EQUAL, comparator); | ||
| testFilter(filter, comparator); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSingleColumnValueFilter() { | ||
| BadComparator comparator = new BadComparator(); | ||
| SingleColumnValueFilter filter = | ||
| new SingleColumnValueFilter(cf, cq, CompareOperator.EQUAL, comparator); | ||
| testFilter(filter, comparator); | ||
| } | ||
|
|
||
| @Test | ||
| public void testValueFilter() { | ||
| BadComparator comparator = new BadComparator(); | ||
| ValueFilter filter = new ValueFilter(CompareOperator.EQUAL, comparator); | ||
| testFilter(filter, comparator); | ||
| } | ||
|
|
||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.