virajjasani commented on code in PR #7882:
URL: https://github.com/apache/hbase/pull/7882#discussion_r3103755156
##########
hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/querymatcher/TestUserScanQueryMatcher.java:
##########
@@ -398,6 +419,232 @@ scanWithFilter, new ScanInfo(this.conf, fam2, 0, 5, ttl,
KeepDeletedCells.FALSE,
assertArrayEquals(nextCell.getQualifierArray(), col4);
}
+ // -----------------------------------------------------------------------
+ // Tests for HBASE-29974: Filter#getSkipHint consulted at matchColumn
+ // structural short-circuits (time-range, column, and version gates).
+ // -----------------------------------------------------------------------
Review Comment:
Let's remove these lines
##########
hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestFilterHintForRejectedRow.java:
##########
@@ -0,0 +1,361 @@
+/*
+ * 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.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.hadoop.hbase.Cell;
+import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.HBaseTestingUtil;
+import org.apache.hadoop.hbase.PrivateCellUtil;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
+import org.apache.hadoop.hbase.client.Durability;
+import org.apache.hadoop.hbase.client.Put;
+import org.apache.hadoop.hbase.client.RegionInfo;
+import org.apache.hadoop.hbase.client.RegionInfoBuilder;
+import org.apache.hadoop.hbase.client.Scan;
+import org.apache.hadoop.hbase.client.TableDescriptor;
+import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
+import org.apache.hadoop.hbase.regionserver.HRegion;
+import org.apache.hadoop.hbase.regionserver.RegionScanner;
+import org.apache.hadoop.hbase.testclassification.FilterTests;
+import org.apache.hadoop.hbase.testclassification.MediumTests;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.TestName;
+
+/**
+ * Integration tests for HBASE-29974 Path 1: {@link
Filter#getHintForRejectedRow(Cell)} allows the
+ * scan pipeline to seek directly past rejected rows instead of iterating
through every cell in each
+ * rejected row one-by-one via {@code nextRow()}.
+ * <p>
+ * Each test verifies two properties simultaneously:
+ * <ol>
+ * <li><b>Correctness</b> — the scan returns exactly the rows that are not
rejected by
+ * {@link Filter#filterRowKey(Cell)}, regardless of whether the hint path or
the legacy
+ * cell-iteration path is used.</li>
+ * <li><b>Efficiency</b> — when a filter provides a hint that jumps over all N
rejected rows in one
+ * seek, {@code getHintForRejectedRow} is called exactly once (not N times),
proving that the
+ * scanner did not fall back to cell-by-cell iteration for the skipped
rows.</li>
+ * </ol>
+ */
+@Category({ FilterTests.class, MediumTests.class })
+public class TestFilterHintForRejectedRow {
+
+ @ClassRule
+ public static final HBaseClassTestRule CLASS_RULE =
+ HBaseClassTestRule.forClass(TestFilterHintForRejectedRow.class);
+
+ private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil();
+
+ private static final byte[] FAMILY = Bytes.toBytes("f");
+ private static final int CELLS_PER_ROW = 10;
+ private static final byte[] VALUE = Bytes.toBytes("value");
+
+ private HRegion region;
+
+ @Rule
+ public TestName name = new TestName();
+
+ @Before
+ public void setUp() throws Exception {
+ TableDescriptor tableDescriptor =
+
TableDescriptorBuilder.newBuilder(TableName.valueOf(name.getMethodName()))
+ .setColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILY)).build();
+ RegionInfo info =
RegionInfoBuilder.newBuilder(tableDescriptor.getTableName()).build();
+ this.region = HBaseTestingUtil.createRegionAndWAL(info,
TEST_UTIL.getDataTestDir(),
+ TEST_UTIL.getConfiguration(), tableDescriptor);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ HBaseTestingUtil.closeRegionAndWAL(this.region);
+ }
+
+ // -------------------------------------------------------------------------
+ // Helper
+ // -------------------------------------------------------------------------
+
+ /**
+ * Writes {@code count} rows into the test region. Row keys are formatted as
{@code "row-XX"}
+ * (zero-padded to two digits) and each row contains {@link #CELLS_PER_ROW}
cells with qualifier
+ * {@code "q-NN"}.
+ * @param prefix string prefix used for both row keys and qualifier names
+ * @param count number of rows to write
+ * @throws IOException if any put fails
+ */
+ private void writeRows(String prefix, int count) throws IOException {
+ for (int i = 0; i < count; i++) {
+ byte[] row = Bytes.toBytes(String.format("%s-%02d", prefix, i));
+ Put p = new Put(row);
+ p.setDurability(Durability.SKIP_WAL);
+ for (int j = 0; j < CELLS_PER_ROW; j++) {
+ p.addColumn(FAMILY, Bytes.toBytes(String.format("q-%02d", j)), VALUE);
+ }
+ this.region.put(p);
+ }
+ this.region.flush(true);
+ }
+
+ // -------------------------------------------------------------------------
+ // Tests
+ // -------------------------------------------------------------------------
+
+ /**
+ * HBASE-29974 Path 1 — single-batch seek hint.
+ * <p>
+ * The filter rejects the first 5 rows ({@code "row-00"} through {@code
"row-04"}) via
+ * {@link Filter#filterRowKey(Cell)} and, for every rejected row, returns a
hint pointing directly
+ * to {@code "row-05"} via {@link Filter#getHintForRejectedRow(Cell)}.
+ * <p>
+ * Expected behaviour:
+ * <ul>
+ * <li>The scanner seeks directly to {@code "row-05"} after the very first
rejection, bypassing
+ * cells in rows {@code "row-01"} through {@code "row-04"} entirely.</li>
+ * <li>{@code getHintForRejectedRow} is called exactly once (not five
times), confirming no
+ * cell-by-cell iteration occurred for the skipped rows.</li>
+ * <li>Rows {@code "row-05"} through {@code "row-09"} are returned with all
their cells
+ * intact.</li>
+ * </ul>
+ */
+ @Test
+ public void testHintJumpsOverAllRejectedRowsInOneSingleSeek() throws
IOException {
Review Comment:
`testHintJumpsOverAllRejectedRowsInOneSingleSeek()` and
`testNullHintFallsThroughToLegacyNextRowBehaviour()` should be combined in
single test. When we check for data correctness, we should check it on the same
table, same data, one with `hintFilter`, one with `noHintFilter` and compare
cells. Separate tests do not serve the same purpose.
##########
hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestFilterHintForRejectedRow.java:
##########
@@ -0,0 +1,361 @@
+/*
+ * 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.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.hadoop.hbase.Cell;
+import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.HBaseTestingUtil;
+import org.apache.hadoop.hbase.PrivateCellUtil;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
+import org.apache.hadoop.hbase.client.Durability;
+import org.apache.hadoop.hbase.client.Put;
+import org.apache.hadoop.hbase.client.RegionInfo;
+import org.apache.hadoop.hbase.client.RegionInfoBuilder;
+import org.apache.hadoop.hbase.client.Scan;
+import org.apache.hadoop.hbase.client.TableDescriptor;
+import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
+import org.apache.hadoop.hbase.regionserver.HRegion;
+import org.apache.hadoop.hbase.regionserver.RegionScanner;
+import org.apache.hadoop.hbase.testclassification.FilterTests;
+import org.apache.hadoop.hbase.testclassification.MediumTests;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.TestName;
+
+/**
+ * Integration tests for HBASE-29974 Path 1: {@link
Filter#getHintForRejectedRow(Cell)} allows the
+ * scan pipeline to seek directly past rejected rows instead of iterating
through every cell in each
+ * rejected row one-by-one via {@code nextRow()}.
+ * <p>
+ * Each test verifies two properties simultaneously:
+ * <ol>
+ * <li><b>Correctness</b> — the scan returns exactly the rows that are not
rejected by
+ * {@link Filter#filterRowKey(Cell)}, regardless of whether the hint path or
the legacy
+ * cell-iteration path is used.</li>
+ * <li><b>Efficiency</b> — when a filter provides a hint that jumps over all N
rejected rows in one
+ * seek, {@code getHintForRejectedRow} is called exactly once (not N times),
proving that the
+ * scanner did not fall back to cell-by-cell iteration for the skipped
rows.</li>
+ * </ol>
+ */
+@Category({ FilterTests.class, MediumTests.class })
+public class TestFilterHintForRejectedRow {
Review Comment:
For all tests in this class, it seems we are not overriding `getSkipHint()`.
Let's create one test where we some cells are out of scan time-range and
`getSkipHint()` is used. Then for the same data, we can use scan without
`getSkipHint()` and it should still return same cells, for the data correctness
comparison.
##########
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/querymatcher/UserScanQueryMatcher.java:
##########
@@ -107,18 +117,26 @@ public Filter getFilter() {
@Override
public ExtendedCell getNextKeyHint(ExtendedCell cell) throws IOException {
+ // A structural short-circuit in matchColumn (time-range, column, or
version gate) may have
+ // stored a hint via resolveSkipHint() before returning
SEEK_NEXT_USING_HINT. Drain and return
+ // it first; it takes priority because it was produced for the exact cell
that triggered the
+ // seek code, without ever calling filterCell.
+ if (pendingSkipHint != null) {
+ ExtendedCell hint = pendingSkipHint;
+ pendingSkipHint = null;
+ return hint;
+ }
+ // Normal path: filterCell returned SEEK_NEXT_USING_HINT — delegate to the
filter.
if (filter == null) {
return null;
+ }
+ Cell hint = filter.getNextCellHint(cell);
+ if (hint == null || hint instanceof ExtendedCell) {
+ return (ExtendedCell) hint;
} else {
- Cell hint = filter.getNextCellHint(cell);
- if (hint == null || hint instanceof ExtendedCell) {
- return (ExtendedCell) hint;
- } else {
- throw new DoNotRetryIOException("Incorrect filter implementation, "
- + "the Cell returned by getNextKeyHint is not an ExtendedCell.
Filter class: "
- + filter.getClass().getName());
- }
-
+ throw new DoNotRetryIOException("Incorrect filter implementation, "
+ + "the Cell returned by getNextKeyHint is not an ExtendedCell. Filter
class: "
+ + filter.getClass().getName());
}
Review Comment:
Is this part changing at all? I guess this is only structural change.
Can we remove this change just to keep it like it was before?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]