Skip to content

Commit

Permalink
Merge pull request #3998 from cgeesink/fix/issue/3907
Browse files Browse the repository at this point in the history
Fix Issue #3907 - MvStoreTool unable to Repair() or Rollback()
  • Loading branch information
katzyn committed Feb 18, 2024
2 parents 33da479 + 9f5839e commit 7791d80
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion h2/src/main/org/h2/mvstore/MVStoreTool.java
Expand Up @@ -642,8 +642,8 @@ public static long rollback(String fileName, long targetVersion, Writer writer)
DataUtils.readFully(file, pos, buffer);
buffer.rewind();
int headerType = buffer.get();
buffer.rewind();
if (headerType == 'H') {
buffer.rewind();
target.write(buffer, pos);
pos += blockSize;
continue;
Expand Down
33 changes: 33 additions & 0 deletions h2/src/test/org/h2/test/store/TestMVStoreTool.java
Expand Up @@ -43,6 +43,7 @@ public static void main(String... a) throws Exception {
public void test() throws Exception {
testCompact();
testDump();
testRollback();
}

private void testCompact() {
Expand Down Expand Up @@ -185,6 +186,38 @@ private void testDump() {
assertEquals("Exactly 2 file headers are expected in the dump", 2, nbFileHeaders);
}

private void testRollback() {
String fileName = getBaseDir() + "/testDump.h4";
FileUtils.createDirectories(getBaseDir());
FileUtils.delete(fileName);
// store with a very small page size, to make sure
// there are many leaf pages
MVStore s = new MVStore.Builder().
pageSplitSize(1000).
fileName(fileName).autoCommitDisabled().open();
s.setRetentionTime(0);
MVMap<Integer, String> map = s.openMap("data");

// Insert some data. Using big strings with "H" and "c" to validate the fix of #3931
int nbEntries = 20_000;
for (int i = 0; i < nbEntries; i++) {
map.put(i, i % 2 == 0 ? BIG_STRING_WITH_C : BIG_STRING_WITH_H);
}
s.commit();
// Let's rewrite the data to trigger some chunk compaction & drop
for (int i = 0; i < nbEntries; i++) {
map.put(i, i % 2 == 0 ? BIG_STRING_WITH_H : BIG_STRING_WITH_C);
}
s.commit();
s.close();
StringWriter dumpWriter = new StringWriter();
try {
MVStoreTool.rollback(fileName, Long.MAX_VALUE, dumpWriter);
} catch (NullPointerException ex ) {
fail("No NullPointerException expected");
}
}

private static int nbOfOccurrences(String str, String pattern) {
return str.split(pattern,-1).length - 1;
}
Expand Down

0 comments on commit 7791d80

Please sign in to comment.