h2database / h2database

H2 is an embeddable RDBMS written in Java.
https://h2database.com
Other
4.21k stars 1.2k forks source link

Exception in thread "H2-lob-cleaner" #3766

Open wburzyns opened 1 year ago

wburzyns commented 1 year ago

This just happened while using the current master:

Exception in thread "H2-lob-cleaner": org.h2.mvstore.MVStoreException: java.lang.ArrayIndexOutOfBoundsException: 11910 [2.2.219/3] at org.h2.mvstore.DataUtils.newMVStoreException(DataUtils.java:996) at org.h2.mvstore.MVStore.tryExecuteUnderStoreLock(MVStore.java:942) at org.h2.mvstore.RandomAccessStore.doHousekeeping(RandomAccessStore.java:721) at org.h2.mvstore.FileStore.writeInBackground(FileStore.java:1834) at org.h2.mvstore.FileStore$BackgroundWriterThread.run(FileStore.java:2245) Caused by: java.lang.ArrayIndexOutOfBoundsException: 11910 at org.h2.mvstore.FileStore.rewriteChunks(FileStore.java:1906) at org.h2.mvstore.FileStore.compactRewrite(FileStore.java:1893) at org.h2.mvstore.FileStore.rewriteChunks(FileStore.java:1854) at org.h2.mvstore.RandomAccessStore.lambda$doHousekeeping$4(RandomAccessStore.java:726) at org.h2.mvstore.MVStore.tryExecuteUnderStoreLock(MVStore.java:938) ... 3 more

The crash occured while running "SELECT DATA, DESC FROM MATDB_DATA WHERE GLOBAL_STAMP = ?" . Both DATA and DESC are blobs. Till the moment of the error this query executed 16M times. I've done this massive data dump many times before and never seen seen any problems (till now). The DB reopened without problems, it does not seem to be damaged. Unfortunately I don't think I'll be able to provide you with a testcase.

grandinj commented 1 year ago

So based on that stacktrace, the chunksToC cache is getting out of sync with the chunk.occupancy BitSet field.

@andreitokar any ideas? I can't see what serialisation mechanism is keeping these two things in sync?

Also noting that "occupancy" seems to be a misnomer now, it is no longer (or perhaps never was?) a bitset of "occupied" pages, it is a bitset of "deleted" pages :-)

andreitokar commented 1 year ago

@grandinj There is nothing to keep in-sync, really. Table of Content {toc) is immutable and contains element per page in chunk, and number of pages stored in chunk.pageCount. Somehow toc comes out of the cache shorter than it should.

JohnNiang commented 1 year ago

I had a similar problem when I saved too much data (100) at the same time:

Exception in thread "H2-lob-cleaner" org.h2.mvstore.MVStoreException: Map lobRef(8) is closed. org.h2.mvstore.MVStoreException: java.lang.OutOfMemoryError: Capacity: 35831808 [2.1.214/3] [2.1.214/4]
    at org.h2.mvstore.DataUtils.newMVStoreException(DataUtils.java:1004)
    at org.h2.mvstore.MVMap.beforeWrite(MVMap.java:962)
    at org.h2.mvstore.MVMap.operate(MVMap.java:1757)
    at org.h2.mvstore.MVMap.remove(MVMap.java:518)
    at org.h2.mvstore.db.LobStorageMap.doRemoveLob(LobStorageMap.java:474)
    at org.h2.mvstore.db.LobStorageMap.cleanup(LobStorageMap.java:443)
    at org.h2.mvstore.db.LobStorageMap.lambda$null$0(LobStorageMap.java:122)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: org.h2.mvstore.MVStoreException: java.lang.OutOfMemoryError: Capacity: 35831808 [2.1.214/3]
    at org.h2.mvstore.DataUtils.newMVStoreException(DataUtils.java:1004)
    at org.h2.mvstore.MVStore.serializeAndStore(MVStore.java:1605)
    at org.h2.mvstore.MVStore.lambda$storeNow$4(MVStore.java:1518)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
    at java.base/java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:264)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java)
    ... 3 more
Caused by: java.lang.OutOfMemoryError: Capacity: 35831808
    at org.h2.mvstore.WriteBuffer.grow(WriteBuffer.java:322)
    at org.h2.mvstore.WriteBuffer.ensureCapacity(WriteBuffer.java:302)
    at org.h2.mvstore.WriteBuffer.put(WriteBuffer.java:164)
    at org.h2.mvstore.type.ByteArrayDataType.write(ByteArrayDataType.java:31)
    at org.h2.mvstore.type.ByteArrayDataType.write(ByteArrayDataType.java:17)
    at org.h2.mvstore.type.BasicDataType.write(BasicDataType.java:67)
    at org.h2.mvstore.Page$Leaf.writeValues(Page.java:1609)
    at org.h2.mvstore.Page.write(Page.java:721)
    at org.h2.mvstore.Page$Leaf.writeUnsavedRecursive(Page.java:1618)
    at org.h2.mvstore.Page$NonLeaf.writeChildrenRecursive(Page.java:1344)
    at org.h2.mvstore.Page$NonLeaf.writeUnsavedRecursive(Page.java:1330)
    at org.h2.mvstore.Page$NonLeaf.writeChildrenRecursive(Page.java:1344)
    at org.h2.mvstore.Page$NonLeaf.writeUnsavedRecursive(Page.java:1330)
    at org.h2.mvstore.MVStore.serializeToBuffer(MVStore.java:1669)
    at org.h2.mvstore.MVStore.serializeAndStore(MVStore.java:1598)
    ... 7 more