Migrating from HSQLDB to any database fails
Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.
Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Problem
The following appears in the atlassian-fisheye-<date>.log
for Oracle migration:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
2012-11-13 15:01:32,595 WARN - An error occurred from hibernate. Failing silently
org.hibernate.HibernateException: Hibernate has been shutdown
at com.cenqua.crucible.hibernate.HibernateUtil.currentState(HibernateUtil.java:143)
at com.cenqua.crucible.hibernate.HibernateUtil.currentSession(HibernateUtil.java:134)
at com.atlassian.fecru.user.UserDAOImpl.session(UserDAOImpl.java:26)
...
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410)
at org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:451)
2012-11-13 15:12:38,740 ERROR - Database migration failed: com.cenqua.crucible.hibernate.CruDBException: Problem with constraints script /data/fisheye/sql/ORACLE/schema/constraints_79.sql
com.cenqua.crucible.hibernate.CruDBException: Problem with constraints script /data/fisheye/sql/ORACLE/schema/constraints_79.sql
at com.cenqua.crucible.hibernate.DefaultDBControl.addConstraints(DefaultDBControl.java:317)
at com.cenqua.crucible.hibernate.OracleDBControl.addConstraints(OracleDBControl.java:122)
at com.atlassian.crucible.migration.item.DBImporter.importData(DBImporter.java:159)
...
Caused by: com.cenqua.crucible.hibernate.CruDBException: SQL script error on line 45: "alter table cru_fr_detail add constraint FK4F2200B487D2F44 foreign key (cru_revision_id) references cru_revision;"
(ORA-02298: cannot validate (CRUCIBLE.FK4F2200B487D2F44) - parent keys not found
), please contact http://www.atlassian.com/support/
at com.cenqua.crucible.hibernate.DefaultDBControl.executeScript(DefaultDBControl.java:483)
at com.cenqua.crucible.hibernate.DefaultDBControl.executeScript(DefaultDBControl.java:414)
at com.cenqua.crucible.hibernate.DefaultDBControl.addConstraints(DefaultDBControl.java:311)
... 11 more
Caused by: java.sql.SQLException: ORA-02298: cannot validate (CRUCIBLE.FK4F2200B487D2F44) - parent keys not found
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:440)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396)
MySQL:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2014-04-17 17:30:44,531 ERROR [ThreadPool3 ] fisheye DBEditHelper-doGet - Database migration failed: com.cenqua.crucible.hibernate.CruDBException: Problem with constraints script /opt/fecru-3.2.1/sql/MYSQL/schema/constraints_87.sql
com.cenqua.crucible.hibernate.CruDBException: Problem with constraints script /opt/fecru-3.2.1/sql/MYSQL/schema/constraints_87.sql
at com.cenqua.crucible.hibernate.DefaultDBControl.addConstraints(DefaultDBControl.java:411)
at com.atlassian.crucible.migration.item.DBImporter.importData(DBImporter.java:145)
at com.atlassian.crucible.actions.admin.database.DBEditHelper$ImportRunner.call(DBEditHelper.java:90)
at com.atlassian.crucible.actions.admin.database.DBEditHelper$ImportRunner.call(DBEditHelper.java:72)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:98)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:206)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:695)
Caused by: com.cenqua.crucible.hibernate.CruDBException: SQL script error on line 49: "alter table cru_fr_detail add index FK4F2200B487D2F44 (cru_revision_id), add constraint FK4F2200B487D2F44 foreign key (cru_revision_id) references cru_revision (cru_revision_id);"
(Cannot add or update a child row: a foreign key constraint fails (`fisheye`.<result 2 when explaining filename '#sql-1d80_4bc8'>, CONSTRAINT `FK4F2200B487D2F44` FOREIGN KEY (`cru_revision_id`) REFERENCES `cru_revision` (`cru_revision_id`))), please contact http://www.atlassian.com/support/
at com.cenqua.crucible.hibernate.DefaultDBControl.executeScript(DefaultDBControl.java:593)
at com.cenqua.crucible.hibernate.DefaultDBControl.executeScript(DefaultDBControl.java:524)
at com.cenqua.crucible.hibernate.DefaultDBControl.addConstraints(DefaultDBControl.java:405)
... 10 more
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`fisheye`.<result 2 when explaining filename '#sql-1d80_4bc8'>, CONSTRAINT `FK4F2200B487D2F44` FOREIGN KEY (`cru_revision_id`) REFERENCES `cru_revision` (`cru_revision_id`))
Cause
There is a database integrity issue in your HSQLDB.
Resolution
Backup your Fisheye/Crucible for rollback purposes
Stop Fisheye/Crucible
Copy the following into a file called ForeignKeyCleanupScript.py
ForeignKeyCleanupScript.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
#! /usr/bin/env python """ Parse the hsql tables_x and constraints_x files to create an sql script that drops entries that conflict with foreign key constraints. Useful for ensuring database consistency when experiencing problems with a hsqldb instance, or before migrating to mysql or postgresql. Optional parameters: version --- db version to run against, defaults to 58 (fe/cru 2.1) sqlDir --- the directory containing tables_x and constraints_x, defaults to ../etc/dist/sql/HSQL/schema/ """ import sys import re tablesExp = re.compile(r"create table (.+) \(.+, primary key \(([^,]+?)\).*\);", re.IGNORECASE) constraintsExp = re.compile(r"alter table (.+) add constraint .* foreign key \((.+)\) references (.+);", re.IGNORECASE) def getPrimaryKeys(tablesFile): primaryKeys = {} line = tablesFile.readline() while line: m = tablesExp.match(line) if m != None: primaryKeys[m.group(1)] = m.group(2) # print m.group(1) + " => " + m.group(2) #else: # print "No match: " + line line = tablesFile.readline() return primaryKeys def writeSql(primaryKeys, constraintsFile, outputFile, outputFileName): outputFile.write( '--- WARNING --- THIS SCRIPT MAY DELETE DATA FROM YOUR DATABASE. ENSURE ALL DATA IS BACKED UP BEFORE RUNNING\n' + '--- To apply the patch to a crucible instance:\n' + '--- Go to Administration > Backup and create a backup of the database\n' + '--- Shut down your crucible server completely.\n' + '--- Go to the FISHEYE_HOME/lib directory and run the following command:\n' + '--- java -Xms512m -Xmx512m -jar FISHEYE_HOME/lib/hsqldb-1.8.0.10.jar --inlineRC "URL=jdbc:hsqldb:file:FISHEYE_INST/var/data/crudb/crucible;shutdown=true,USER=sa,PASSWORD=" '+outputFileName+'\n' + '--- Replace FISHEYE_HOME and FISHEYE_INST with the fully qualified locations (see Administration > Sys Info/Support > System Info, if you are not sure of the fully qualified paths).\n' + '--- You may need to replace "hsqldb-1.8.0.10.jar" with the current version in your lib directory\n' ) line = constraintsFile.readline() while line: m = constraintsExp.match(line) if m!= None: sTable1 = m.group(1) sColumn1 = m.group(2) sTable2 = m.group(3) sColumn2 = primaryKeys[sTable2] if sColumn2 != None: outputFile.write('delete from '+ sTable1 +' where ' + sColumn1 + ' not in (select '+ sColumn2 +' from '+sTable2+');\n') else: print "Can't find primary key for table " + sTable2 + ', unable to create statement for column ' + sColumn1 + ' of table ' + sTable1 #else: # print "No match: " + line line = constraintsFile.readline() outputFile.write('commit;') def doit(version, sqlDir): tablesFile = open(sqlDir + "tables_"+version+".sql", 'r') constraintsFile = open(sqlDir + 'constraints_'+version+'.sql', 'r') outputFileName = 'foreign_key_cleanup_'+version+'.sql' outputFile = open(outputFileName, 'w') primaryKeys = getPrimaryKeys(tablesFile) writeSql(primaryKeys, constraintsFile, outputFile, outputFileName) if __name__ == '__main__': version = '58' sqlDir = '../etc/dist/sql/HSQL/schema/' if len(sys.argv) > 1: version = sys.argv[1] if len(sys.argv) > 2: sqlDir = sys.argv[2] doit(version, sqlDir)
Use create ForeignKeyCleanupScript.py to generate a script for your Fisheye/Crucible:
1
python createForeignKeyCleanupScript.py VERSION FISHEYE_HOME/sql/HSQL/schema/
This script is compatible with Python version 2.x only.
That will output an sql file containing cleanup scripts for the version of fisheye in your checkout. The
VERSION
is the version number of the db of the customer, but its usually safe to just use the largest number in the files inFISHEYE_HOME
, e.g./sql/HSQL/schema/
tables_67.sql
.Run the following command:
1
java -Xms512m -Xmx1024m -jar FISHEYE_HOME/lib/hsqldb-*.jar --inlineRC "URL=jdbc:hsqldb:file:FISHEYE_INST/var/data/crudb/crucible;shutdown=true,USER=sa,PASSWORD=" foreign_key_cleanup_VERSION.sql
Replace FISHEYE_INST with the fully qualified locations (see
Administration >> Systems Settings >> System Info
, if you are not sure of the fully qualified paths).The script will return a result such as:
1 2
637 rows updated. 196 rows updated.
If the script fails with an out of memory problem, retry again but raise the
-Xmx
value, e.g. from-Xmx1024m
to-Xmx2048m
.Start Fisheye/Crucible
Perform the database migration again
If the script fails with the following message, this is because the CRU_FR_DETAIL contains a reference to the CRU_REVISION table:
Integrity constraint violation FK4F2200B487D2F44 table: CRU_FR_DETAIL
To resolve this, apply the following prior to run the script once again:
Run the query to identify the revisions that will be deleted:
SELECT * FROM cru_revision WHERE cru_path NOT IN (SELECT cru_path_id FROM cru_stored_path)
retrieve the ids from the query above and delete them with the following statement: DELETE FROM cru_fr_detail WHERE cru_revision_id IN (<comma separated list of ids>)
Was this helpful?