[ 
https://issues.apache.org/jira/browse/SENTRY-2185?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Alexander Kolbasov updated SENTRY-2185:
---------------------------------------
    Description: 
>From the code below, for each MAuthzPathsMapping, there is a query to save 
>each MAuthzPathsMapping instance. Need to save the changes in batch. 

{code:java}
  public void persistFullPathsImage(final Map<String, Collection<String>> 
authzPaths,
      final long notificationID) throws Exception {
    tm.executeTransactionWithRetry(
            pm -> {
              pm.setDetachAllOnCommit(false); // No need to detach objects
              deleteNotificationsSince(pm, notificationID + 1);

              // persist the notidicationID
              pm.makePersistent(new MSentryHmsNotification(notificationID));

              // persist the full snapshot
              long snapshotID = getCurrentAuthzPathsSnapshotID(pm);
              long nextSnapshotID = snapshotID + 1;
              pm.makePersistent(new MAuthzPathsSnapshotId(nextSnapshotID));
              LOGGER.info("Attempting to commit new HMS snapshot with ID = {}", 
nextSnapshotID);
              for (Map.Entry<String, Collection<String>> authzPath : 
authzPaths.entrySet()) {
                pm.makePersistent(new MAuthzPathsMapping(nextSnapshotID, 
authzPath.getKey(), authzPath.getValue()));
              }
              return null;
            });
  }{code}

  was:
>From the code below, for each MAuthzPathsMapping, there is a query to save 
>each MAuthzPathsMapping instance. Need to save the changes in batch. 

{code:java}
/**
* Persist an up-to-date HMS snapshot into Sentry DB in a single transaction 
with its latest
* notification ID
*
* @param authzPaths paths to be be persisted
* @param notificationID the latest notificationID associated with the snapshot
* @throws Exception
*/public void persistFullPathsImage(final Map<String, Collection<String>> 
authzPaths,final long notificationID) throws Exception {
tm.executeTransactionWithRetry(
pm -> {
pm.setDetachAllOnCommit(false); // No need to detach 
objectsdeleteNotificationsSince(pm, notificationID + 1);// persist the 
notidicationIDpm.makePersistent(new MSentryHmsNotification(notificationID));// 
persist the full snapshotlong snapshotID = 
getCurrentAuthzPathsSnapshotID(pm);long nextSnapshotID = snapshotID + 1;
pm.makePersistent(new MAuthzPathsSnapshotId(nextSnapshotID));
LOGGER.info("Attempting to commit new HMS snapshot with ID = {}", 
nextSnapshotID);for (Map.Entry<String, Collection<String>> authzPath : 
authzPaths.entrySet()) {
pm.makePersistent(new MAuthzPathsMapping(nextSnapshotID, authzPath.getKey(), 
authzPath.getValue()));
}return null;
});
}
{code}


> Performance Issue: Saving MAuthzPathsMapping should be done in batch for path 
> full snapshot
> -------------------------------------------------------------------------------------------
>
>                 Key: SENTRY-2185
>                 URL: https://issues.apache.org/jira/browse/SENTRY-2185
>             Project: Sentry
>          Issue Type: Bug
>          Components: Sentry
>    Affects Versions: 2.1.0
>            Reporter: Na Li
>            Priority: Major
>
> From the code below, for each MAuthzPathsMapping, there is a query to save 
> each MAuthzPathsMapping instance. Need to save the changes in batch. 
> {code:java}
>   public void persistFullPathsImage(final Map<String, Collection<String>> 
> authzPaths,
>       final long notificationID) throws Exception {
>     tm.executeTransactionWithRetry(
>             pm -> {
>               pm.setDetachAllOnCommit(false); // No need to detach objects
>               deleteNotificationsSince(pm, notificationID + 1);
>               // persist the notidicationID
>               pm.makePersistent(new MSentryHmsNotification(notificationID));
>               // persist the full snapshot
>               long snapshotID = getCurrentAuthzPathsSnapshotID(pm);
>               long nextSnapshotID = snapshotID + 1;
>               pm.makePersistent(new MAuthzPathsSnapshotId(nextSnapshotID));
>               LOGGER.info("Attempting to commit new HMS snapshot with ID = 
> {}", nextSnapshotID);
>               for (Map.Entry<String, Collection<String>> authzPath : 
> authzPaths.entrySet()) {
>                 pm.makePersistent(new MAuthzPathsMapping(nextSnapshotID, 
> authzPath.getKey(), authzPath.getValue()));
>               }
>               return null;
>             });
>   }{code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to