Skip to content

Commit

Permalink
RANGER-4478: Incorrect trie updates when processing deltas - Part 3
Browse files Browse the repository at this point in the history
  • Loading branch information
kulkabhay committed Nov 4, 2023
1 parent 0558fa9 commit 3f78f9f
Showing 1 changed file with 37 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ private void insert(TrieNode<T> currentRoot, String resource, boolean isRecursiv

}

private String getNonWildcardPrefix(String str) {
private int getNonWildcardPrefixLength(String str) {
int minIndex = str.length();

for (int i = 0; i < wildcardChars.length(); i++) {
Expand All @@ -587,9 +587,17 @@ private String getNonWildcardPrefix(String str) {
}
}

return str.substring(0, minIndex);
return minIndex;
}

private String getNonWildcardPrefix(String str) {
int prefixLen = getNonWildcardPrefixLength(str);

return (prefixLen < str.length()) ? str.substring(0, prefixLen) : str;
}



private Set<T> getEvaluatorsForResource(String resource, ResourceElementMatchingScope scope) {
if(LOG.isDebugEnabled()) {
LOG.debug("==> RangerResourceTrie.getEvaluatorsForResource(" + resource + ", " + scope + ")");
Expand Down Expand Up @@ -718,7 +726,7 @@ private TrieNode<T> getNodeForResource(String resource) {
}

TrieNode<T> curr = root;
final int len = resource.length();
final int len = getNonWildcardPrefixLength(resource);
int i = 0;

while (i < len) {
Expand All @@ -738,6 +746,8 @@ private TrieNode<T> getNodeForResource(String resource) {
i += childStr.length();
}

curr = (i == len) ? curr : null;

RangerPerfTracer.logAlways(perf);

if(LOG.isDebugEnabled()) {
Expand Down Expand Up @@ -1128,11 +1138,21 @@ void undoSetup() {
}

void removeSelfFromTrie() {
if (evaluators == null && wildcardEvaluators == null && children.size() == 0) {
if (LOG.isDebugEnabled()) {
LOG.debug("==> removeSelfFromTrie(" + this + ")");
}
if (evaluators == null && children.size() == 0) {
TrieNode<U> parent = getParent();
if (parent != null) {
parent.children.remove(str.charAt(0));
}
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("removeSelfFromTrie(" + this + ") could not remove self from Trie");
}
}
if (LOG.isDebugEnabled()) {
LOG.debug("<== removeSelfFromTrie(" + this + ")");
}
}

Expand Down Expand Up @@ -1298,12 +1318,25 @@ private void collectChildEvaluators(Set<U> childEvaluators) {
}

private void removeEvaluatorFromSubtree(U evaluator) {
if (LOG.isDebugEnabled()) {
LOG.debug("==> removeEvaluatorFromSubtree(" + evaluator.getId() + ")");
}
if (CollectionUtils.isNotEmpty(wildcardEvaluators) && wildcardEvaluators.contains(evaluator)) {
removeWildcardEvaluator(evaluator);
} else {
removeEvaluator(evaluator);
}
removeSelfFromTrie();
if (LOG.isDebugEnabled()) {
LOG.debug("<== removeEvaluatorFromSubtree(" + evaluator.getId() + ")");
}
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
toString(sb);
return sb.toString();
}

void toString(StringBuilder sb) {
Expand Down

0 comments on commit 3f78f9f

Please sign in to comment.