I think it's safe to say that your H2 DB file is corrupted since the NullPointerException is within internal H2 code while trying to just open the database file, not anything GoCD is specifically trying to do.
Generic error
General error: "java.lang.NullPointerException" [50000-168]
^^ H2 DB code version 1.3.168 doesn't like the database structure it finds.
Root problem:INFO | jvm 1 | 2022/01/17 22:18:35 | Caused by: java.lang.NullPointerException
INFO | jvm 1 | 2022/01/17 22:18:35 | at org.h2.store.Data.getValueLen(Data.java:880)
INFO | jvm 1 | 2022/01/17 22:18:35 | at org.h2.store.Data.getValueLen(Data.java:866)
INFO | jvm 1 | 2022/01/17 22:18:35 | at org.h2.index.PageBtreeIndex.getRowSize(PageBtreeIndex.java:396)
INFO | jvm 1 | 2022/01/17 22:18:35 | at org.h2.index.PageBtreeLeaf.addRow(PageBtreeLeaf.java:106)
INFO | jvm 1 | 2022/01/17 22:18:35 | at org.h2.index.PageBtreeLeaf.addRowTry(PageBtreeLeaf.java:100)
INFO | jvm 1 | 2022/01/17 22:18:35 | at org.h2.index.PageBtreeNode.addRowTry(PageBtreeNode.java:200)
INFO | jvm 1 | 2022/01/17 22:18:35 | at org.h2.index.PageBtreeNode.addRowTry(PageBtreeNode.java:200)
INFO | jvm 1 | 2022/01/17 22:18:35 | at org.h2.index.PageBtreeIndex.addRow(PageBtreeIndex.java:105)
INFO | jvm 1 | 2022/01/17 22:18:35 | at org.h2.index.PageBtreeIndex.add(PageBtreeIndex.java:96)
INFO | jvm 1 | 2022/01/17 22:18:35 | at org.h2.table.RegularTable.addRow(RegularTable.java:121)
INFO | jvm 1 | 2022/01/17 22:18:35 | ... 125 more
Which happens during
INFO | jvm 1 | 2022/01/17 22:18:35 | at org.h2.table.RegularTable.addRow(RegularTable.java:139)
INFO | jvm 1 | 2022/01/17 22:18:35 | at org.h2.store.PageStore.redo(PageStore.java:1531)
INFO | jvm 1 | 2022/01/17 22:18:35 | at org.h2.store.PageLog.recover(PageLog.java:319)
INFO | jvm 1 | 2022/01/17 22:18:35 | at org.h2.store.PageStore.recover(PageStore.java:1365)
INFO | jvm 1 | 2022/01/17 22:18:35 | at org.h2.store.PageStore.openExisting(PageStore.java:361)
INFO | jvm 1 | 2022/01/17 22:18:35 | at org.h2.store.PageStore.open(PageStore.java:285)
INFO | jvm 1 | 2022/01/17 22:18:35 | at org.h2.engine.Database.getPageStore(Database.java:2118)
INFO | jvm 1 | 2022/01/17 22:18:35 | at org.h2.engine.Database.open(Database.java:577)
INFO | jvm 1 | 2022/01/17 22:18:35 | at org.h2.engine.Database.openDatabase(Database.java:222)
INFO | jvm 1 | 2022/01/17 22:18:35 | at org.h2.engine.Database.<init>(Database.java:217)
INFO | jvm 1 | 2022/01/17 22:18:35 | at org.h2.engine.Engine.openSession(Engine.java:56)
INFO | jvm 1 | 2022/01/17 22:18:35 | at org.h2.engine.Engine.openSession(Engine.java:159)
INFO | jvm 1 | 2022/01/17 22:18:35 | at org.h2.engine.Engine.createSessionAndValidate(Engine.java:138)
INFO | jvm 1 | 2022/01/17 22:18:35 | at org.h2.engine.Engine.createSession(Engine.java:121)
INFO | jvm 1 | 2022/01/17 22:18:35 | at org.h2.engine.Engine.createSession(Engine.java:28)
So it cannot even open the database file and make sense of the file structure. The question is whether it can be recovered. Just to be clear, you don't have either manual pre-migration backups, GoCD automated backups (via /go/admin/backup) or perhaps file-system level backups of the disk (/var/lib/go-server/db) on which the H2 store was saved?
Were there errors from the migration tool during the migration? Do you have the logs for that? Hopefully not.
An Idea
Anyway, the version of H2 that is with GoCD 20.4.0 is 1.3.168. The version that the DB migrator tool uses is 1.4.200.
My theory is that the migrator tool touched your source database as part of ensuring it was in a state ready for migration (e.g applying any missing DB migrations). It has likely done so using the new version of H2 in some way which the old version does not like. It's also possible that concurrent writes to the file from two different H2 versions completely corrupted it.
If there were no errors on the migration tool itself when you ran it, you
might have a valid 1.4.200 DB file that cannot be read by the version in GoCD server 20.4.0 (which is 1.3.168). If that theory is true, the key question will be can a 1.3.x jar recover
or understand a database that has been migrated to 1.4.x? I suspect not, hence your errors at startup.
On the assumption/hope that the file
is in a valid state for 1.4.200 you can try something similar to
Aravind's instructions to get back to a state 20.4.0 can understand.
To modify for your situation
- Backup the "corrupt" file as is :-)
- Confirm the theory - is the DB valid from the perspective of H2 "1.4.200"? If you try to export it to SQL with 1.4.200 jar as per Aravind's instructions, that should help you know.
- If that export to script doesn't work, you might need to try the recover tool. (
org.h2.tools.Recover) - If export, or recover+export works, you now have a whole lot of SQL. You can then import to a new database using the 1.3.168 jar. i.e adapt the instructions to
$ ls
backup.sql cruise.mv.db h2-1.4.200.jar h2-1.3.168.jar
# Import from backup.sql into a new DB file: new.cruise.mv.db
$ java -cp h2-1.3.168.jar org.h2.tools.RunScript -url jdbc:h2:./new.cruise -user sa -script backup.sql
- Try that newly created database with GoCD 21.4.0.
Personally, given the different versions of H2 DB with the migrator tool and with GoCD 20.4.0 I think that will maximise your chances of getting a working DB.
Using an old DB or fresh db
To clarify, Aravind's instructions create a fresh DB file, by trying an export-to-sql and import-to-new-file, so would be a "fresh" DB, but not an empty DB, or schema-only DB :-)
I don't really have an opinion on whether using a 2 year old DB is useful for you. Depends which GoCD it was and whether there is still an upgrade path on the DB - but off top of my head there should be. You will be missing records of pipeline/stage/job runs, VSMs, links to artifacts and materials, plugin configuration, agent approvals, user preferences - all that type of stuff. The stuff that would have been reported in the migration dry run which should have a summary in the log. You can
see here what's in the DB (ignores a single later change to drop usage reporting data in 20.6.0)
-Chad