-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Fixes file corruption upon page rewrite. #2225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
When a Leaf is rewritten, it has no key, hence the rewrite will fail with an ArrayIndexOutOfBoundsException.
|
How can that happen, surely an empty page should not be written at all? |
|
Hi @grandinj, I agree this looks really strange... but it happen nevertheless "randomly" but quite often. Once I get this error on my database, then the DB is corrupted and it is impossible to connect to it afterwards. The pattern is the following: I load an old H2 database (created with a version 1.4.196) and I apply a bunch of migration statements (the connection gets closed). Then, when I want to connect to the database again, it sometimes fails with the given error above. And sometimes it even fails later, this is unclear when. However, with this fix, there is no more crash at all and it works flawlessly. I would say that this is relative to the NULL/NOT NULL with column with default values. In the previous version (1.4.199), when a default value was specified on a column, the column was described as not nullable, and that behaviour seems to changed in 1.4.200 (which is why I wanted to update). Up to 1.4.199, I had no problem and nothing changed on our side since then (the impacted H2 database is used for migration tests). |
|
@ctabin, Thank you for your contribution. I wonder, if you can replicate this problem after following recommended migration path of exporting database into a script and run it in a newly created 1.4.200 database? |
|
@andreitokar Thanks for your reply. Actually, the dump was created by using version 1.4.196 and was then exported to a script. Hence, we are now loading only a H2 SQL script with the version 1.4.200, applying some migration statements and that's it. Previously, I added a guard in the Page constructor to prevent arrays of Key of length 0, but that triggered a lot of exceptions and basically h2 was unable to work 😅 I'll see if I can create a test case, even if I think that will be quite hard because of the randomness of the bug 🤔 |
|
Ok, so it seems like 1.4.200 issue then. |
|
Seems the same pb as we have here orbisgis/geoclimate#188 |
|
@andreitokar You're right, we are using spatial data (with GeoDB 0.9). I tried to do a test case on the default value and NULL/NOT NULL change, but this works fine. I'll try to generate a new one with spatial data. |
|
I think i got it. Was able to replicate empty leaf creation with a simple test. Will post the the fix tonight. |
|
@andreitokar Yep, let me know when I can test it 👍 |
|
@andreitokar I think I have a testcase that throws a similar error: You can just experiment it by running |
|
@andreitokar Just for information: stmt.execute("DROP TABLE IF EXISTS someTable");
stmt.execute("CREATE TABLE someTable("
+ "idpk1 varchar(10) NOT NULL,"
+ "idpk2 varchar(10) NOT NULL,"
+ "label varchar(255),"
+ "status1 varchar(1),"
+ "status2 varchar(1) DEFAULT '2',"
+ "status3 varchar(1) DEFAULT '3' NOT NULL,"
+ "status4 int(11) DEFAULT '0',"
+ "spatialcol geometry NOT NULL,"
+ "PRIMARY KEY (idpk1,idpk2)"
+ ")");
stmt.execute("CREATE SPATIAL INDEX tbl_spatial_idx ON someTable(spatialcol)");If I comment out the last statement about the SPATIAL INDEX creation, the test works fine :) |
|
@andreitokar Thanks for the fix ! This works fine with it. What should we do about this MR ? I agree that it only circumvent the problem, but still avoid a corruption in that case. Also can I suggest to add the test case on the spatial data ? |
|
I think we should merge it, because the corruption is already in the wild. Please, send a license statement as described here to our mailing list |
|
@andreitokar Thanks, that's done ! Can we expect a new release soon with those fixes ? 🙏 |
|
Thank you! H2 is not released too often, but you can build H2 by yourself: |
|
@katzyn Thanks for the merge. Considering this could break existing database, I would suggest to create a release somewhat quickly 😉 Anyway, thanks for your amazing work on this ! |
Fixes the following error: