Hi MVStore developers,
We are experiencing a strange behavior using the
MVStore.compactMoveChunks() method.
In our use scenario we use large MVMaps of multiple million entries. As
these maps are modified, MVStore database file grows to unexpected size. We
found that calling method MVStore.compactMoveChunks() compacts the database
file. The file size problem could be solved this way. However, this
function call corrupts our data in MVStore.
We created and attached a JUnit test to reproduce this behavior.
The test creates a database, writes to it, commits the changes, rollbacks
(no changes), calls compactMoveChunks(), than closes the database.
After reopening the store, data written before is disappeared, test fails.
If line 46 (store.compactMoveChunks();) is removed, test passes.
If line 45 and 46 (store.rollback(); store.compactMoveChunks();) are
swapped, test passes.
Could you please look into this?
Are we doing something wrong or did we find a bug in MVStore?
Thanks, regards,
Roland
--
You received this message because you are subscribed to the Google Groups "H2
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.
package org.test;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.h2.mvstore.MVStore;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
public class CompactMoveChunksTest {
@ClassRule
public static TemporaryFolder folder = new TemporaryFolder();
private static String storePath;
private MVStore store;
private Map<Long, Map<String, Object>> map;
@BeforeClass
public static void beforeClass() throws IOException {
storePath = folder.newFolder().getPath();
}
public void openStore() throws Exception {
File file = new File(storePath, "test.db");
MVStore.Builder storeBuilder = new MVStore.Builder();
storeBuilder.autoCommitDisabled();
storeBuilder.fileName(file.getPath());
store = storeBuilder.open();
store.setReuseSpace(true);
store.setVersionsToKeep(0);
}
public void closeStore() throws Exception {
store.rollback();
store.compactMoveChunks();
store.close();
}
private void openMap() throws Exception {
map = store.openMap("map");
}
@Test
public void testPut() throws Exception {
Map<String, Object> values = new HashMap<>();
values.put("mapKey", "mapValue");
openStore();
openMap();
map.put(11L, values);
store.commit();
closeStore();
openStore();
openMap();
Map<String, Object> content = map.get(11L);
assertNotNull(content);
assertTrue(content.toString(), content.containsKey("mapKey"));
assertTrue(content.toString(), content.containsValue("mapValue"));
closeStore();
}
}