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

Upgrade to 5.7 breaks if there are invalid entries on attachments table

    XMLWordPrintable

Details

    Description

      In Confluence 5.7 we migrated the information from the ATTACHMENTS table to the CONTENT table. However if there are entries on the ATTACHMENTS where the pageid is not on the CONTENT table the upgrade will fail with the following error:

      2015-03-27 13:30:53,281 ERROR [localhost-startStop-1] [atlassian.confluence.upgrade.UpgradeLauncherServletContextListener] contextInitialized Upgrade failed, application will not start: Upgrade task com.atlassian.confluence.upgrade.upgradetask.attachmentceo.AttachmentToCeoConversionUpgradeTask@2b2e536b failed during the SCHEMA_UPGRADE phase due to: PreparedStatementCallback; SQL [insert into CONTENT(CONTENTID, CONTENTTYPE, TITLE, PAGEID, CREATOR, CREATIONDATE, LASTMODIFIER, LASTMODDATE, VERSIONCOMMENT, VERSION, PREVVER) select ATTACHMENTID, ? as CONTENTTYPE, TITLE, PAGEID, CREATOR, CREATIONDATE, LASTMODIFIER, LASTMODDATE, ATTACHMENT_COMMENT, ATTVERSION, PREVVER from ATTACHMENTS where ATTACHMENTID >= ? and ATTACHMENTID <= ?]; Cannot add or update a child row: a foreign key constraint fails (`confluence`.`CONTENT`, CONSTRAINT `FK6382C0598C38FBEA` FOREIGN KEY (`PAGEID`) REFERENCES `CONTENT` (`CONTENTID`)); nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`confluence`.`CONTENT`, CONSTRAINT `FK6382C0598C38FBEA` FOREIGN KEY (`PAGEID`) REFERENCES `CONTENT` (`CONTENTID`))
      com.atlassian.confluence.upgrade.UpgradeException: Upgrade task com.atlassian.confluence.upgrade.upgradetask.attachmentceo.AttachmentToCeoConversionUpgradeTask@2b2e536b failed during the SCHEMA_UPGRADE phase due to: PreparedStatementCallback; SQL [insert into CONTENT(CONTENTID, CONTENTTYPE, TITLE, PAGEID, CREATOR, CREATIONDATE, LASTMODIFIER, LASTMODDATE, VERSIONCOMMENT, VERSION, PREVVER) select ATTACHMENTID, ? as CONTENTTYPE, TITLE, PAGEID, CREATOR, CREATIONDATE, LASTMODIFIER, LASTMODDATE, ATTACHMENT_COMMENT, ATTVERSION, PREVVER from ATTACHMENTS where ATTACHMENTID >= ? and ATTACHMENTID <= ?]; Cannot add or update a child row: a foreign key constraint fails (`confluence`.`CONTENT`, CONSTRAINT `FK6382C0598C38FBEA` FOREIGN KEY (`PAGEID`) REFERENCES `CONTENT` (`CONTENTID`)); nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstra
      

      Since those entries are not making any references to a existing PAGEID in CONTENT our upgrade should ignore those instead of returning that error.

      Environment

      At current moment we only had reports from customer using mysql instances hitting on this.

      Work Around:

      1. Restore your Confluence instance to a state prior the upgrade.
      2. Once you confirm you Confluence is working fine, shut down Confluence.
      3. Run below queries in order against Confluence database:
        DELETE FROM IMAGEDETAILS WHERE ATTACHMENTID IN (select ATTACHMENTID FROM ATTACHMENTS WHERE PAGEID NOT IN (SELECT CONTENTID FROM CONTENT));
        

        And:

        DELETE FROM ATTACHMENTS where PAGEID NOT IN (SELECT CONTENTID FROM CONTENT);
        

        This will remove any entries that are not bound to any page.

      4. Try upgrading Confluence.

      Attachments

        Activity

          People

            nbhawnani Niraj Bhawnani
            dluvison Deividi Luvison (Inactive)
            Votes:
            3 Vote for this issue
            Watchers:
            8 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: