Skip to content
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

Ensure the index for rep:ACL is correctly detected #714

Open
ghenzler opened this issue May 16, 2024 · 2 comments · May be fixed by #720
Open

Ensure the index for rep:ACL is correctly detected #714

ghenzler opened this issue May 16, 2024 · 2 comments · May be fixed by #720
Milestone

Comments

@ghenzler
Copy link
Member

ghenzler commented May 16, 2024

In AEMaaCS there is currently the issue that even though the oak index /oak:index/repACL-custom-1 is installed, QueryHelper [1] takes the wrong query for ACEs instead of ACLs, and for our case we are above the 100,000 query limit with that. [2] should really give access to /oak:index/repACL-custom-1, but session.nodeExists(OAK_INDEX_PATH_REP_ACL) returns false.

[1]

boolean indexForRepACLExists = session.nodeExists(OAK_INDEX_PATH_REP_ACL);
LOG.debug("Index for repACL exists: {}",indexForRepACLExists);
String queryForAClNodes = indexForRepACLExists ?
"SELECT * FROM [rep:ACL] WHERE ISDESCENDANTNODE([%s])" :
"SELECT ace.* FROM [rep:ACE] AS ace WHERE ace.[rep:principalName] IS NOT NULL AND ISDESCENDANTNODE(ace, [%s])";
LOG.debug("Query to obtain all ACLs: {}", queryForAClNodes);

[2]

@kwin kwin added this to the 3.1.1 milestone Jun 4, 2024
@ghenzler
Copy link
Member Author

ghenzler commented Jun 4, 2024

As quick test I created the following groovy script as an alternative to detect if a index for node type rep:ACL exists:

String checkIndexExplainQuery = "EXPLAIN SELECT * FROM [rep:ACL] AS s WHERE ISDESCENDANTNODE([/etc])";
def query = session.getWorkspace().getQueryManager().createQuery(checkIndexExplainQuery, javax.jcr.query.Query.JCR_SQL2);

def plan = query.execute().getRows().nextRow().getValues()[0]

boolean indexExists = (plan =~ "(?ms).*indexDefinition:.*luceneQuery:.*jcr:primaryType:rep:ACL.*")

println "Index for node type rep:ACL exists: ${indexExists}\n" 
println "Execution Plan:\n " + plan

Pro:

  • This approach does not require read access to /oak:index (in the SDK it's visible, in the CS by default /oak:index has a deny for everyone in the ACL)
  • For projects that do for some reason not like to use accesscontroltool-oakindex-package directly but define their own index for rep:ACL, we don't hard-code the name
  • Also if we have to create a new version /oak:index/repACL-custom-2 at some point the index path would not be hard-coded anymore

Con:

  • The regex on the explain query might be brittle if oak chooses to change that string format at some point (the current regex is quite specific, we could also make it more open)

@kwin
Copy link
Member

kwin commented Jun 4, 2024

Wouldn't a EXPLAIN MEASURE be more stable with regards to the return value (just evaluating the double value representing the cost)?
If it is above a certain threshold we can derive from that a better index than the traversal fallback one does not exist.

kwin added a commit that referenced this issue Jun 4, 2024
Rely on EXPLAIN MEASURE and evaluate the estimated cost.

This closes #714
kwin added a commit that referenced this issue Jun 5, 2024
Rely on EXPLAIN MEASURE and evaluate the estimated cost.

This closes #714
kwin added a commit that referenced this issue Jun 5, 2024
Rely on EXPLAIN MEASURE and evaluate the estimated cost.

This closes #714
kwin added a commit that referenced this issue Jun 5, 2024
Rely on EXPLAIN MEASURE and evaluate the estimated cost.

This closes #714
kwin added a commit that referenced this issue Jun 5, 2024
Rely on EXPLAIN MEASURE and evaluate the estimated cost.

This closes #714
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants