Skip to content

Fix for "double mark" error at database opening (#2752)#4065

Merged
andreitokar merged 4 commits intoh2database:masterfrom
vreuland:master
Jun 21, 2024
Merged

Fix for "double mark" error at database opening (#2752)#4065
andreitokar merged 4 commits intoh2database:masterfrom
vreuland:master

Conversation

@vreuland
Copy link
Contributor

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 dropUnusedChunks will 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 dropUnusedChunk never 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

@vreuland
Copy link
Contributor Author

I see the new test is failing in the CI due to an OOM…
I can flag the test as « big » (do nothing if config.big!=true) as I have seen in other tests. But when are those tests run and by what/who?

@andreitokar andreitokar merged commit 575302d into h2database:master Jun 21, 2024
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants