-
-
Notifications
You must be signed in to change notification settings - Fork 95
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
Migrating from 3.x to 4.x: Database file is corrupted #820
Comments
Not sure what causing this issue. You can take a look at the upgrade test code here - nitrite-java/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/NitriteTest.java Line 424 in 072909e
One thing I'll suggest, to use minimal store config, as there are config changes as well in H2 v1 vs v2. I'll caution you against the upgrade functionality, all kind of v1 db might not be upgradable to v2. H2 itself does not support the upgradation (no idea why). Here, it is a mere effort to try upgrade on common use cases only. |
Thanks for the suggestions. I'll give them a try. Failing those, if the Nitrite upgrade logic is for common use-cases only, what do you suggest for people with (apparently) non-common use-cases? |
In un-common use cases, unfortunately, there is no upgrade path yet. User have to destroy the old database and re-create the new one. That's what H2 is also suggesting. |
Looks like H2 recommends export/import using their export/import tools. I'll take a look at that... |
Also, the "Database file is corrupted" message is bogus: the open/upgrade code creates a new (empty) database file whose name is the old db file appended with "_new" (e.g., "my-nitrite.db" -> "my-nitrite.db_new"). The open/upgrade starts to populate this new file, but if the upgrade/open fails (as it did in my case), the "_new" file is not deleted and on subsequent attempts to open "my-nitrite.db", it tries to open the existing "my-nitrite.db_new" file and fails (with the exception/stacktraces I shared -- "Database is corrupted"). The "_new" file should really be deleted on failure (or the code should check for an existing "_new" file and, if it exists, create a new uniquely named file)... If I delete the "_new" file and try to start my app, here is the actual error that's happening during the open/upgrade (I abbreviated a long list of numbers following "-84, -19, 0,..."):
This is very similar to the errors I remember seeing the last time I tried to migrate from 3.x to 4.x. Any thoughts? |
You are right. The unfinished new file needs to be cleaned up. Is it possible for you to share the data file? I could not reproduce it at my end. |
Necessary clean up code has been added to 4.2.0-SNAPSHOT. |
Trying again to migrate from 3.x to 4.x. I've checked out the 4.x branch and did the refactoring in my codebase to use 4.x. When I initially tried to start my app, I saw the following exception when it tried to open the database:
Caused by: java.lang.ClassNotFoundException: org.h2.mvstore.MVMap$MapBuilder
After adding the H2 dependency (2.1.214), I now see the following error when trying to open the database:
It seems that H2 is complaining that since the database is v1, H2 v2 cannot open it? My understanding is that 4.x has explicit code to upgrade a database when opening it (presumably to support migration from 3.x to 4.x), do you know why this isn't working? Or how I can fix this or work around it? The same file opens without error under 3.x.
Here is my 4.x code for opening the db:
The text was updated successfully, but these errors were encountered: