AnsweredAssumed Answered

CMIS: DataIntegrityViolationException

Question asked by jack0077 on Jul 24, 2015
Hi,

I have following problem:

<blockquote>
Caused by: org.springframework.dao.DataIntegrityViolationException: Detected stale node entry: NodeVersionKey [nodeId=175860260, version=4] (now [NodeVersionKey [nodeId=175860260, version=5
]])
        at org.alfresco.repo.domain.node.AbstractNodeDAOImpl$AspectsCallbackDAO.findByKey(AbstractNodeDAOImpl.java:2795)
        at org.alfresco.repo.domain.node.AbstractNodeDAOImpl$AspectsCallbackDAO.findByKey(AbstractNodeDAOImpl.java:2770)
        at org.alfresco.repo.cache.lookup.EntityLookupCache.getByKey(EntityLookupCache.java:321)
        at org.alfresco.repo.domain.node.AbstractNodeDAOImpl.getNodeAspectsCached(AbstractNodeDAOImpl.java:2734)
        at org.alfresco.repo.domain.node.AbstractNodeDAOImpl.getNodeAspects(AbstractNodeDAOImpl.java:2560)
        at org.alfresco.repo.node.db.DbNodeServiceImpl.getAspects(DbNodeServiceImpl.java:1013)
        at sun.reflect.GeneratedMethodAccessor648.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
        at org.alfresco.repo.tenant.MultiTNodeServiceInterceptor.invoke(MultiTNodeServiceInterceptor.java:105)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
        at $Proxy322.getAspects(Unknown Source)
        at org.alfresco.repo.security.permissions.impl.PermissionServiceImpl.hasPermission(PermissionServiceImpl.java:528)
        at org.alfresco.repo.security.permissions.impl.PermissionServiceImpl.hasPermission(PermissionServiceImpl.java:1042)
        at sun.reflect.GeneratedMethodAccessor650.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
        at $Proxy344.hasPermission(Unknown Source)
        at org.alfresco.repo.security.permissions.impl.acegi.ACLEntryVoter.vote(ACLEntryVoter.java:510)
        at net.sf.acegisecurity.vote.AffirmativeBased.decide(AffirmativeBased.java:69)
        at net.sf.acegisecurity.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:398)
        at net.sf.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:77)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:46)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:161)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.alfresco.repo.transaction.RetryingTransactionInterceptor$1.execute(RetryingTransactionInterceptor.java:79)
        at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:401)
        at org.alfresco.repo.transaction.RetryingTransactionInterceptor.invoke(RetryingTransactionInterceptor.java:69)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
        at $Proxy322.getProperties(Unknown Source)
        at org.alfresco.repo.template.TemplateNode.getProperties(TemplateNode.java:263)
        … 81 more
</blockquote>

I look to the source code <cite>org.alfresco.repo.domain.node.AbstractNodeDAOImpl</cite> at lines (decompiled code):

private class AspectsCallbackDAO extends EntityLookupCallbackDAOAdaptor<NodeVersionKey, Set<QName>, Serializable> {
// …
public Pair<NodeVersionKey, Set<QName>> findByKey(NodeVersionKey nodeVersionKey) {
            Long nodeId = nodeVersionKey.getNodeId();
            Set nodeIds = Collections.singleton(nodeId);
            Map nodeAspectQNameIdsByVersionKey = AbstractNodeDAOImpl.this.selectNodeAspects(nodeIds);
            Set nodeAspectQNames = (Set)nodeAspectQNameIdsByVersionKey.get(nodeVersionKey);
            if(nodeAspectQNames == null) {
                if(nodeAspectQNameIdsByVersionKey.size() != 0) {
                    AbstractNodeDAOImpl.this.invalidateNodeCaches(nodeId);
                    throw new DataIntegrityViolationException("Detected stale node entry: " + nodeVersionKey + " (now " + nodeAspectQNameIdsByVersionKey.keySet() + ")");
                }

                nodeAspectQNames = Collections.emptySet();
            }

            return new Pair(nodeVersionKey, Collections.unmodifiableSet(nodeAspectQNames));
        }


As I understand, this exception occurs when nodeVersionKey object is not inside nodeAspectQNameIdsByVersionKey map - obtain from database.
I think this may occur when nodeVersionKey has version field different then version obtain from database (in call selectNodeAspects(nodeIds)) - because I don't believe that nodeVersionKey could have different nodeId field.
Is it true?
Maybe something change alf_node table direct in database?

Please tell me, why it is possible, that this DataIntegrityViolationException can be thrown? What exactly it means?
And how Alfresco developer predicted such situation and write those 'if else' condition with exception throwing.
And the most important - how to prevent this exception?

Please help me.


Outcomes