-
Notifications
You must be signed in to change notification settings - Fork 3.4k
HBASE-28621 PrefixFilter should use SEEK_NEXT_USING_HINT #6361
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
Merged
stoty
merged 15 commits into
apache:master
from
PDavid:HBASE-28621-PrefixFilter-SEEK_NEXT_USING_HINT
Nov 6, 2024
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
42ca0cf
HBASE-28621 PrefixFilter should use SEEK_NEXT_USING_HINT
45d5cbf
HBASE-28621 Removed unused field from TestPrefixFilter
3280f9f
HBASE-28621 PrefixFilter should also provide hint on reversed scans
PDavid 75fd8fa
HBASE-28621 PrefixFilter now implements HintingFilter marker interface
PDavid 870e9b6
HBASE-28621 Added unit test for PrefixFilter with mini cluster
PDavid a9db7da
HBASE-28621 Fixed PrefixFilter hint with reverse scans
PDavid 0da2505
HBASE-28621 Added unit test for shorter rowKey than prefix length
PDavid 2792fb2
HBASE-28621 Make sure PrefixFilter.filterRow() returns true even when…
PDavid 31f34b4
HBASE-28621 Pre-compute reverse hint at creation
PDavid 5779bd4
HBASE-28621 Restored some tests in TestPrefixFilter related to WhileM…
PDavid 3225197
HBASE-28621 Moved hint-related methods before the serialization-relat…
PDavid 039c896
HBASE-28621 Also pre-compute forward hint at PrefixFilter creation
PDavid ce46c31
HBASE-28621 Fixed TestFilterList.testMPONE() unit test
PDavid 1aa84f5
HBASE-28621 Adjusted comment about behavior of PrefixFilter.filterRow…
PDavid ba21710
HBASE-28621 Fixed comment: use before/after
PDavid 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,9 +17,15 @@ | |
| */ | ||
| package org.apache.hadoop.hbase.filter; | ||
|
|
||
| import static org.junit.Assert.*; | ||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertFalse; | ||
| import static org.junit.Assert.assertNotNull; | ||
| import static org.junit.Assert.assertNull; | ||
| import static org.junit.Assert.assertTrue; | ||
|
|
||
| import org.apache.hadoop.hbase.Cell; | ||
| import org.apache.hadoop.hbase.HBaseClassTestRule; | ||
| import org.apache.hadoop.hbase.KeyValue; | ||
| import org.apache.hadoop.hbase.KeyValueUtil; | ||
| import org.apache.hadoop.hbase.testclassification.FilterTests; | ||
| import org.apache.hadoop.hbase.testclassification.SmallTests; | ||
|
|
@@ -40,7 +46,6 @@ public class TestPrefixFilter { | |
| static final char FIRST_CHAR = 'a'; | ||
| static final char LAST_CHAR = 'e'; | ||
| static final String HOST_PREFIX = "org.apache.site-"; | ||
| static final byte[] GOOD_BYTES = Bytes.toBytes("abc"); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is also a bit unrelated - an unused constant field. |
||
|
|
||
| @Before | ||
| public void setUp() throws Exception { | ||
|
|
@@ -82,13 +87,182 @@ private void prefixRowTests(Filter filter, boolean lastFilterAllRemaining) throw | |
| } | ||
| String yahooSite = "com.yahoo.www"; | ||
| byte[] yahooSiteBytes = Bytes.toBytes(yahooSite); | ||
| assertTrue("Failed with character " + yahooSite, | ||
| filter.filterRowKey(KeyValueUtil.createFirstOnRow(yahooSiteBytes))); | ||
| assertEquals(filter.filterAllRemaining(), lastFilterAllRemaining); | ||
| KeyValue yahooSiteCell = KeyValueUtil.createFirstOnRow(yahooSiteBytes); | ||
| assertFalse("Failed with character " + yahooSite, filter.filterRowKey(yahooSiteCell)); | ||
| assertEquals(Filter.ReturnCode.SEEK_NEXT_USING_HINT, filter.filterCell(yahooSiteCell)); | ||
| assertEquals(lastFilterAllRemaining, filter.filterAllRemaining()); | ||
| } | ||
|
|
||
| private byte[] createRow(final char c) { | ||
| return Bytes.toBytes(HOST_PREFIX + Character.toString(c)); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldProvideHintWhenKeyBefore() { | ||
| byte[] prefix = Bytes.toBytes("gg"); | ||
| PrefixFilter filter = new PrefixFilter(prefix); | ||
|
|
||
| KeyValue cell = KeyValueUtil.createFirstOnRow(Bytes.toBytes("aa")); | ||
|
|
||
| // Should include this row so that filterCell() will be invoked. | ||
| assertFalse(filter.filterRowKey(cell)); | ||
| assertEquals(Filter.ReturnCode.SEEK_NEXT_USING_HINT, filter.filterCell(cell)); | ||
| Cell actualCellHint = filter.getNextCellHint(cell); | ||
| assertNotNull(actualCellHint); | ||
| Cell expectedCellHint = KeyValueUtil.createFirstOnRow(prefix); | ||
| assertEquals(expectedCellHint, actualCellHint); | ||
| assertFalse(filter.filterAllRemaining()); | ||
| assertTrue(filter.filterRow()); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldProvideHintWhenKeyBeforeAndShorter() { | ||
| byte[] prefix = Bytes.toBytes("gggg"); | ||
| PrefixFilter filter = new PrefixFilter(prefix); | ||
|
|
||
| KeyValue cell = KeyValueUtil.createFirstOnRow(Bytes.toBytes("aa")); | ||
|
|
||
| // Should include this row so that filterCell() will be invoked. | ||
| assertFalse(filter.filterRowKey(cell)); | ||
| assertEquals(Filter.ReturnCode.SEEK_NEXT_USING_HINT, filter.filterCell(cell)); | ||
| Cell actualCellHint = filter.getNextCellHint(cell); | ||
| assertNotNull(actualCellHint); | ||
| Cell expectedCellHint = KeyValueUtil.createFirstOnRow(prefix); | ||
| assertEquals(expectedCellHint, actualCellHint); | ||
| assertFalse(filter.filterAllRemaining()); | ||
| assertTrue(filter.filterRow()); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldIncludeWhenKeyMatches() { | ||
| PrefixFilter filter = new PrefixFilter(Bytes.toBytes("gg")); | ||
|
|
||
| KeyValue matchingCell = KeyValueUtil.createFirstOnRow(Bytes.toBytes("gg")); | ||
|
|
||
| assertFalse(filter.filterRowKey(matchingCell)); | ||
| assertEquals(Filter.ReturnCode.INCLUDE, filter.filterCell(matchingCell)); | ||
| assertFalse(filter.filterAllRemaining()); | ||
| assertFalse(filter.filterRow()); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldReturnNextRowWhenKeyAfter() { | ||
| PrefixFilter filter = new PrefixFilter(Bytes.toBytes("gg")); | ||
|
|
||
| KeyValue afterCell = KeyValueUtil.createFirstOnRow(Bytes.toBytes("pp")); | ||
|
|
||
| assertTrue(filter.filterRowKey(afterCell)); | ||
| assertEquals(Filter.ReturnCode.NEXT_ROW, filter.filterCell(afterCell)); | ||
| assertTrue(filter.filterAllRemaining()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This API is so awkward... |
||
| assertTrue(filter.filterRow()); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldProvideHintWhenKeyBeforeReversed() { | ||
| PrefixFilter filter = new PrefixFilter(Bytes.toBytes("aa")); | ||
| filter.setReversed(true); | ||
|
|
||
| KeyValue cell = KeyValueUtil.createFirstOnRow(Bytes.toBytes("x")); | ||
|
|
||
| // Should include this row so that filterCell() will be invoked. | ||
| assertFalse(filter.filterRowKey(cell)); | ||
| assertEquals(Filter.ReturnCode.SEEK_NEXT_USING_HINT, filter.filterCell(cell)); | ||
| Cell actualCellHint = filter.getNextCellHint(cell); | ||
| assertNotNull(actualCellHint); | ||
| Cell expectedCellHint = KeyValueUtil.createFirstOnRow(Bytes.toBytes("ab")); | ||
| assertEquals(expectedCellHint, actualCellHint); | ||
| assertFalse(filter.filterAllRemaining()); | ||
| assertTrue(filter.filterRow()); | ||
| } | ||
|
|
||
| @Test | ||
| public void hintShouldIncreaseLastNonMaxByteWhenReversed() { | ||
| PrefixFilter filter = new PrefixFilter(new byte[] { 'a', 'a', Byte.MAX_VALUE }); | ||
| filter.setReversed(true); | ||
|
|
||
| KeyValue cell = KeyValueUtil.createFirstOnRow(Bytes.toBytes("x")); | ||
|
|
||
| // Should include this row so that filterCell() will be invoked. | ||
| assertFalse(filter.filterRowKey(cell)); | ||
| assertEquals(Filter.ReturnCode.SEEK_NEXT_USING_HINT, filter.filterCell(cell)); | ||
| Cell actualCellHint = filter.getNextCellHint(cell); | ||
| assertNotNull(actualCellHint); | ||
| Cell expectedCellHint = KeyValueUtil.createFirstOnRow(new byte[] { 'a', 'b', Byte.MAX_VALUE }); | ||
| assertEquals(expectedCellHint, actualCellHint); | ||
| assertFalse(filter.filterAllRemaining()); | ||
| assertTrue(filter.filterRow()); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldIncludeWhenKeyMatchesReversed() { | ||
| PrefixFilter filter = new PrefixFilter(Bytes.toBytes("aa")); | ||
| filter.setReversed(true); | ||
|
|
||
| KeyValue matchingCell = KeyValueUtil.createFirstOnRow(Bytes.toBytes("aa")); | ||
|
|
||
| assertFalse(filter.filterRowKey(matchingCell)); | ||
| assertEquals(Filter.ReturnCode.INCLUDE, filter.filterCell(matchingCell)); | ||
| assertFalse(filter.filterAllRemaining()); | ||
| assertFalse(filter.filterRow()); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldReturnNextRowWhenKeyAfterReversed() { | ||
| PrefixFilter filter = new PrefixFilter(Bytes.toBytes("dd")); | ||
| filter.setReversed(true); | ||
|
|
||
| KeyValue cell = KeyValueUtil.createFirstOnRow(Bytes.toBytes("aa")); | ||
|
|
||
| assertTrue(filter.filterRowKey(cell)); | ||
| assertEquals(Filter.ReturnCode.NEXT_ROW, filter.filterCell(cell)); | ||
| assertTrue(filter.filterAllRemaining()); | ||
| assertTrue(filter.filterRow()); | ||
| } | ||
|
|
||
| @Test | ||
| public void hintShouldNotIncreaseMaxBytesWhenReversed() { | ||
| PrefixFilter filter = | ||
| new PrefixFilter(new byte[] { Byte.MAX_VALUE, Byte.MAX_VALUE, Byte.MAX_VALUE }); | ||
| filter.setReversed(true); | ||
|
|
||
| KeyValue cell = KeyValueUtil.createFirstOnRow(Bytes.toBytes("x")); | ||
|
|
||
| assertTrue(filter.filterRowKey(cell)); | ||
| assertEquals(Filter.ReturnCode.NEXT_ROW, filter.filterCell(cell)); | ||
| Cell actualCellHint = filter.getNextCellHint(cell); | ||
| assertNotNull(actualCellHint); | ||
| Cell expectedCellHint = | ||
| KeyValueUtil.createFirstOnRow(new byte[] { Byte.MAX_VALUE, Byte.MAX_VALUE, Byte.MAX_VALUE }); | ||
| assertEquals(expectedCellHint, actualCellHint); | ||
| assertTrue(filter.filterAllRemaining()); | ||
| assertTrue(filter.filterRow()); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldNotThrowWhenCreatedWithNullPrefix() { | ||
| PrefixFilter filter = new PrefixFilter(null); | ||
| KeyValue cell = KeyValueUtil.createFirstOnRow(Bytes.toBytes("doesNotMatter")); | ||
|
|
||
| assertNull(filter.getNextCellHint(cell)); | ||
| filter.setReversed(true); | ||
| assertNull(filter.getNextCellHint(cell)); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldNotThrowWhenCreatedWithEmptyByteArrayPrefix() { | ||
| byte[] emptyPrefix = {}; | ||
| KeyValue emptyPrefixCell = KeyValueUtil.createFirstOnRow(emptyPrefix); | ||
| KeyValue cell = KeyValueUtil.createFirstOnRow(Bytes.toBytes("doesNotMatter")); | ||
|
|
||
| PrefixFilter filter = new PrefixFilter(emptyPrefix); | ||
|
|
||
| Cell forwardNextCellHint = filter.getNextCellHint(cell); | ||
| assertNotNull(forwardNextCellHint); | ||
| assertEquals(emptyPrefixCell, forwardNextCellHint); | ||
|
|
||
| filter.setReversed(true); | ||
| Cell reverseNextCellHint = filter.getNextCellHint(cell); | ||
| assertNotNull(reverseNextCellHint); | ||
| assertEquals(emptyPrefixCell, reverseNextCellHint); | ||
| } | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was about to say that we could choose the direction here, but interestingly the direction is not available here yet.
Another API awkwardness.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly. The direction can be influenced with
setReversed()which can be invoked only after the filter creation.So it is available but can be changed after creation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Practically, I'm sure it's not changed after any of the Cell processing methods have been called.
It is called once when the Scan is set up. (perhaps also after reset() is called)