-
Notifications
You must be signed in to change notification settings - Fork 3.4k
HBASE-30115 Introduce approximate progress estimation for TableRecordReader based on row key position #8134
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
jinhyukify
wants to merge
5
commits into
apache:master
Choose a base branch
from
jinhyukify:HBASE-30115
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.
Open
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
468a39b
HBASE-30115 Introduce approximate progress estimation for TableRecord…
jinhyukify 400c39b
HBASE-30115 Align names with RegionSplitter and drop hex prefix lengt…
jinhyukify 22c6baa
HBASE-30115 Fix failing tests
jinhyukify efb99ab
HBASE-30115 Consider reverse scan start row
jinhyukify 00523d1
HBASE-30115 Handle capital hex alphabets
jinhyukify 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
67 changes: 67 additions & 0 deletions
67
hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/mapreduce/ByteBasedRowKeyProgress.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,67 @@ | ||
| /* | ||
| * 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.mapreduce; | ||
|
|
||
| import org.apache.yetus.audience.InterfaceAudience; | ||
|
|
||
| /** | ||
| * {@link RowKeyProgress} implementation that treats row keys as raw byte sequences. Converts the | ||
| * leading bytes to a big-endian unsigned numeric value and computes progress as a linear fraction | ||
| * of the key space. | ||
| */ | ||
| @InterfaceAudience.Public | ||
| public class ByteBasedRowKeyProgress implements RowKeyProgress { | ||
| private static final int BYTES_FOR_PROGRESS = Double.BYTES; | ||
|
|
||
| private double start; | ||
| private double stop; | ||
|
|
||
| @Override | ||
| public void setStartStopRows(byte[] startRow, byte[] stopRow) { | ||
| this.start = rowKeyToDouble(startRow); | ||
| this.stop = rowKeyToDouble(stopRow); | ||
| } | ||
|
|
||
| @Override | ||
| public float getProgress(byte[] currentRow) { | ||
| if (currentRow == null || stop <= start) { | ||
| return 0.0f; | ||
| } | ||
| double current = rowKeyToDouble(currentRow); | ||
| float progress = (float) ((current - start) / (stop - start)); | ||
| return Math.min(1.0f, Math.max(0.0f, progress)); | ||
| } | ||
|
|
||
| /** | ||
| * Interpret the leading bytes of a row key as an unsigned big-endian value. Keys shorter than | ||
| * {@link #BYTES_FOR_PROGRESS} bytes are treated as if right-padded with zeros. | ||
| */ | ||
| private static double rowKeyToDouble(byte[] row) { | ||
| if (row == null) { | ||
| return 0; | ||
| } | ||
| double d = 0; | ||
| for (int i = 0; i < BYTES_FOR_PROGRESS; i++) { | ||
| d *= 256; // shift left by one byte (2^8) to build a big-endian base-256 number | ||
| if (i < row.length) { | ||
| d += (row[i] & 0xFF); | ||
| } | ||
| } | ||
| return d; | ||
| } | ||
| } |
98 changes: 98 additions & 0 deletions
98
hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/mapreduce/HexPrefixRowKeyProgress.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,98 @@ | ||
| /* | ||
| * 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.mapreduce; | ||
|
|
||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.conf.Configured; | ||
| import org.apache.yetus.audience.InterfaceAudience; | ||
|
|
||
| /** | ||
| * {@link RowKeyProgress} implementation for tables whose row keys start with a hex-encoded prefix | ||
| * (e.g. MD5 hashes like {@code "a3f2b1..."}). Only the hex prefix is used for progress estimation; | ||
| * bytes beyond the prefix length are ignored. | ||
| * <p> | ||
| * The prefix length is configurable via {@link #PREFIX_LENGTH_KEY} and defaults to | ||
| * {@link #DEFAULT_PREFIX_LENGTH}. | ||
| * <p> | ||
| * Configure via: | ||
| * | ||
| * <pre> | ||
| * conf.setClass("hbase.mapreduce.rowkey.progress.class", HexPrefixRowKeyProgress.class, | ||
| * RowKeyProgress.class); | ||
| * conf.setInt("hbase.mapreduce.rowkey.progress.hex.prefix.length", 8); | ||
| * </pre> | ||
| */ | ||
| @InterfaceAudience.Public | ||
| public class HexPrefixRowKeyProgress extends Configured implements RowKeyProgress { | ||
| public static final String PREFIX_LENGTH_KEY = | ||
| "hbase.mapreduce.rowkey.progress.hex.prefix.length"; | ||
| public static final int DEFAULT_PREFIX_LENGTH = 4; | ||
|
|
||
| private int prefixLength = DEFAULT_PREFIX_LENGTH; | ||
| private double start; | ||
| private double stop; | ||
|
|
||
| @Override | ||
| public void setConf(Configuration conf) { | ||
| super.setConf(conf); | ||
| if (conf != null) { | ||
| this.prefixLength = conf.getInt(PREFIX_LENGTH_KEY, DEFAULT_PREFIX_LENGTH); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void setStartStopRows(byte[] startRow, byte[] stopRow) { | ||
| this.start = hexPrefixToDouble(startRow); | ||
| this.stop = hexPrefixToDouble(stopRow); | ||
| } | ||
|
|
||
| @Override | ||
| public float getProgress(byte[] currentRow) { | ||
| if (currentRow == null || stop <= start) { | ||
| return 0.0f; | ||
| } | ||
| double current = hexPrefixToDouble(currentRow); | ||
| float progress = (float) ((current - start) / (stop - start)); | ||
| return Math.min(1.0f, Math.max(0.0f, progress)); | ||
| } | ||
|
|
||
| private double hexPrefixToDouble(byte[] row) { | ||
| if (row == null) { | ||
| return 0; | ||
| } | ||
| int len = Math.min(prefixLength, row.length); | ||
| double d = 0; | ||
| for (int i = 0; i < prefixLength; i++) { | ||
| d *= 16; | ||
| if (i < len) { | ||
| d += hexCharToInt(row[i]); | ||
| } | ||
| } | ||
| return d; | ||
| } | ||
|
|
||
| private static int hexCharToInt(byte b) { | ||
| if (b >= '0' && b <= '9') { | ||
| return b - '0'; | ||
| } | ||
| if (b >= 'a' && b <= 'f') { | ||
| return 10 + (b - 'a'); | ||
| } | ||
| return 0; | ||
| } | ||
| } |
44 changes: 44 additions & 0 deletions
44
hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/mapreduce/RowKeyProgress.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,44 @@ | ||
| /* | ||
| * 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.mapreduce; | ||
|
|
||
| import org.apache.yetus.audience.InterfaceAudience; | ||
|
|
||
| /** | ||
| * Estimates scan progress based on row key positions within a start/stop range. Custom | ||
| * implementations can be plugged in via {@link RowKeyProgress#PROGRESS_CLASS_KEY}. | ||
| */ | ||
| @InterfaceAudience.Public | ||
| public interface RowKeyProgress { | ||
| String PROGRESS_CLASS_KEY = "hbase.mapreduce.rowkey.progress.class"; | ||
|
|
||
| /** | ||
| * Initialize the progress estimator with the start and stop row keys. | ||
| * @param startRow the start row of the scan (inclusive), may be null or empty | ||
| * @param stopRow the stop row of the scan (exclusive), may be null or empty | ||
| */ | ||
| void setStartStopRows(byte[] startRow, byte[] stopRow); | ||
|
|
||
| /** | ||
| * Estimate progress as a fraction between 0.0 and 1.0 based on where {@code currentRow} falls in | ||
| * the range. | ||
| * @param currentRow the last successfully read row key, or null if no row has been read yet | ||
| * @return estimated progress between 0.0 and 1.0, or 0.0 if progress cannot be estimated | ||
| */ | ||
| float getProgress(byte[] currentRow); | ||
| } |
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
Oops, something went wrong.
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.