Fix for ALF-3142: CLONE - patch.updateDmPermissions takes too long to complete

- final improvements and fix progress report

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@22040 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Andrew Hind
2010-08-27 11:35:38 +00:00
parent 7703a41412
commit 0a41dd2c72
6 changed files with 106 additions and 70 deletions

View File

@@ -354,6 +354,13 @@
</isGreaterThan> </isGreaterThan>
</update> </update>
<update id="update_NodePatchAcl" parameterClass="NodeUpdate">
update alf_node set
<isEqual property="updateAclId" compareValue="true" > acl_id = #aclId#</isEqual>
where
id = #id#
</update>
<update id="update_ChildAssocsUniqueName" parameterClass="ChildAssoc"> <update id="update_ChildAssocsUniqueName" parameterClass="ChildAssoc">
update alf_child_assoc set update alf_child_assoc set
child_node_name_crc = #childNodeNameCrc#, child_node_name_crc = #childNodeNameCrc#,

View File

@@ -298,7 +298,7 @@
</select> </select>
<!-- for patch --> <!-- for patch -->
<select id="select_DmNodeCount"> <select id="select_DmNodeCount" resultClass="long">
select select
count(*) count(*)
from from
@@ -306,7 +306,7 @@
</select> </select>
<!-- for patch --> <!-- for patch -->
<select id="select_DmNodeCountWherePermissionsHaveChanged" parameterMap="parameter_IdMap"> <select id="select_DmNodeCountWherePermissionsHaveChanged" parameterMap="parameter_IdMap" resultClass="long">
select select
count(*) count(*)
from from

View File

@@ -1418,6 +1418,17 @@ public abstract class AbstractNodeDAOImpl implements NodeDAO, BatchingDAO
invalidateCachesByNodeId(primaryParentNodeId, null, nodesCache); invalidateCachesByNodeId(primaryParentNodeId, null, nodesCache);
} }
@Override
public void setNodeDefiningAclId(Long nodeId, long aclId)
{
NodeUpdateEntity nodeUpdateEntity = new NodeUpdateEntity();
nodeUpdateEntity.setId(nodeId);
nodeUpdateEntity.setAclId(aclId);
nodeUpdateEntity.setUpdateAclId(true);
updateNodePatchAcl(nodeUpdateEntity);
invalidateCachesByNodeId(null, nodeId, nodesCache);
}
public void deleteNode(Long nodeId) public void deleteNode(Long nodeId)
{ {
Node node = getNodeNotNull(nodeId); Node node = getNodeNotNull(nodeId);
@@ -3161,6 +3172,7 @@ public abstract class AbstractNodeDAOImpl implements NodeDAO, BatchingDAO
protected abstract int updateStoreRoot(StoreEntity store); protected abstract int updateStoreRoot(StoreEntity store);
protected abstract Long insertNode(NodeEntity node); protected abstract Long insertNode(NodeEntity node);
protected abstract int updateNode(NodeUpdateEntity nodeUpdate); protected abstract int updateNode(NodeUpdateEntity nodeUpdate);
protected abstract int updateNodePatchAcl(NodeUpdateEntity nodeUpdate);
protected abstract void updatePrimaryChildrenSharedAclId( protected abstract void updatePrimaryChildrenSharedAclId(
Long primaryParentNodeId, Long primaryParentNodeId,
Long optionalOldSharedAlcIdInAdditionToNull, Long optionalOldSharedAlcIdInAdditionToNull,

View File

@@ -630,4 +630,12 @@ public interface NodeDAO extends NodeBulkLoader
Serializable nodeValue, Serializable nodeValue,
ChildAssocRefQueryCallback resultsCallback); ChildAssocRefQueryCallback resultsCallback);
/**
* Used in ACL upgrade only to set the acl id with mimimal overhead
*
* @param nodeId
* @param id
*/
public void setNodeDefiningAclId(Long nodeId, long id);
} }

View File

@@ -85,6 +85,7 @@ public class NodeDAOImpl extends AbstractNodeDAOImpl
private static final String SELECT_STORE_ROOT_NODE_BY_REF = "alfresco.node.select_StoreRootNodeByRef"; private static final String SELECT_STORE_ROOT_NODE_BY_REF = "alfresco.node.select_StoreRootNodeByRef";
private static final String INSERT_NODE = "alfresco.node.insert_Node"; private static final String INSERT_NODE = "alfresco.node.insert_Node";
private static final String UPDATE_NODE = "alfresco.node.update_Node"; private static final String UPDATE_NODE = "alfresco.node.update_Node";
private static final String UPDATE_NODE_PATCH_ACL = "alfresco.node.update_NodePatchAcl";
private static final String DELETE_NODE_BY_ID = "alfresco.node.delete_NodeById"; private static final String DELETE_NODE_BY_ID = "alfresco.node.delete_NodeById";
private static final String SELECT_NODE_BY_ID = "alfresco.node.select_NodeById"; private static final String SELECT_NODE_BY_ID = "alfresco.node.select_NodeById";
private static final String SELECT_NODE_BY_NODEREF = "alfresco.node.select_NodeByNodeRef"; private static final String SELECT_NODE_BY_NODEREF = "alfresco.node.select_NodeByNodeRef";
@@ -284,6 +285,12 @@ public class NodeDAOImpl extends AbstractNodeDAOImpl
return template.update(UPDATE_NODE, nodeUpdate); return template.update(UPDATE_NODE, nodeUpdate);
} }
@Override
protected int updateNodePatchAcl(NodeUpdateEntity nodeUpdate)
{
return template.update(UPDATE_NODE_PATCH_ACL, nodeUpdate);
}
@Override @Override
protected void updatePrimaryChildrenSharedAclId( protected void updatePrimaryChildrenSharedAclId(
Long primaryParentNodeId, Long primaryParentNodeId,

View File

@@ -133,7 +133,8 @@ public class ADMAccessControlListDAO implements AccessControlListDAO
if (!pair.getSecond().getProtocol().equals(StoreRef.PROTOCOL_AVM)) if (!pair.getSecond().getProtocol().equals(StoreRef.PROTOCOL_AVM))
{ {
CounterSet update; CounterSet update;
update = fixOldDmAcls(nodeDAO.getRootNode(pair.getSecond()).getFirst(), (Long)null, true); Long rootNodeId = nodeDAO.getRootNode(pair.getSecond()).getFirst();
update = fixOldDmAcls(rootNodeId, nodeDAO.getNodeAclId(rootNodeId), (Long)null, true);
result.add(update); result.add(update);
} }
} }
@@ -148,91 +149,92 @@ public class ADMAccessControlListDAO implements AccessControlListDAO
return toReturn; return toReturn;
} }
private CounterSet fixOldDmAcls(Long nodeId, Long inherited, boolean isRoot) private CounterSet fixOldDmAcls(Long nodeId, Long existingNodeAclId, Long inheritedAclId, boolean isRoot)
{
return fixOldDmAclsImpl(nodeId, inherited, isRoot);
}
private CounterSet fixOldDmAclsImpl(Long nodeId, Long inherited, boolean isRoot)
{ {
CounterSet result = new CounterSet(); CounterSet result = new CounterSet();
// Do the children first
Acl existingAcl = null; // If existingNodeAclId is not null and equal to inheritedAclId then we know we have hit a shared ACL we have bulk set
Long aclId = nodeDAO.getNodeAclId(nodeId); // - just carry on in this case - we do not need to get the acl
if (aclId != null)
Long newDefiningAcl = null;
if((existingNodeAclId != null) && (existingNodeAclId == inheritedAclId))
{ {
existingAcl = aclDaoComponent.getAcl(aclId); // nothing to do except move into the children
}
Long toInherit = null;
Long idToInheritFrom = null;
if (existingAcl != null)
{
if (existingAcl.getAclType() == ACLType.OLD)
{
result.increment(ACLType.DEFINING);
SimpleAccessControlListProperties properties = new SimpleAccessControlListProperties(aclDaoComponent.getDefaultProperties());
properties.setInherits(existingAcl.getInherits());
AccessControlList existing = aclDaoComponent.getAccessControlList(existingAcl.getId());
Long actuallyInherited = null;
if (existingAcl.getInherits())
{
if (inherited != null)
{
actuallyInherited = inherited;
}
}
Acl newAcl = aclDaoComponent.createAccessControlList(properties, existing.getEntries(), actuallyInherited);
idToInheritFrom = newAcl.getId();
nodeDAO.setNodeAclId(nodeId, idToInheritFrom);
}
else if (existingAcl.getAclType() == ACLType.SHARED)
{
// nothing to do just cascade into the children - we most likely did a bulk set above.
}
else
{
// Already fixed up
return result;
}
} }
else else
{ {
// Set default ACL on roots with no settings AccessControlList existing = null;
if (isRoot) if (existingNodeAclId != null)
{ {
result.increment(ACLType.DEFINING); existing = aclDaoComponent.getAccessControlList(existingNodeAclId);
}
AccessControlListProperties properties = aclDaoComponent.getDefaultProperties(); if (existing != null)
Acl newAcl = aclDaoComponent.createAccessControlList(properties); {
long id = newAcl.getId(); if (existing.getProperties().getAclType() == ACLType.OLD)
{
result.increment(ACLType.DEFINING);
SimpleAccessControlListProperties properties = new SimpleAccessControlListProperties(aclDaoComponent.getDefaultProperties());
properties.setInherits(existing.getProperties().getInherits());
idToInheritFrom = id; Long actuallyInherited = null;
nodeDAO.setNodeAclId(nodeId, id); if (existing.getProperties().getInherits())
{
if (inheritedAclId != null)
{
actuallyInherited = inheritedAclId;
}
}
Acl newAcl = aclDaoComponent.createAccessControlList(properties, existing.getEntries(), actuallyInherited);
newDefiningAcl = newAcl.getId();
nodeDAO.setNodeDefiningAclId(nodeId, newDefiningAcl);
}
else if (existing.getProperties().getAclType() == ACLType.SHARED)
{
// nothing to do just cascade into the children - we most likely did a bulk set above.
// TODO: Check shared ACL set is correct
}
else
{
// Already fixed up
// TODO: Keep going to check
// Check inheritance is correct
return result;
}
} }
else else
{ {
// Unset - simple inherit // Set default ACL on roots with no settings
nodeDAO.setNodeAclId(nodeId, inherited); if (isRoot)
{
result.increment(ACLType.DEFINING);
AccessControlListProperties properties = aclDaoComponent.getDefaultProperties();
Acl newAcl = aclDaoComponent.createAccessControlList(properties);
newDefiningAcl = newAcl.getId();
nodeDAO.setNodeDefiningAclId(nodeId, newDefiningAcl);
}
else
{
// Unset - simple inherit
nodeDAO.setNodeDefiningAclId(nodeId, inheritedAclId);
}
} }
} }
Long toInherit = null;
List<NodeIdAndAclId> children = nodeDAO.getPrimaryChildrenAcls(nodeId); List<NodeIdAndAclId> children = nodeDAO.getPrimaryChildrenAcls(nodeId);
if (children.size() > 0) if (children.size() > 0)
{ {
// Only make inherited if required // Only make inherited if required
if (toInherit == null) if (newDefiningAcl == null)
{ {
if (idToInheritFrom == null) toInherit = inheritedAclId;
{ }
toInherit = inherited; else
} {
else toInherit = aclDaoComponent.getInheritedAccessControlList(newDefiningAcl);
{
toInherit = aclDaoComponent.getInheritedAccessControlList(idToInheritFrom);
}
} }
} }
@@ -244,7 +246,7 @@ public class ADMAccessControlListDAO implements AccessControlListDAO
for (NodeIdAndAclId child : children) for (NodeIdAndAclId child : children)
{ {
CounterSet update = fixOldDmAcls(child.getId(), toInherit, false); CounterSet update = fixOldDmAcls(child.getId(), child.getAclId(), toInherit, false);
result.add(update); result.add(update);
} }