Skip to content

MvStoreTool unable to Repair() or Rollback() [2.1.214] #3907

@cgeesink

Description

@cgeesink

Every try to repair or rollback an Database with the MVStoreTool throws an NullPointerException.

Exception in thread "main" java.lang.NullPointerException: Cannot read field "len" because "newestChunk" is null
at org.h2.mvstore.MVStoreTool.rollback(MVStoreTool.java:676)
...

RootCause is the int headerType = block.get(); in the following Code (h2/src/main/org/h2/mvstore/MVStoreTool.java:637):

public static long rollback(String fileName, long targetVersion, Writer writer)
                 DataUtils.readFully(file, pos, block);
                 block.rewind();
                 int headerType = block.get();
                 if (headerType == 'H') {
                     block.rewind();
                     target.write(block, pos);
                     pos += blockSize;
                     continue;

the block.get() increments the BufferPosition but the following block.rewind() ist just called in the StoreHeader Block, that in the following code:

                Chunk c;
                try {
                    c = Chunk.readChunkHeader(block, pos);
                } catch (MVStoreException e) {
                    pos += blockSize;
                    continue;
                }

The parsing of the chunkHeader always starts with missing the first character hunk:1,block:2,len:1,map:6,max:1c0,next:3,pages:2,root:4000004f8c,time:1fc,version:1

The following diff Block fixes the Problem:

diff --git a/h2/src/main/org/h2/mvstore/MVStoreTool.java b/h2/src/main/org/h2/mvstore/MVStoreTool.java
index d29909994..b3f5fc07d 100644
--- a/h2/src/main/org/h2/mvstore/MVStoreTool.java
+++ b/h2/src/main/org/h2/mvstore/MVStoreTool.java
@@ -635,8 +635,8 @@ public static long rollback(String fileName, long targetVersion, Writer writer)
                 DataUtils.readFully(file, pos, block);
                 block.rewind();
                 int headerType = block.get();
+               block.rewind();
                 if (headerType == 'H') {
-                    block.rewind();
                     target.write(block, pos);
                     pos += blockSize;
                     continue;

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