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

Na Li commented on SENTRY-2184:
-------------------------------

[~akolb] "somewhat symmetrical issue when writing snapshots " from the code 
below, for each MAuthzPathsMapping, there is a query to save the instance. Need 
to spend time to see how 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 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}

> Performance Issue: MPath is queried for each MAuthzPathsMapping in full 
> snapshot
> --------------------------------------------------------------------------------
>
>                 Key: SENTRY-2184
>                 URL: https://issues.apache.org/jira/browse/SENTRY-2184
>             Project: Sentry
>          Issue Type: Bug
>          Components: Sentry
>    Affects Versions: 2.1.0
>            Reporter: Na Li
>            Assignee: Na Li
>            Priority: Critical
>         Attachments: SENTRY-2184.001.patch
>
>
> MAuthzPathsMapping contains list of MPath instances. From log message, when 
> getting path full snapshot at SentryStore.retrieveFullPathsImageCore(), 
> DataNucleus issues a query for all MPath instances associated with each 
> MAuthzPathsMapping. Therefore, getting full path image may take a very long 
> time.
> The solution is to get MPath in a batch when getting full path image.
> Log Message when DataNucleus issues a query for all MPath instances 
> associated with each MAuthzPathsMapping
> {code:java}
> 1) Initially, all MAuthzPathsMapping entries for current snapshot is queried.
> 2018-03-14 11:51:23,999 (main) [DEBUG - 
> org.datanucleus.util.Log4JLogger.debug(Log4JLogger.java:58)] SELECT 
> 'org.apache.sentry.provider.db.service.model.MAuthzPathsMapping' AS 
> NUCLEUS_TYPE,A0.AUTHZ_OBJ_NAME,A0.AUTHZ_SNAPSHOT_ID,A0.CREATE_TIME_MS,A0.AUTHZ_OBJ_ID
>  FROM AUTHZ_PATHS_MAPPING A0 WHERE A0.AUTHZ_SNAPSHOT_ID = <1>
> 2) call authzToPaths.getPathStrings() causes MPath to be queried for each 
> AUTHZ_OBJ_ID
> 2018-03-14 11:52:27,700 (main) [DEBUG - 
> org.datanucleus.util.Log4JLogger.debug(Log4JLogger.java:58)] SELECT 
> 'org.apache.sentry.provider.db.service.model.MPath' AS 
> NUCLEUS_TYPE,A0.PATH_NAME,A0.PATH_ID FROM AUTHZ_PATH A0 WHERE A0.AUTHZ_OBJ_ID 
> = <1>{code}



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

Reply via email to