H2 - General error: "java.lang.NullPointerException" [50000-182]
I have a rather large (> 2.5 GB) h2 database file. Driver version 1.4.182. Everything worked fine, but recently the database stops working with the exception:
Błąd ogólny: "java.lang.NullPointerException" General error: "java.lang.NullPointerException" [50000-182] HY000/50000 (Help) org.h2.jdbc.JdbcSQLException: Błąd ogólny: "java.lang.NullPointerException" General error: "java.lang.NullPointerException" [50000-182] at org.h2.message.DbException.getJdbcSQLException(DbException.java:345) at org.h2.message.DbException.get(DbException.java:168) at org.h2.message.DbException.convert(DbException.java:295) at org.h2.engine.Database.openDatabase(Database.java:297) at org.h2.engine.Database.<init>(Database.java:260) at org.h2.engine.Engine.openSession(Engine.java:60) at org.h2.engine.Engine.openSession(Engine.java:167) at org.h2.engine.Engine.createSessionAndValidate(Engine.java:145) at org.h2.engine.Engine.createSession(Engine.java:128) at org.h2.engine.Engine.createSession(Engine.java:26) at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:347) at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:108) at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:92) at org.h2.Driver.connect(Driver.java:72) at org.h2.server.web.WebServer.getConnection(WebServer.java:750) at org.h2.server.web.WebApp.test(WebApp.java:895) at org.h2.server.web.WebApp.process(WebApp.java:221) at org.h2.server.web.WebApp.processRequest(WebApp.java:170) at org.h2.server.web.WebThread.process(WebThread.java:137) at org.h2.server.web.WebThread.run(WebThread.java:93) at java.lang.Thread.run(Thread.java:722) Caused by: java.lang.NullPointerException at org.h2.mvstore.db.ValueDataType.compare(ValueDataType.java:102) at org.h2.mvstore.MVMap.compare(MVMap.java:741) at org.h2.mvstore.Page.binarySearch(Page.java:388) at org.h2.mvstore.MVMap.put(MVMap.java:179) at org.h2.mvstore.MVMap.put(MVMap.java:133) at org.h2.mvstore.db.TransactionStore.rollbackTo(TransactionStore.java:491) at org.h2.mvstore.db.TransactionStore$Transaction.rollback(TransactionStore.java:785) at org.h2.mvstore.db.MVTableEngine$Store.initTransactions(MVTableEngine.java:223) at org.h2.engine.Database.open(Database.java:736) at org.h2.engine.Database.openDatabase(Database.java:266) ... 17 more The problem occurs in my application and uses the H2 web interface. I tried the solution from a similar question , but I can not lower H2 to 1.3.x, since it cannot read 1.4.x DB files.
My questions are :
How to do it? Is it possible to do this again? I tried to lower H2 to 1.4.177, but that did not help.
Is there a way to recover data in a different format? I could use other DBs (Sqlite, etc.), but I need a way to get this data.
EDIT: updated stacktrace
EDIT 2: Result of using the recovery tool:
$ java -cp h2-1.4.182.jar org.h2.tools.Recover Exception in thread "main" java.lang.IllegalStateException: Unknown tag 50 [1.4.182/6] at org.h2.mvstore.DataUtils.newIllegalStateException(DataUtils.java:762) at org.h2.mvstore.type.ObjectDataType.read(ObjectDataType.java:222) at org.h2.mvstore.db.TransactionStore$ArrayType.read(TransactionStore.java:1792) at org.h2.mvstore.db.TransactionStore$ArrayType.read(TransactionStore.java:1759) at org.h2.mvstore.Page.read(Page.java:843) at org.h2.mvstore.Page.read(Page.java:230) at org.h2.mvstore.MVStore.readPage(MVStore.java:1813) at org.h2.mvstore.MVMap.readPage(MVMap.java:769) at org.h2.mvstore.Page.getChildPage(Page.java:252) at org.h2.mvstore.MVMap.getFirstLast(MVMap.java:351) at org.h2.mvstore.MVMap.firstKey(MVMap.java:218) at org.h2.mvstore.db.TransactionStore.init(TransactionStore.java:169) at org.h2.mvstore.db.TransactionStore.<init>(TransactionStore.java:117) at org.h2.mvstore.db.TransactionStore.<init>(TransactionStore.java:81) at org.h2.tools.Recover.dumpMVStoreFile(Recover.java:593) at org.h2.tools.Recover.process(Recover.java:331) at org.h2.tools.Recover.runTool(Recover.java:192) at org.h2.tools.Recover.main(Recover.java:155) I also noticed that two more files (.txt and .sql) were created, but they do not seem to contain data.
I got the same situation last week with the JIRA database, it took me a few hours to make Google regarding this issue, however there are no answers that can resolve the situation.
I decided to take a look at the source code of H2, and I can restore the entire database with very simple code. Perhaps I do not understand the whole picture of the situation, for example. the root cause, in what condition it happened, etc. However, the reason is that: when you connect to the h2 file, the H2 engine will look in auditLog and roll back incomplete transactions, there is some data that has an unknown type (id is 17), and H2 does not roll back due to an exception during recognition type (id 17).
My code is simple, add h2 lib to your build path, and then just manually connect to the file and clear AuditLog, because I think this is just a log and will not have much influence (someone can fix me). Hope you can also solve your problem.
public static void main(final String[] args) { // open the store (in-memory if fileName is null) final MVStore store = MVStore.open("C:\\temp\\h2db.mv.db"); final MVMap<Object, Object> openMap = store.openMap("undoLog"); openMap.clear(); // close the store (this will persist changes) store.close(); } I had a similar problem:
[HY000][50000] Allgemeiner Fehler: "java.lang.NullPointerException" General error: "java.lang.NullPointerException" [50000-176] java.lang.NullPointerException I tried connecting to IntelliJ to the H2 database file. The H2 driver version was 1.3.176, but the DB file version was 1.3.161. Thus, downgrading the driver to 1.3.161 in IntelliJ completely solved the problem.
Another solution to this problem:
Go to your home folder (~ on Linux).
Move all the files with the name [* .mv.db] to the backup with a different name. For example:
mv xyz.mv.db xyz.mv.db.backupReboot the database.
This seems to eliminate the MVStore metadata used for H2 undo functions and removes the NPE from the MV Store comparison.