Repository: sentry Updated Branches: refs/heads/sentry-ha-redesign 04db24b21 -> d8df78279
SENTRY-1770: Avoid more detaches on commit (Alex Kolbasov, reviewed by Vamsee Yarlagadda) Project: http://git-wip-us.apache.org/repos/asf/sentry/repo Commit: http://git-wip-us.apache.org/repos/asf/sentry/commit/d8df7827 Tree: http://git-wip-us.apache.org/repos/asf/sentry/tree/d8df7827 Diff: http://git-wip-us.apache.org/repos/asf/sentry/diff/d8df7827 Branch: refs/heads/sentry-ha-redesign Commit: d8df7827918761e941fc8dc9c2079edecc0633b0 Parents: 04db24b Author: Alexander Kolbasov <[email protected]> Authored: Wed May 17 17:39:55 2017 -0700 Committer: Alexander Kolbasov <[email protected]> Committed: Wed May 17 17:39:55 2017 -0700 ---------------------------------------------------------------------- .../service/persistent/DelegateSentryStore.java | 6 +++ .../db/service/persistent/SentryStore.java | 42 +++++++++++++++----- 2 files changed, 39 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/sentry/blob/d8df7827/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 ebb1916..ff46298 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/d8df7827/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 c458651..29e3686 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 @@ -337,6 +337,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); @@ -358,10 +359,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) { @@ -517,6 +520,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); @@ -539,10 +543,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); @@ -593,6 +597,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); @@ -708,6 +713,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); @@ -746,11 +752,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); @@ -1066,6 +1073,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; } @@ -1085,6 +1093,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; } @@ -1139,6 +1148,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; } @@ -1161,6 +1171,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; } @@ -1199,6 +1210,7 @@ public class SentryStore { tm.executeTransactionWithRetry( new TransactionBlock<Object>() { public Object execute(PersistenceManager pm) throws Exception { + pm.setDetachAllOnCommit(false); // No need to detach objects alterSentryRoleAddUsersCore(pm, roleName, userNames); return null; } @@ -1233,6 +1245,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) { @@ -1269,6 +1282,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) { @@ -1306,6 +1320,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) { @@ -1400,6 +1415,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); @@ -1648,13 +1664,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); } }); @@ -1665,13 +1682,14 @@ public class SentryStore { } public Set<String> getRoleNamesForUsers(final Set<String> users) throws Exception { - if (users == null || users.isEmpty()) { + if ((users == null) || users.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 getRoleNamesForUsersCore(pm,users); } }); @@ -1686,6 +1704,7 @@ public class SentryStore { return tm.executeTransaction( new TransactionBlock<Set<TSentryRole>>() { public Set<TSentryRole> execute(PersistenceManager pm) throws Exception { + pm.setDetachAllOnCommit(false); // No need to detach objects Set<MSentryRole> mSentryRoles = getRolesForUsers(pm, users); // Since {@link MSentryRole#getGroups()} is lazy-loading, // the conversion should be done before transaction is committed. @@ -1753,6 +1772,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 Set<String> activeRoleNames = toTrimedLower(roleSet.getRoles()); Set<String> roleNames = Sets.newHashSet(); @@ -1999,6 +2019,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); @@ -2034,6 +2055,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); @@ -2069,6 +2091,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); @@ -2111,6 +2134,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); @@ -2561,6 +2585,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; } @@ -3025,6 +3050,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 getAllRoleNamesCore(pm); } }); @@ -3658,7 +3684,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); @@ -3692,7 +3717,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);
