Fix for "double mark" error at database opening (#2752)#4065
Merged
andreitokar merged 4 commits intoh2database:masterfrom Jun 21, 2024
Merged
Fix for "double mark" error at database opening (#2752)#4065andreitokar merged 4 commits intoh2database:masterfrom
andreitokar merged 4 commits intoh2database:masterfrom
Conversation
Contributor
Author
|
I see the new test is failing in the CI due to an OOM… |
bryceatmoderne
pushed a commit
to openrewrite/h2database
that referenced
this pull request
Jul 19, 2024
Fix for "double mark" error at database opening (h2database#2752) (cherry picked from commit 575302d)
bryceatmoderne
added a commit
to openrewrite/h2database
that referenced
this pull request
Jul 19, 2024
Fix for "double mark" error at database opening (h2database#2752) (cherry picked from commit 575302d) Co-authored-by: Andrei Tokar <andreitokar@users.noreply.github.com>
bryceatmoderne
pushed a commit
to openrewrite/h2database
that referenced
this pull request
Jul 19, 2024
Fix for "double mark" error at database opening (h2database#2752) (cherry picked from commit 575302d)
bryceatmoderne
added a commit
to openrewrite/h2database
that referenced
this pull request
Jul 19, 2024
* Merge pull request h2database#4065 from vreuland/master Fix for "double mark" error at database opening (h2database#2752) (cherry picked from commit 575302d) * Add github actions workflows * ci-maven.yml implementation * Add gradle build scripts * Add missing h2/build.gradle.kts * Disable license tests * Override resource source sets --------- Co-authored-by: Andrei Tokar <andreitokar@users.noreply.github.com>
bryceatmoderne
added a commit
to openrewrite/h2database
that referenced
this pull request
Jul 19, 2024
* Merge pull request h2database#4065 from vreuland/master Fix for "double mark" error at database opening (h2database#2752) (cherry picked from commit 575302d) * Match h2database version tag format in publish.yml --------- Co-authored-by: Andrei Tokar <andreitokar@users.noreply.github.com>
bryceatmoderne
added a commit
to openrewrite/h2database
that referenced
this pull request
Jul 22, 2024
…#6) * Merge pull request h2database#4065 from vreuland/master Fix for "double mark" error at database opening (h2database#2752) (cherry picked from commit 575302d) * Override artifactId in publish task to align with upstream h2database --------- Co-authored-by: Andrei Tokar <andreitokar@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Following my comment on issue #2752 (#2752 (comment)), I have looked further into the issue.
I was able to reproduce it in a small test with dummy data. Please find in this PR the test added in the current H2 test suite.
I have also included a proposal for the fix.
My understanding is that the issue lies in the code that is opening the database.
In the test scenario, the first opening of the database is made on a fresh backup of the database. As this is an online backup, the database file is not assumed "clean" by
RandomAccessStore#readStoreHeader. In that case, the code is trying to find the last written chunk and goes over all the chunks listed in its layout map. It also "modifies" the non-live chunks to avoid marking their bytes as non-free, thinking these chunks would be anyway removed later (from the layout map, cf.FileStore#dropUnusedChunks).That works in most of the cases but if the chunks are still within the retention time (default is 45 sec.), there is an issue: The
dropUnusedChunkswill not remove those chunks from the layout map at the first write(s). And that first write(s) can actually reuse the space of those dead chunks (as their space are marked as free in the FreeBitSet...).Then the datase is closed (and the "clean" flag is set in the header). We eventually end up with a "Double Mark" error when reopening the database as we still have in the layout map the reference to the dead chunks (as
dropUnusedChunknever run on those) and the last chunks using the same space in the file.The fix is pretty simple: I don't see why we would want to tamper/modify the dead chunk references when opening the database from an "non-clean" file if the references are valid. So I leave the dead chunk references untouched if they are valid.
Any comment or feedback is welcome.
Best regards,
Vincent