[ 
https://issues.apache.org/jira/browse/SENTRY-1937?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16162510#comment-16162510
 ] 

Alexander Kolbasov commented on SENTRY-1937:
--------------------------------------------

Here is what I tried and seen a noticeable performance improvement:

{code}
  public Set<TSentryRole> getTSentryRolesByGroupNameOptimized(final Set<String> 
groupNames,
                                                              boolean 
checkAllGroups) throws Exception {
    return tm.executeTransaction(
            new TransactionBlock<Set<TSentryRole>>() {
              @Override
              public Set<TSentryRole> execute(PersistenceManager pm) throws 
Exception {
                pm.setDetachAllOnCommit(false); // No need to detach objects
                Set<MSentryRole> roles = new HashSet<>();
                for(String group: groupNames) {
                  Query query = pm.newQuery(MSentryGroup.class);
                  query.addExtension(LOAD_RESULTS_AT_COMMIT, "false");
                  query.setFilter("this.groupName == :groupName");
                  query.setUnique(true);
                  MSentryGroup mGroup = (MSentryGroup) query.execute(group);
                  roles.addAll(mGroup.getRoles());
                  query.closeAll();
                }
                Set<TSentryRole> result = new HashSet<>(roles.size());
                for (MSentryRole role: roles) {
                  result.add(convertToTSentryRole(role));
                }
                return result;
              }
            }
    );
  }
{code}

> Optimize performance for listing sentry roles by group name
> -----------------------------------------------------------
>
>                 Key: SENTRY-1937
>                 URL: https://issues.apache.org/jira/browse/SENTRY-1937
>             Project: Sentry
>          Issue Type: Improvement
>          Components: Sentry
>    Affects Versions: 2.0.0
>            Reporter: Alexander Kolbasov
>            Assignee: Arjun Mishra
>
> It seems that the most common request is listing sentry roles by group name, 
> so this is a very hot path. It is important to optimize its performance, 
> especially in the presence of many roles.
> [~arjunmishra13] FYI.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to