Skip to content

Commit

Permalink
HBASE-28905: Skip excessive evaluations of LINK_NAME_PATTERN and REF_…
Browse files Browse the repository at this point in the history
…NAME_PATTERN regular expressions (#6348)

Signed-off-by: Wellington Chevreuil <wchevreuil@apache.org>
  • Loading branch information
charlesconnell authored and wchevreuil committed Oct 7, 2024
1 parent 9067198 commit 8eb4a41
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,13 @@ public static boolean isHFileLink(final Path path) {
* @return True if the path is a HFileLink.
*/
public static boolean isHFileLink(String fileName) {
// The LINK_NAME_PATTERN regex is not computationally trivial, so see if we can fast-fail
// on a simple heuristic first. The regex contains a literal "=", so if that character
// isn't in the fileName, then the regex cannot match.
if (!fileName.contains("=")) {
return false;
}

Matcher m = LINK_NAME_PATTERN.matcher(fileName);
if (!m.matches()) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class StoreFileInfo implements Configurable {

/**
* A non-capture group, for hfiles, so that this can be embedded. HFiles are uuid ([0-9a-z]+).
* Bulk loaded hfiles has (_SeqId_[0-9]+_) has suffix. The mob del file has (_del) as suffix.
* Bulk loaded hfiles have (_SeqId_[0-9]+_) as a suffix. The mob del file has (_del) as a suffix.
*/
public static final String HFILE_NAME_REGEX = "[0-9a-f]+(?:(?:_SeqId_[0-9]+_)|(?:_del))?";

Expand All @@ -66,7 +66,7 @@ public class StoreFileInfo implements Configurable {
* hfilelink reference names ({@code
*
<table>
* =<region>-<hfile>.<parentEncRegion>}) If reference, then the regex has more than just one
* =<region>-<hfile>.<parentEncRegion>}). If reference, then the regex has more than just one
* group. Group 1, hfile/hfilelink pattern, is this file's id. Group 2 '(.+)' is the reference's
* parent region name.
*/
Expand Down Expand Up @@ -533,6 +533,13 @@ public static boolean isReference(final Path path) {
* @return True if the path has format of a HStoreFile reference.
*/
public static boolean isReference(final String name) {
// The REF_NAME_PATTERN regex is not computationally trivial, so see if we can fast-fail
// on a simple heuristic first. The regex contains a literal ".", so if that character
// isn't in the name, then the regex cannot match.
if (!name.contains(".")) {
return false;
}

Matcher m = REF_NAME_PATTERN.matcher(name);
return m.matches() && m.groupCount() > 1;
}
Expand Down

0 comments on commit 8eb4a41

Please sign in to comment.