You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sentry.apache.org by va...@apache.org on 2017/06/14 00:57:06 UTC

[28/52] [abbrv] sentry git commit: SENTRY-1770: Avoid more detaches on commit (Alex Kolbasov, reviewed by Vamsee Yarlagadda)

SENTRY-1770: Avoid more detaches on commit (Alex Kolbasov, reviewed by Vamsee Yarlagadda)

Change-Id: I50ed001ef38e6a81f9d41e1d2fc4bf3b1093df28
Reviewed-on: http://gerrit.sjc.cloudera.com:8080/22804
Tested-by: Jenkins User
Reviewed-by: Alexander Kolbasov <ak...@cloudera.com>


Project: http://git-wip-us.apache.org/repos/asf/sentry/repo
Commit: http://git-wip-us.apache.org/repos/asf/sentry/commit/71a12143
Tree: http://git-wip-us.apache.org/repos/asf/sentry/tree/71a12143
Diff: http://git-wip-us.apache.org/repos/asf/sentry/diff/71a12143

Branch: refs/for/cdh5-1.5.1_ha
Commit: 71a12143d8295f96e89326c2cc5d709bda6193fd
Parents: 1c9014e
Author: Alexander Kolbasov <ak...@cloudera.com>
Authored: Wed May 17 17:51:12 2017 -0700
Committer: Alexander Kolbasov <ak...@cloudera.com>
Committed: Wed May 17 20:16:58 2017 -0700

----------------------------------------------------------------------
 .../service/persistent/DelegateSentryStore.java |  6 ++++
 .../db/service/persistent/SentryStore.java      | 35 +++++++++++++++-----
 2 files changed, 33 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sentry/blob/71a12143/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/service/persistent/DelegateSentryStore.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/service/persistent/DelegateSentryStore.java b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/service/persistent/DelegateSentryStore.java
index 99e5161..30ad4db 100644
--- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/service/persistent/DelegateSentryStore.java
+++ b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/generic/service/persistent/DelegateSentryStore.java
@@ -118,6 +118,7 @@ public class DelegateSentryStore implements SentryStoreLayer {
     delegate.getTransactionManager().executeTransactionWithRetry(
       new TransactionBlock() {
         public Object execute(PersistenceManager pm) throws Exception {
+          pm.setDetachAllOnCommit(false); // No need to detach objects
           String trimmedRole = toTrimmedLower(role);
           MSentryRole mRole = getRole(trimmedRole, pm);
           if (mRole == null) {
@@ -141,6 +142,7 @@ public class DelegateSentryStore implements SentryStoreLayer {
     delegate.getTransactionManager().executeTransactionWithRetry(
       new TransactionBlock() {
         public Object execute(PersistenceManager pm) throws Exception {
+          pm.setDetachAllOnCommit(false); // No need to detach objects
           String trimmedRole = toTrimmedLower(role);
           MSentryRole mRole = getRole(trimmedRole, pm);
           if (mRole == null) {
@@ -177,6 +179,7 @@ public class DelegateSentryStore implements SentryStoreLayer {
     delegate.getTransactionManager().executeTransactionWithRetry(
         new TransactionBlock() {
           public Object execute(PersistenceManager pm) throws Exception {
+            pm.setDetachAllOnCommit(false); // No need to detach objects
             privilegeOperator.renamePrivilege(toTrimmedLower(component), toTrimmedLower(service),
                 oldAuthorizables, newAuthorizables, requestor, pm);
             return null;
@@ -193,6 +196,7 @@ public class DelegateSentryStore implements SentryStoreLayer {
     delegate.getTransactionManager().executeTransactionWithRetry(
         new TransactionBlock() {
           public Object execute(PersistenceManager pm) throws Exception {
+            pm.setDetachAllOnCommit(false); // No need to detach objects
             privilegeOperator.dropPrivilege(privilege, pm);
             return null;
           }
@@ -284,6 +288,7 @@ public class DelegateSentryStore implements SentryStoreLayer {
     return delegate.getTransactionManager().executeTransaction(
       new TransactionBlock<Set<PrivilegeObject>>() {
         public Set<PrivilegeObject> execute(PersistenceManager pm) throws Exception {
+          pm.setDetachAllOnCommit(false); // No need to detach objects
           Set<PrivilegeObject> privileges = new HashSet<>();
           Set<MSentryRole> mRoles = new HashSet<>();
           for (String role : roles) {
@@ -308,6 +313,7 @@ public class DelegateSentryStore implements SentryStoreLayer {
     return delegate.getTransactionManager().executeTransaction(
       new TransactionBlock<Set<PrivilegeObject>>() {
         public Set<PrivilegeObject> execute(PersistenceManager pm) throws Exception {
+          pm.setDetachAllOnCommit(false); // No need to detach objects
           String trimmedComponent = toTrimmedLower(component);
           String trimmedService = toTrimmedLower(service);
 

http://git-wip-us.apache.org/repos/asf/sentry/blob/71a12143/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/persistent/SentryStore.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/persistent/SentryStore.java b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/persistent/SentryStore.java
index 0faaf28..a723a0a 100644
--- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/persistent/SentryStore.java
+++ b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/persistent/SentryStore.java
@@ -330,6 +330,7 @@ public class SentryStore {
     tm.executeTransactionWithRetry(
         new TransactionBlock<Object>() {
           public Object execute(PersistenceManager pm) throws Exception {
+            pm.setDetachAllOnCommit(false); // No need to detach objects
             String trimmedRoleName = trimAndLower(roleName);
             if (getRole(pm, trimmedRoleName) != null) {
               throw new SentryAlreadyExistsException("Role: " + trimmedRoleName);
@@ -351,10 +352,12 @@ public class SentryStore {
       return tm.executeTransaction(
           new TransactionBlock<Long>() {
             public Long execute(PersistenceManager pm) throws Exception {
+              pm.setDetachAllOnCommit(false); // No need to detach objects
               Query query = pm.newQuery();
               query.setClass(tClass);
               query.setResult("count(this)");
-              return (Long) query.execute();
+              Long result = (Long)query.execute();
+              return result;
             }
           });
     } catch (Exception e) {
@@ -497,6 +500,7 @@ public class SentryStore {
       tm.executeTransaction(new TransactionBlock<Object>() {
         @Override
         public Object execute(PersistenceManager pm) throws Exception {
+          pm.setDetachAllOnCommit(false); // No need to detach objects
           purgeDeltaChangeTableCore(MSentryPermChange.class, pm, 1);
           LOGGER.info("MSentryPermChange table has been purged.");
           purgeDeltaChangeTableCore(MSentryPathChange.class, pm, 1);
@@ -519,10 +523,10 @@ public class SentryStore {
    */
   void alterSentryRoleGrantPrivilege(final String grantorPrincipal,
       final String roleName, final TSentryPrivilege privilege) throws Exception {
-
     tm.executeTransactionWithRetry(
       new TransactionBlock<Object>() {
         public Object execute(PersistenceManager pm) throws Exception {
+          pm.setDetachAllOnCommit(false); // No need to detach objects
           String trimmedRoleName = trimAndLower(roleName);
           // first do grant check
           grantOptionCheck(pm, grantorPrincipal, privilege);
@@ -573,6 +577,7 @@ public class SentryStore {
 
     execute(new DeltaTransactionBlock(update), new TransactionBlock<Object>() {
       public Object execute(PersistenceManager pm) throws Exception {
+        pm.setDetachAllOnCommit(false); // No need to detach objects
         String trimmedRoleName = trimAndLower(roleName);
         // first do grant check
         grantOptionCheck(pm, grantorPrincipal, privilege);
@@ -682,6 +687,7 @@ public class SentryStore {
     tm.executeTransactionWithRetry(
       new TransactionBlock<Object>() {
         public Object execute(PersistenceManager pm) throws Exception {
+          pm.setDetachAllOnCommit(false); // No need to detach objects
           String trimmedRoleName = safeTrimLower(roleName);
           // first do revoke check
           grantOptionCheck(pm, grantorPrincipal, tPrivilege);
@@ -720,11 +726,12 @@ public class SentryStore {
    * @throws Exception
    *
    */
-  void alterSentryRoleRevokePrivilege(final String grantorPrincipal,
-      final String roleName, final TSentryPrivilege tPrivilege,
-      final Update update) throws Exception {
+  private void alterSentryRoleRevokePrivilege(final String grantorPrincipal,
+                                              final String roleName, final TSentryPrivilege tPrivilege,
+                                              final Update update) throws Exception {
     execute(new DeltaTransactionBlock(update), new TransactionBlock<Object>() {
       public Object execute(PersistenceManager pm) throws Exception {
+        pm.setDetachAllOnCommit(false); // No need to detach objects
         String trimmedRoleName = safeTrimLower(roleName);
         // first do revoke check
         grantOptionCheck(pm, grantorPrincipal, tPrivilege);
@@ -1040,6 +1047,7 @@ public class SentryStore {
     tm.executeTransactionWithRetry(
         new TransactionBlock<Object>() {
           public Object execute(PersistenceManager pm) throws Exception {
+            pm.setDetachAllOnCommit(false); // No need to detach objects
             dropSentryRoleCore(pm, roleName);
             return null;
           }
@@ -1059,6 +1067,7 @@ public class SentryStore {
 
     execute(new DeltaTransactionBlock(update), new TransactionBlock<Object>() {
       public Object execute(PersistenceManager pm) throws Exception {
+        pm.setDetachAllOnCommit(false); // No need to detach objects
         dropSentryRoleCore(pm, roleName);
         return null;
       }
@@ -1113,6 +1122,7 @@ public class SentryStore {
     tm.executeTransactionWithRetry(
         new TransactionBlock<Object>() {
           public Object execute(PersistenceManager pm) throws Exception {
+            pm.setDetachAllOnCommit(false); // No need to detach objects
             alterSentryRoleAddGroupsCore(pm, roleName, groupNames);
             return null;
           }
@@ -1135,6 +1145,7 @@ public class SentryStore {
 
     execute(new DeltaTransactionBlock(update), new TransactionBlock<Object>() {
       public Object execute(PersistenceManager pm) throws Exception {
+        pm.setDetachAllOnCommit(false); // No need to detach objects
         alterSentryRoleAddGroupsCore(pm, roleName, groupNames);
         return null;
       }
@@ -1180,6 +1191,7 @@ public class SentryStore {
     tm.executeTransactionWithRetry(
         new TransactionBlock<Object>() {
           public Object execute(PersistenceManager pm) throws Exception {
+            pm.setDetachAllOnCommit(false); // No need to detach objects
             String trimmedRoleName = trimAndLower(roleName);
             MSentryRole role = getRole(pm, trimmedRoleName);
             if (role == null) {
@@ -1217,6 +1229,7 @@ public class SentryStore {
           throws Exception {
     execute(new DeltaTransactionBlock(update), new TransactionBlock<Object>() {
       public Object execute(PersistenceManager pm) throws Exception {
+        pm.setDetachAllOnCommit(false); // No need to detach objects
         String trimmedRoleName = trimAndLower(roleName);
         MSentryRole role = getRole(pm, trimmedRoleName);
         if (role == null) {
@@ -1312,6 +1325,7 @@ public class SentryStore {
     return tm.executeTransaction(
       new TransactionBlock<Boolean>() {
         public Boolean execute(PersistenceManager pm) throws Exception {
+          pm.setDetachAllOnCommit(false); // No need to detach objects
           Query query = pm.newQuery(MSentryPrivilege.class);
           QueryParamBuilder paramBuilder = QueryParamBuilder.addRolesFilter(query,null, roleNames);
           paramBuilder.add(SERVER_NAME, serverName);
@@ -1553,13 +1567,14 @@ public class SentryStore {
   }
 
   public Set<String> getRoleNamesForGroups(final Set<String> groups) throws Exception {
-    if (groups == null || groups.isEmpty()) {
+    if ((groups == null) || groups.isEmpty()) {
       return ImmutableSet.of();
     }
 
     return tm.executeTransaction(
         new TransactionBlock<Set<String>>() {
           public Set<String>execute(PersistenceManager pm) throws Exception {
+            pm.setDetachAllOnCommit(false); // No need to detach objects
             return getRoleNamesForGroupsCore(pm, groups);
           }
         });
@@ -1853,6 +1868,7 @@ public class SentryStore {
     tm.executeTransactionWithRetry(
         new TransactionBlock<Object>() {
           public Object execute(PersistenceManager pm) throws Exception {
+            pm.setDetachAllOnCommit(false); // No need to detach objects
 
             // Drop the give privilege for all possible actions from all roles.
             TSentryPrivilege tPrivilege = toSentryPrivilege(tAuthorizable);
@@ -1888,6 +1904,7 @@ public class SentryStore {
 
     execute(new DeltaTransactionBlock(update), new TransactionBlock<Object>() {
       public Object execute(PersistenceManager pm) throws Exception {
+        pm.setDetachAllOnCommit(false); // No need to detach objects
 
         // Drop the give privilege for all possible actions from all roles.
         TSentryPrivilege tPrivilege = toSentryPrivilege(tAuthorizable);
@@ -1923,6 +1940,7 @@ public class SentryStore {
     tm.executeTransactionWithRetry(
         new TransactionBlock<Object>() {
           public Object execute(PersistenceManager pm) throws Exception {
+            pm.setDetachAllOnCommit(false); // No need to detach objects
 
             // Drop the give privilege for all possible actions from all roles.
             TSentryPrivilege tPrivilege = toSentryPrivilege(oldTAuthorizable);
@@ -1965,6 +1983,7 @@ public class SentryStore {
 
     execute(new DeltaTransactionBlock(update), new TransactionBlock<Object>() {
       public Object execute(PersistenceManager pm) throws Exception {
+        pm.setDetachAllOnCommit(false); // No need to detach objects
 
         // Drop the give privilege for all possible actions from all roles.
         TSentryPrivilege tPrivilege = toSentryPrivilege(oldTAuthorizable);
@@ -2416,6 +2435,7 @@ public class SentryStore {
       final Update update) throws Exception {
     execute(new DeltaTransactionBlock(update), new TransactionBlock<Object>() {
       public Object execute(PersistenceManager pm) throws Exception {
+        pm.setDetachAllOnCommit(false); // No need to detach objects
         addAuthzPathsMappingCore(pm, authzObj, paths);
         return null;
       }
@@ -2748,6 +2768,7 @@ public class SentryStore {
     return tm.executeTransaction(
         new TransactionBlock<Set<String>>() {
           public Set<String> execute(PersistenceManager pm) throws Exception {
+            pm.setDetachAllOnCommit(false); // No need to detach objects
             return getAllRoleNames(pm);
           }
         });
@@ -3072,7 +3093,6 @@ public class SentryStore {
       throws Exception {
     return tm.executeTransaction(new TransactionBlock<List<MSentryPathChange>>() {
       public List<MSentryPathChange> execute(PersistenceManager pm) throws Exception {
-        pm.setDetachAllOnCommit(false); // No need to detach objects
         List<MSentryPathChange> pathChanges =
             getMSentryChangesCore(pm, MSentryPathChange.class, changeID);
         long curChangeID = getLastProcessedChangeIDCore(pm, MSentryPathChange.class);
@@ -3106,7 +3126,6 @@ public class SentryStore {
     return tm.executeTransaction(
     new TransactionBlock<List<MSentryPermChange>>() {
       public List<MSentryPermChange> execute(PersistenceManager pm) throws Exception {
-        pm.setDetachAllOnCommit(false); // No need to detach objects
         List<MSentryPermChange> permChanges =
             getMSentryChangesCore(pm, MSentryPermChange.class, changeID);
         long curChangeID = getLastProcessedChangeIDCore(pm, MSentryPermChange.class);