After upgrading to 1.4.191 the database becomes corrupted

121 views
Skip to first unread message

Henry De Lange

unread,
Mar 8, 2016, 11:32:29 PM3/8/16
to H2 Database
Hi

In short:
After upgrading to v1.4.191 (from v1.4.187) when I insert/update a row into a specific table and then close the database, it will be corrupted when I then try to reopen it.

More background:
I have an application that has been using H2 for many years now (in embedded mode).
Until recently it was running on H2 v1.4.187 and I was albe to insert/update/select/etc. without problems.

I now want to release the next version of my application and wanted to include the latest version of H2 (v1.4.191).
Initially all seemed fine. The application opened normally and I was able to read all the data.

However, the database (consistently) breaks when I perform the following actions:
1) Edit (update or insert) a record into a specific table (only the one table gives this problem).
2) Exit the application.
3) When I try to re-open the application the database is corrupted and can't be opened.

I've tried to use the Recover tool (described on the H2 website), but it didn't restore all of my data and the RunScript step encountered some errors (unique index violations).

Fortunately I frequently make backups using the BACKUP TO command. I then tried to use the latest backup which was created a few days ago.
This file also gave the same problem. I tried a bunch of older backups and continued to encounter the problem all the way back to the start of 2015, but upgrading from databases earlier than that seemed to work fine.

Luckily I also created backups using the SCRIPT TO command. In the end I was able to restore my data from this SQL script file. (I created a clean database using the web client and then ran the script.sql file using SCRIPT FROM. The script ran without problems and it seems like all my data was restored.)

I'm now very concerned that the other users of my software will also run into this problem when they try to upgrade their databases using the latest H2 library.

While trying to figure out what went wrong with my data I discovered that the problem only happens when using the v1.4.191 release, but the v1.4.187 works fine... (I only tested with 191 and 187.)

QUESTION:
Is this a known problem in newer versions of H2?
How likely is this problem to be fixed "soon-ish" in the next release? 
I'm trying to decide whether will it be best for me to rather roll back and stick with the older v1.4.187 version for the time being...


MORE INFO:
Please let me know if there is any information I can provide to help solve this problem.
Below are some of the stacktraces I'm seeing in my application.

In my code:
----- SQLException -----
  SQL State:  HY000
  Error Code: 50000
  Message:    General error: "java.lang.ArrayIndexOutOfBoundsException: 2048" [50000-191]
org.h2.jdbc.JdbcSQLException: General error: "java.lang.ArrayIndexOutOfBoundsException: 2048" [50000-191]
 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:301)
 at org.h2.engine.Database.<init>(Database.java:264)
 at org.h2.engine.Engine.openSession(Engine.java:65)
 at org.h2.engine.Engine.openSession(Engine.java:175)
 at org.h2.engine.Engine.createSessionAndValidate(Engine.java:153)
 at org.h2.engine.Engine.createSession(Engine.java:136)
 at org.h2.engine.Engine.createSession(Engine.java:28)
 at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:349)
 at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:107)
 at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:91)
 at org.h2.Driver.connect(Driver.java:72)
 at java.sql.DriverManager.getConnection(DriverManager.java:664)
 at java.sql.DriverManager.getConnection(DriverManager.java:208)
...
Caused by: java.lang.ArrayIndexOutOfBoundsException: 2048
 at org.h2.store.Data.writeVarLong(Data.java:1276)
 at org.h2.store.Data.writeValue(Data.java:536)
 at org.h2.index.PageBtreeIndex.writeRow(PageBtreeIndex.java:393)
 at org.h2.index.PageBtreeNode.writeData(PageBtreeNode.java:453)
 at org.h2.index.PageBtreeNode.write(PageBtreeNode.java:426)
 at org.h2.store.PageStore.writeBack(PageStore.java:1046)
 at org.h2.store.PageStore.writeBack(PageStore.java:418)
 at org.h2.store.PageStore.recover(PageStore.java:1436)
 at org.h2.store.PageStore.openExisting(PageStore.java:367)
 at org.h2.store.PageStore.open(PageStore.java:288)
 at org.h2.engine.Database.getPageStore(Database.java:2474)
 at org.h2.engine.Database.open(Database.java:692)
 at org.h2.engine.Database.openDatabase(Database.java:270)
 ... 31 more


From the trace file:
2016-03-08 22:49:50 database: close
java.lang.ArrayIndexOutOfBoundsException: 2048
 at org.h2.store.Data.writeVarLong(Data.java:1276)
 at org.h2.store.Data.writeValue(Data.java:536)
 at org.h2.index.PageBtreeIndex.writeRow(PageBtreeIndex.java:393)
 at org.h2.index.PageBtreeNode.writeData(PageBtreeNode.java:453)
 at org.h2.index.PageBtreeNode.write(PageBtreeNode.java:426)
 at org.h2.store.PageStore.writeBack(PageStore.java:1046)
 at org.h2.store.PageStore.writeBack(PageStore.java:418)
 at org.h2.store.PageStore.checkpoint(PageStore.java:436)
 at org.h2.engine.Database.closeOpenFilesAndUnlock(Database.java:1353)
 at org.h2.engine.Database.close(Database.java:1286)
 at org.h2.engine.Database.removeSession(Database.java:1170)
 at org.h2.engine.Session.close(Session.java:815)
 at org.h2.jdbc.JdbcConnection.close(JdbcConnection.java:383)


The table which is causing the problem has indexes for bigint, timestamp and varchar.

I really hope that this problem can be resolved, because I'm very concerned about the impact this might have on the databases of my users (most of which will not have the expertise to fix/restore their databases on their own) should this problem happen to them as well.

Thanks
Henry

Noel Grandin

unread,
Mar 9, 2016, 1:19:08 PM3/9/16
to h2-da...@googlegroups.com
What does your H2 DB URL look like?

Henry De Lange

unread,
Mar 10, 2016, 1:41:49 AM3/10/16
to H2 Database
I create the connection like this:

String connectionURL = "jdbc:h2:" + getAbsolutePath() + ";AUTOCOMMIT=ON;IGNORECASE=TRUE;QUERY_CACHE_SIZE=30";
Class.forName("org.h2.Driver").newInstance();
Properties props = new Properties();
props.setProperty("USER", "xxx");
props.setProperty("PASSWORD", "xxx");
conn = DriverManager.getConnection(connectionURL, props);

Noel Grandin

unread,
Mar 10, 2016, 2:37:30 AM3/10/16
to h2-da...@googlegroups.com
Nothing problematic there, except that your query cache size is rather
small - make sure you are closing your PreparedStatements if you do
that.
> --
> You received this message because you are subscribed to the Google Groups
> "H2 Database" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to h2-database...@googlegroups.com.
> To post to this group, send email to h2-da...@googlegroups.com.
> Visit this group at https://groups.google.com/group/h2-database.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages