Uploaded image for project: 'Confluence Data Center'
  1. Confluence Data Center
  2. CONFSERVER-57823

"Purge All" space trash fails with "org.hibernate.StaleStateException" due to Confluence's handling of CustomContentEntity

      Problem summary

      Due to an issue with Confluence's handling of CustomContentEntity within the ContentPropertyService API, using the "Purge All" option in the Space Trash can fail with a org.hibernate.StaleStateException. This can affect spaces which contains a custom entity created by ContentPropertyService. An example is the Numbered Headings plugin, which uses this API.

      Environment

      1. Confluence 6.13.0 Server
      2. Numbered Headings 5.2.2 for Server (link) – this is just an example, there may be other plugins impacted by this bug

      Steps to reproduce

      1. Create a page
      2. In Edit mode, press the "Numbered Headings" button in the tool bar (screenshot: press_this.png)
        • Note: Whenever the "Numbered Headings" button is pressed, a row will be inserted in the CONTENT table which looks like this:
           contentid | hibernateversion | contenttype |         title         |      lowertitle       | version |             creator              |      creationdate       |           lastmodifier           |       lastmoddate       | prevver | content_status | pageid  | spaceid |                                       pluginkey                                       | pluginver |
          -----------+------------------+-------------+-----------------------+-----------------------+---------+----------------------------------+-------------------------+----------------------------------+-------------------------+----------------+---------+----------------+---------+---------+----------------+----------+-----------+---------------------------------------------------------------------------------------+-----------+
             1409026 |                2 | CUSTOM      | nl_avisi_nh           | nl_avisi_nh           |       1 | 2c94b0bb681b718701681b71f8510000 | 2019-01-17 18:05:04.472 | 2c94b0bb681b718701681b71f8510000 | 2019-01-17 18:05:04.472 |         | current        | 1409025 |  491521 | com.atlassian.confluence.plugins.confluence-content-property-storage:content-property | 6.13.0    |
          
      3. Save the page (the page content doesn't matter)
      4. Delete the page
      5. Go to the space trash, and try to "Purge All".

      Expected behavior

      The space trash is purged without issue

      Actual behavior

      Stacktrace will be reproduced in the UI and in the logs. Snippet below, and Full stacktrace here: full_stacktrace.txt).

      2019-01-17 18:05:46,086 ERROR [http-nio-8090-exec-10] [core.persistence.hibernate.HibernateObjectDao] unIndex Unable to index object: [com.atlassian.confluence.plugins.confluence-content-property-storage:content-property] custom: nl_avisi_nh v.1 (1409026) -- Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1; nested exception is org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
       -- space: 491521 | url: /pages/doemptytrash.action | traceId: ccc8b7a19e645d3c | userName: admin | referer: http://confluence.example.com/pages/emptytrash.action?key=FOO | action: doemptytrash
      org.springframework.orm.hibernate5.HibernateOptimisticLockingFailureException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1; nested exception is org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
      	at org.springframework.orm.hibernate5.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:283)
      	at org.springframework.orm.hibernate5.HibernateTemplate.doExecute(HibernateTemplate.java:368)
      	at org.springframework.orm.hibernate5.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:328)
      	at com.atlassian.confluence.core.persistence.hibernate.HibernateObjectDao.findNamedQueryStringParams(HibernateObjectDao.java:524)
      	at com.atlassian.confluence.core.persistence.hibernate.HibernateObjectDao.findNamedQueryStringParam(HibernateObjectDao.java:400)
      	at com.atlassian.confluence.pages.persistence.dao.hibernate.AbstractHibernateAttachmentDao.getLatestVersionsOfAttachments(AbstractHibernateAttachmentDao.java:118)
      	at com.atlassian.confluence.pages.attachments.CachingAttachmentDao.getLatestVersionsOfAttachments(CachingAttachmentDao.java:131)
      	at com.atlassian.confluence.pages.DefaultAttachmentManager.getLatestVersionsOfAttachments(DefaultAttachmentManager.java:280)
      	at com.atlassian.confluence.pages.DelegatorAttachmentManager.getLatestVersionsOfAttachments(DelegatorAttachmentManager.java:65)
      	at com.atlassian.confluence.pages.CachingAttachmentManager.getLatestVersionsOfAttachments(CachingAttachmentManager.java:57)
      ...
      

      Workaround

      As a workaround, purge the offending page(s) individually from the space trash, which will then allow the "Purge All" option to work again.

      Numbered Headings

      In the case of Numbered Headings specifically, you can use this query to identify spaces/pages that may be affected:

      SELECT s.spacekey, 
             c.contentid, 
             c.title, 
             c.contenttype, 
             c.content_status 
      FROM   content c 
      JOIN   spaces s 
      ON     c.spaceid = s.spaceid 
      WHERE  c.contentid IN 
             ( 
                    SELECT pageid 
                    FROM   content 
                    WHERE  contenttype = 'CUSTOM' 
                    AND    title = 'nl_avisi_nh' 
                    AND    content_status = 'deleted');
      

      Comala Workflows

      In the case of Comala Workflows specifically, you can use this query to identify spaces/pages that may be affected:

      select * FROM CONTENT where CONTENTTYPE = 'CUSTOM' and LOWERTITLE = 'comalaworkflows' and CONTENT_STATUS = 'deleted';
      

      and then to manually delete the above pages, we need to first delete out the child dependent pages before we can delete the above pages using these steps:

      1. Shutdown Confluence
      2. Backup the Confluence database
      3. Run these manual SQL to delete the affected pages (and their child pages)
        delete from CONTENTPROPERTIES where CONTENTID in (select CONTENTID FROM CONTENT where CONTENTTYPE = 'CUSTOM' and LOWERTITLE = 'comalaworkflows' and CONTENT_STATUS = 'deleted');
        
        delete from BODYCONTENT where CONTENTID in (select CONTENTID FROM CONTENT where CONTENTTYPE = 'CUSTOM' and LOWERTITLE = 'comalaworkflows' and CONTENT_STATUS = 'deleted');
        
        delete from CONTENTPROPERTIES where CONTENTID in (select CONTENTID from CONTENT where PREVVER in (select CONTENTID FROM CONTENT where CONTENTTYPE = 'CUSTOM' and LOWERTITLE = 'comalaworkflows' and CONTENT_STATUS = 'deleted'));
        
        delete from BODYCONTENT where CONTENTID in (select CONTENTID from CONTENT where PREVVER in (select CONTENTID FROM CONTENT where CONTENTTYPE = 'CUSTOM' and LOWERTITLE = 'comalaworkflows' and CONTENT_STATUS = 'deleted'));
        
        delete from CONTENT where CONTENTID in (select CONTENTID from CONTENT where PREVVER in (select CONTENTID FROM CONTENT where CONTENTTYPE = 'CUSTOM' and LOWERTITLE = 'comalaworkflows' and CONTENT_STATUS = 'deleted'));
        
        delete from CONTENT where CONTENTID in (select CONTENTID FROM CONTENT where CONTENTTYPE = 'CUSTOM' and LOWERTITLE = 'comalaworkflows' and CONTENT_STATUS = 'deleted');
        
      4. Startup Confluence
        • Navigate to Confluence Administration » General Configuration » Content Indexing
          • Rebuild the indexes to realign the Lucene index files from disk with the manual DB changes we made above
      5. Navigate to any Space and attempt to purge out the Trash and it should succeed

        1. full_stacktrace.txt
          45 kB
        2. press_this.png
          press_this.png
          81 kB

            [CONFSERVER-57823] "Purge All" space trash fails with "org.hibernate.StaleStateException" due to Confluence's handling of CustomContentEntity

            This does not work for 7.14.0 Data Center.
             

            Iro Karavasili added a comment - This does not work for 7.14.0 Data Center.  

            This does NOT work for 7.14.1 Server. Is there a fix to be expected for this version as well?

            Michael Scholze added a comment - This does NOT work for 7.14.1 Server. Is there a fix to be expected for this version as well?

            A fix for this issue is available to Server and Data Center customers in Confluence 7.4.9
            Upgrade now or check out the Release Notes to see what other issues are resolved.

            Jiri Hronik added a comment - A fix for this issue is available to Server and Data Center customers in Confluence 7.4.9 Upgrade now or check out the Release Notes to see what other issues are resolved.

            Affected version 

            • 7.8.1

            Akshay Bhandakkar added a comment - Affected version  7.8.1

            Rick Carini added a comment - - edited

            I see that you have backported this into LTS 6.13.21, but was this also ported into the other LTS release branch, 7.4.x ?

            I am not finding it in any of those release notes...

            Oh, my bad. I see that it is scheduled for 7.4.9, but the release is not yet available.

            Thanks!
            Rick
             

            Rick Carini added a comment - - edited I see that you have backported this into LTS 6.13.21, but was this also ported into the other LTS release branch, 7.4.x ? I am not finding it in any of those release notes... Oh, my bad. I see that it is scheduled for 7.4.9, but the release is not yet available. Thanks! Rick  

            A fix for this issue is available to Server and Data Center customers in Confluence 6.13.21
            Upgrade now or check out the Release Notes to see what other issues are resolved.

            Jiri Hronik added a comment - A fix for this issue is available to Server and Data Center customers in Confluence 6.13.21 Upgrade now or check out the Release Notes to see what other issues are resolved.

            David Pressley added a comment - - edited

            FYI: Don't forget to add the semi-colon to the third statement, or you may get a foreign key constraint violation

            David Pressley added a comment - - edited FYI: Don't forget to add the semi-colon to the third statement, or you may get a foreign key constraint violation

            Thanks everyone, for your patience with this bug and for the interest in this being backported to an LTS release. We are currently reviewing this issue as a candidate for backporting to the 7.4 LTS release line. If no issues are reported from customers on 7.11+ we will go ahead with the backport.

            Regards,
            Niraj Bhawnani
            Engineering Manager - Confluence Data Center
            Atlassian

            Niraj Bhawnani added a comment - Thanks everyone, for your patience with this bug and for the interest in this being backported to an LTS release. We are currently reviewing this issue as a candidate for backporting to the 7.4 LTS release line. If no issues are reported from customers on 7.11+ we will go ahead with the backport. Regards, Niraj Bhawnani Engineering Manager - Confluence Data Center Atlassian

            +1 on this being backported to LTS releases.

            Rick Carini added a comment - +1 on this being backported to LTS releases.

            Peter-I added a comment -

            @jwhitehead, is this fix going to be backported to CONF 7.4 LTS?

            Peter-I added a comment - @jwhitehead, is this fix going to be backported to CONF 7.4 LTS?

            A fix for this issue is available to Server and Data Center customers in Confluence 7.11.0
            Upgrade now or check out the Release Notes to see what other issues are resolved.

            James Whitehead added a comment - A fix for this issue is available to Server and Data Center customers in Confluence 7.11.0 Upgrade now or check out the Release Notes to see what other issues are resolved.

            Peter-I added a comment -

            Same issue with CONF 7.4.1 - can't purge trash if you have deleted pages with comala workflows. 

            Peter-I added a comment - Same issue with CONF 7.4.1 - can't purge trash if you have deleted pages with comala workflows. 

            We are nearing September - can we get a status update? Trashed pages also seem to appear in CQL queries, so they mess up statistics. 

            Michael Scholze added a comment - We are nearing September - can we get a status update? Trashed pages also seem to appear in CQL queries, so they mess up statistics. 

            We are also impacted by this in 6.13.7 Confluence. I have faced this in 2-3 spaces in my instance. Please appreciate the help and fix.

            ViswanathanR added a comment - We are also impacted by this in 6.13.7 Confluence. I have faced this in 2-3 spaces in my instance. Please appreciate the help and fix.

            Thomas CHARON added a comment - - edited

            We have Comala workflow set by default on many of our customer confluence spaces. That mean we are not able to add or remove a worklfow because it is mandatory on those spaces. Then anytime a user is deleting a page and would like to use the "purge all", He can't.

            If the execution on the database side was a one time job it could be an acceptable workaround. But sadly in this case it should be done every month with all the possibility of error we could get trough.

            Please provide a fix to this issue.

            Thomas CHARON added a comment - - edited We have Comala workflow set by default on many of our customer confluence spaces. That mean we are not able to add or remove a worklfow because it is mandatory on those spaces. Then anytime a user is deleting a page and would like to use the "purge all", He can't. If the execution on the database side was a one time job it could be an acceptable workaround. But sadly in this case it should be done every month with all the possibility of error we could get trough. Please provide a fix to this issue.

            I'm following this issue as it has become a real issue for our use of Confluence.  We use plug-ins extensively to implement our use of Confluence for technical documentation production.  We have an ever-growing trash of pages with large attachments that cannot be deleted with Purge All.  Deleting them individually is too labor-intensive, and bringing down Confluence periodically to deal with this issue through administration seems overly burdensome.

            Please raise the priority of this issue as the current level of "Minor" does not accurately reflect the operational impact of this problem.

            Joni Velasco added a comment - I'm following this issue as it has become a real issue for our use of Confluence.  We use plug-ins extensively to implement our use of Confluence for technical documentation production.  We have an ever-growing trash of pages with large attachments that cannot be deleted with Purge All.  Deleting them individually is too labor-intensive, and bringing down Confluence periodically to deal with this issue through administration seems overly burdensome. Please raise the priority of this issue as the current level of "Minor" does not accurately reflect the operational impact of this problem.

            The issue is present with most of our spaces as we intensively take advantage of the involved plugins. The workaround is not really relevant and this issue compromises a really basic and important Confluence feature. It becomes difficult to recommend scaling-up operations with Confluence if this kind of issue remains open. Please consider resolving.

            Thanks.

            Arnaud BUTZBACH added a comment - The issue is present with most of our spaces as we intensively take advantage of the involved plugins. The workaround is not really relevant and this issue compromises a really basic and important Confluence feature. It becomes difficult to recommend scaling-up operations with Confluence if this kind of issue remains open. Please consider resolving. Thanks.

            We are reaching hundreds of pages in trash now and the error expanded to more than 1 space already. Some CQL Scripts also seem to count trash pages to statistics which is undesireable (aside from issues such as stale attachments and hard drive space use). Workaround manual deletion is not really feasible, especially when the frontend-assertion doesn't really give us a Page ID to work with to identify the "culprits". 

            Could we get a more permanent solution anytime soon?

            Michael Scholze added a comment - We are reaching hundreds of pages in trash now and the error expanded to more than 1 space already. Some CQL Scripts also seem to count trash pages to statistics which is undesireable (aside from issues such as stale attachments and hard drive space use). Workaround manual deletion is not really feasible, especially when the frontend-assertion doesn't really give us a Page ID to work with to identify the "culprits".  Could we get a more permanent solution anytime soon?

            Could you please provide statement 4 and 5 also for mysql working.

            "You can't specify target table 'CONTENT' for update in FROM clause"

            Thanks in advance.

            Christian

            Christian König added a comment - Could you please provide statement 4 and 5 also for mysql working. "You can't specify target table 'CONTENT' for update in FROM clause" Thanks in advance. Christian

            凯 王 added a comment -

            kindly take an action to resolve as early as possible.

            凯 王 added a comment - kindly take an action to resolve as early as possible.

            Yogananth added a comment -

            Dear Team,

            Since this is given as an workaround so, everytime end users having a dependency with confluence admin user. They are not happy with this solution to resolve the issues.

            Expecting a fix to resolve from the end user end itself (i.e., space admin level) it should be completed.

            So, kindly take an action to resolve as early as possible.

            Regards,

            Yoga.

            Yogananth added a comment - Dear Team, Since this is given as an workaround so, everytime end users having a dependency with confluence admin user. They are not happy with this solution to resolve the issues. Expecting a fix to resolve from the end user end itself (i.e., space admin level) it should be completed. So, kindly take an action to resolve as early as possible. Regards, Yoga.

              qpham@atlassian.com Quan Pham
              rchang Robert Chang
              Affected customers:
              81 This affects my team
              Watchers:
              85 Start watching this issue

                Created:
                Updated:
                Resolved: