-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Add regx pattern file filter for distributed load #18311
Merged
alluxio-bot
merged 5 commits into
Alluxio:main
from
JiamingMai:add-regx-pattern-file-filter
Oct 26, 2023
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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 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 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 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 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 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 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 |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
import alluxio.grpc.LoadJobPOptions; | ||
import alluxio.job.LoadJobRequest; | ||
import alluxio.master.file.DefaultFileSystemMaster; | ||
import alluxio.master.predicate.FilePredicate; | ||
import alluxio.scheduler.job.Job; | ||
import alluxio.scheduler.job.JobFactory; | ||
import alluxio.security.User; | ||
|
@@ -29,6 +30,7 @@ | |
import java.util.Optional; | ||
import java.util.OptionalLong; | ||
import java.util.UUID; | ||
import java.util.function.Predicate; | ||
|
||
/** | ||
* Factory for creating {@link LoadJob}s that get file infos from master. | ||
|
@@ -60,14 +62,28 @@ public Job<?> create() { | |
.ofNullable(AuthenticatedClientUser.getOrNull()) | ||
.map(User::getName); | ||
|
||
Predicate<UfsStatus> predicate = Predicates.alwaysTrue(); | ||
Optional<String> fileFilterRegx = Optional.empty(); | ||
if (options.hasFileFilterRegx()) { | ||
String regxPatternStr = options.getFileFilterRegx(); | ||
if (regxPatternStr != null && !regxPatternStr.isEmpty()) { | ||
alluxio.proto.journal.Job.FileFilter.Builder builder = | ||
alluxio.proto.journal.Job.FileFilter.newBuilder() | ||
.setName("fileNamePattern").setValue(regxPatternStr); | ||
FilePredicate filePredicate = FilePredicate.create(builder.build()); | ||
predicate = filePredicate.getUfsStatusPredicate(); | ||
fileFilterRegx = Optional.of(regxPatternStr); | ||
} | ||
} | ||
|
||
UnderFileSystem ufs = mFs.getUfsManager().getOrAdd(new AlluxioURI(path), | ||
() -> UnderFileSystemConfiguration.defaults(Configuration.global())); | ||
Iterable<UfsStatus> iterable = new UfsStatusIterable(ufs, path, | ||
Optional.ofNullable(AuthenticatedClientUser.getOrNull()).map(User::getName), | ||
Predicates.alwaysTrue()); | ||
predicate); | ||
return new DoraLoadJob(path, user, UUID.randomUUID().toString(), bandwidth, partialListing, | ||
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. We also want to put this filter information into DoraLoadJob so we can turn this job into a journal entry. 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. Updated. |
||
verificationEnabled, options.getLoadMetadataOnly(), options.getSkipIfExists(), | ||
iterable.iterator(), ufs); | ||
fileFilterRegx, iterable.iterator(), ufs); | ||
} | ||
} | ||
|
This file contains 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
122 changes: 122 additions & 0 deletions
122
dora/core/server/master/src/main/java/alluxio/master/predicate/FileNamePatternPredicate.java
This file contains 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,122 @@ | ||
/* | ||
* The Alluxio Open Foundation licenses this work under the Apache License, version 2.0 | ||
* (the "License"). You may not use this work except in compliance with the License, which is | ||
* available at www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
* either express or implied, as more fully set forth in the License. | ||
* | ||
* See the NOTICE file distributed with this work for information regarding copyright ownership. | ||
*/ | ||
|
||
package alluxio.master.predicate; | ||
|
||
import alluxio.proto.journal.Job.FileFilter; | ||
import alluxio.underfs.UfsStatus; | ||
import alluxio.wire.FileInfo; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.function.Predicate; | ||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* A predicate related to date of the file. | ||
*/ | ||
public class FileNamePatternPredicate implements FilePredicate { | ||
private static final Logger LOG = LoggerFactory.getLogger(FileNamePatternPredicate.class); | ||
private final String mFilterName; | ||
private String mRegexPatternStr; | ||
|
||
/** | ||
* Factory for modification time predicate. | ||
*/ | ||
public static class FileNamePatternFactory extends Factory { | ||
@Override | ||
public String getFilterName() { | ||
return "fileNamePattern"; | ||
} | ||
} | ||
|
||
/** | ||
* Factory for creating instances. | ||
*/ | ||
public abstract static class Factory implements FilePredicateFactory { | ||
/** | ||
* @return filter name for the predicate | ||
*/ | ||
public abstract String getFilterName(); | ||
|
||
/** | ||
* Creates a {@link FilePredicate} from the string value. | ||
* | ||
* @param regexPatternStr the regex pattern string from the filter | ||
* @return the created predicate | ||
*/ | ||
public FilePredicate createFileNamePatternPredicate(String regexPatternStr) { | ||
return new FileNamePatternPredicate(getFilterName(), regexPatternStr); | ||
} | ||
|
||
@Override | ||
public FilePredicate create(FileFilter filter) { | ||
try { | ||
if (filter.hasName() && filter.getName().equals(getFilterName())) { | ||
if (filter.hasValue()) { | ||
return createFileNamePatternPredicate(filter.getValue()); | ||
} | ||
} | ||
} catch (Exception e) { | ||
// fall through | ||
} | ||
return null; | ||
} | ||
} | ||
|
||
/** | ||
* Creates an instance. | ||
* | ||
* @param filterName the filter name | ||
* @param regexPatternStr the regex pattern string for file filtering | ||
*/ | ||
public FileNamePatternPredicate(String filterName, String regexPatternStr) { | ||
mFilterName = filterName; | ||
mRegexPatternStr = regexPatternStr; | ||
} | ||
|
||
@Override | ||
public Predicate<FileInfo> get() { | ||
return FileInfo -> { | ||
try { | ||
String fileName = FileInfo.getName(); | ||
return Pattern.matches(mRegexPatternStr, fileName); | ||
} catch (RuntimeException e) { | ||
LOG.debug("Failed to filter: ", e); | ||
return false; | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public Predicate<UfsStatus> getUfsStatusPredicate() { | ||
return UfsStatus -> { | ||
try { | ||
String fileName = getFileName(UfsStatus); | ||
return Pattern.matches(mRegexPatternStr, fileName); | ||
} catch (RuntimeException e) { | ||
LOG.debug("Failed to filter: ", e); | ||
return false; | ||
} | ||
}; | ||
} | ||
|
||
private String getFileName(UfsStatus ufsStatus) { | ||
String name = ufsStatus.getName(); | ||
int index = name.lastIndexOf("/"); | ||
if (index == -1) { | ||
return name; | ||
} | ||
name = name.substring(index + 1); | ||
return name; | ||
} | ||
} |
This file contains 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 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 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 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.
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.
These logic should also appear at JournaledLoadJobFactory so we can recover from journal entry
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.
Updated. I put these logic into JournaledLoadJobFactory.