Skip to content

[2.4.240] SHUTDOWN COMPACT failure #4286

Closed

Description

@ctabin

Hello,

In the version 2.4.240, we hit the following exception with a SHUTDOWN COMPACT command:

        at <my_class>
        at org.codehaus.mojo.exec.ExecJavaMojo.doMain(ExecJavaMojo.java:371)
        at org.codehaus.mojo.exec.ExecJavaMojo.doExec(ExecJavaMojo.java:360)
        at org.codehaus.mojo.exec.ExecJavaMojo.lambda$execute$0(ExecJavaMojo.java:280)
        at java.base/java.lang.Thread.run(Thread.java:1583)
Caused by: org.h2.jdbc.JdbcSQLNonTransientException: General error: "java.util.concurrent.CompletionException: org.h2.mvstore.MVStoreException: java.lang.AssertionError [2.4.240/3]"; SQL statement:
SHUTDOWN COMPACT [50000-240]
        at org.h2.message.DbException.getJdbcSQLException(DbException.java:566)
        at org.h2.message.DbException.getJdbcSQLException(DbException.java:489)
        at org.h2.message.DbException.get(DbException.java:212)
        at org.h2.message.DbException.convert(DbException.java:407)
        at org.h2.command.Command.executeUpdate(Command.java:318)
        at org.h2.command.Command.executeUpdate(Command.java:250)
        at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:262)
        at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:231)
        at my.H2DatabaseManager.importH2Statements(H2DatabaseManager.java:379)
        ... 8 more
Caused by: java.util.concurrent.CompletionException: org.h2.mvstore.MVStoreException: java.lang.AssertionError [2.4.240/3]
        at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:315)
        at java.base/java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:320)
        at java.base/java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1807)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
        ... 1 more
Caused by: org.h2.mvstore.MVStoreException: java.lang.AssertionError [2.4.240/3]
        at org.h2.mvstore.DataUtils.newMVStoreException(DataUtils.java:996)
        at org.h2.mvstore.FileStore.serializeAndStore(FileStore.java:1446)
        at org.h2.mvstore.FileStore.lambda$storeIt$2(FileStore.java:1381)
        at org.h2.mvstore.FileStore.submitOrRun(FileStore.java:1406)
        at org.h2.mvstore.FileStore.storeIt(FileStore.java:1380)
        at org.h2.mvstore.MVStore.storeNow(MVStore.java:965)
        at org.h2.mvstore.MVStore.store(MVStore.java:930)
        at org.h2.mvstore.MVStore.commit(MVStore.java:900)
        at org.h2.mvstore.MVStore.commit(MVStore.java:892)
        at org.h2.mvstore.MVStore.registerUnsavedMemoryAndCommitIfNeeded(MVStore.java:1372)
        at org.h2.mvstore.MVMap.copy(MVMap.java:1200)
        at org.h2.mvstore.MVMap.copyFrom(MVMap.java:1176)
        at org.h2.mvstore.MVStore.lambda$compact$0(MVStore.java:435)
        at java.base/java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1804)
        ... 3 more
Caused by: java.lang.AssertionError
        at org.h2.mvstore.Page$PageReference.clearPageReference(Page.java:1079)
        at org.h2.mvstore.Page$NonLeaf.releaseSavedPages(Page.java:1388)
        at org.h2.mvstore.FileStore.serializeAndStore(FileStore.java:1441)
        ... 15 more

Following the PR #4273, we set the system property h2.compactThreads to 1 and the error get away, so this is a simple workaround. If we enforce it to any other value than 1 (tested with 2 and 4), then this error rises.

Note that we are importing an H2 dump from a previous version with RUNSCRIPT and the latter works without any error. Also if we just call SHUTDOWN instead of SHUTDOWN COMPACT, this works also fine, so it seems to be a multithread issue.

Thanks for the work and best regards.

Activity

  1. naive924 commented on Sep 25, 2025

    @naive924
    Contributor

    Hi, I requested PR #4273 (parallel COMPACT) and I’m happy to help with repro.
    On my side (16 cores / latest master branch, daily SHUTDOWN COMPACT, assertions enabled) I can’t reproduce the failure.

    Would it be possible to share the RUNSCRIPT-based dataset ? If not, any of the following would still help a lot:

    • A minimal RUNSCRIPT script (DDL/INSERT excerpt is fine)
    • Settings/flags: -Dh2.compactThreads, RETENTION_TIME, MAX_COMPACT_TIME, etc.
    • Exact steps (e.g., RUNSCRIPT → immediately SHUTDOWN COMPACT)
    • Full stack trace

    If needed, I can receive it privately. I’ll run it under the same conditions and assist with pinpointing the cause. Thanks!

  2. andreitokar commented on Sep 27, 2025

    @andreitokar
    Contributor

    I can reproduce it pretty consistently, but it seems that it's just a failing assertion, which just became faulty indeed, because of a parallel execution. Unfortunately in my prior testing i ran this with -da to measure performance.
    Assertion need to be removed, and it should be fine otherwise.

  3. naive924 commented on Sep 27, 2025

    @naive924
    Contributor

    Understood.
    When I run with the JVM option -ea (-enableassertions) and execute org.h2.tools.Shell, I can also reproduce the issue in my environment. Normally I don’t add -ea, so no AssertionError occurs.

    ■ Not reproducible
    java -cp h2.jar org.h2.tools.Shell -url "...."
    
    
    ■ Reproducible
    java -ea -cp h2.jar org.h2.tools.Shell -url "...."
    
  4. katzyn commented on Sep 27, 2025

    @katzyn
    Contributor

    Assertions can be enabled or disabled on individual packages, so you can enable them for your application and disable them for org.h2 package as a temporary workaround.

  5. ctabin commented on Sep 27, 2025

    @ctabin
    ContributorAuthor

    @naive924 Hi, I can confirm we also use -ea during our tests causing the assertion failure.

  6. naive924 commented on Sep 29, 2025

    @naive924
    Contributor

    @andreitokar
    Thank you for your response to #4288.

    As I progressed with my investigation, I came to the conclusion that simply removing assert page.isSaved() || !page.isComplete(); is the most reasonable fix.

    • With parallel SHUTDOWN COMPACT (parallel MVMap.copy), each worker updates the global MVStore by calling store.registerUnsavedMemoryAndCommitIfNeeded(...) after finishing a copy.
    • That can trigger background save/cleanup in another thread, so clearPageReference() may run on a page that is complete but not yet saved (!isSaved() && isComplete()). This is a benign transient state, but the assertion aborts the process.
    • Conversely, commenting out registerUnsavedMemoryAndCommitIfNeeded(...) and relying only on the final target.commit() in MVStore.compact disables incremental flushing and leads to OOM on large databases.
  7. DarkAtra commented on Aug 29, 2026

    @DarkAtra

    @andreitokar, @naive924 i just ran into this exact issue when i tried to fix nitrite/nitrite-java#1284. it seems like the fix from #4288 is not yet released. The last release dates back to Sep 23, 2025. Is there any plan to release a new version of mvstore in the near future that includes this bugfix? Disabling assertions sounds like a short-term workaround, not like something people should have to use for years.

  8. added a commit that references this issue on Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions