Skip to content

Commit

Permalink
[ADH-4134] Use thread local matcher in PathChecker to prevent race co…
Browse files Browse the repository at this point in the history
…ndition of SmartServer RPC server threads checking ignored paths
  • Loading branch information
tigrulya-exe committed Mar 7, 2024
1 parent 22eefdf commit 846034a
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions smart-common/src/main/java/org/smartdata/model/PathChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
public class PathChecker {
private static final String IGNORED_PATH_TEMPLATES_DELIMITER = ",";

private final Matcher patternMatcher;
private final ThreadLocal<Matcher> patternMatcherThreadLocal;
private final List<String> coverDirs;

public PathChecker(SmartConf configuration) {
Expand All @@ -52,13 +52,15 @@ public PathChecker(List<String> ignoredPathPatterns, List<String> coverDirs) {
ignoredPathPatterns.forEach(patternBuilder::add);

Pattern pattern = Pattern.compile(patternBuilder.toString());
this.patternMatcher = pattern.matcher("");
this.patternMatcherThreadLocal =
ThreadLocal.withInitial(() -> pattern.matcher(""));
this.coverDirs = coverDirs;
}

public boolean isIgnored(String absolutePath) {
patternMatcher.reset(absolutePath);
return patternMatcher.find();
return patternMatcherThreadLocal.get()
.reset(absolutePath)
.find();
}

public boolean isCovered(String absolutePath) {
Expand Down

0 comments on commit 846034a

Please sign in to comment.