An open MVMap causes a conflict with TransactionMap in the below simple example:
import org.h2.mvstore.MVMap;
import org.h2.mvstore.MVStore;
import org.h2.mvstore.db.TransactionStore;
import org.h2.mvstore.db.TransactionStore.Transaction;
import org.h2.mvstore.db.TransactionStore.TransactionMap;
import org.h2.mvstore.MVMap;
import org.h2.mvstore.MVStore;
import org.h2.mvstore.db.TransactionStore;
import org.h2.mvstore.db.TransactionStore.Transaction;
import org.h2.mvstore.db.TransactionStore.TransactionMap;
public class H2TestMain5 {
public static void main(String[] args) {
String fileName = "MVStoreFile.dat";
MVStore s = MVStore.open(fileName);
MVMap<Integer, String> auxMap;
auxMap = s.openMap("testMap");
TransactionStore ts = new TransactionStore(s);
ts.init();
Transaction tx = ts.begin();
TransactionMap<Integer, String> testMap = tx.openMap("testMap");
testMap.put(new Integer(0), "Hi");
testMap.put(new Integer(1), "Hello");
testMap.put(new Integer(2), "Hello world");
tx.commit();
ts.close();
//auxMap = s.openMap("testMap");
for (int i = 0; i < 3; i++) {
System.out.println(auxMap.get(i));
}
s.close();
}
}
After line:
testMap.put(new Integer(0), "Hi");
the testMap is incorrectly closed and due to this the following line:
testMap.put(new Integer(1), "Hello");
gives in debugger the following errors:
Exception in thread "main" java.lang.IllegalStateException: This map is closed [1.4.191/4]
at org.h2.mvstore.DataUtils.newIllegalStateException(DataUtils.java:773)
at org.h2.mvstore.MVMap.beforeWrite(MVMap.java:1039)
at org.h2.mvstore.MVMap.put(MVMap.java:117)
at org.h2.mvstore.db.TransactionStore.log(TransactionStore.java:282)
at org.h2.mvstore.db.TransactionStore$Transaction.log(TransactionStore.java:706)
at org.h2.mvstore.db.TransactionStore$TransactionMap.trySet(TransactionStore.java:1104)
at org.h2.mvstore.db.TransactionStore$TransactionMap.set(TransactionStore.java:1027)
at org.h2.mvstore.db.TransactionStore$TransactionMap.put(TransactionStore.java:1005)
at t2test2.H2TestMain5.main(H2TestMain5.java:24)
However, when run without debugger the erros are:
Exception in thread "main" java.lang.IllegalArgumentException: Could not serialize Hi [1.4.191/0]
at org.h2.mvstore.DataUtils.newIllegalArgumentException(DataUtils.java:736)
at org.h2.mvstore.type.ObjectDataType.serialize(ObjectDataType.java:355)
at org.h2.mvstore.type.ObjectDataType$SerializedObjectType.write(ObjectDataType.java:1531)
at org.h2.mvstore.type.ObjectDataType.write(ObjectDataType.java:128)
at org.h2.mvstore.type.ObjectDataType.write(ObjectDataType.java:122)
at org.h2.mvstore.Page.write(Page.java:744)
at org.h2.mvstore.Page.writeUnsavedRecursive(Page.java:825)
at org.h2.mvstore.Page.writeUnsavedRecursive(Page.java:831)
at org.h2.mvstore.MVStore.storeNowTry(MVStore.java:1141)
at org.h2.mvstore.MVStore.storeNow(MVStore.java:1046)
at org.h2.mvstore.MVStore.commitAndSave(MVStore.java:1035)
at org.h2.mvstore.MVStore.commit(MVStore.java:996)
at org.h2.mvstore.db.TransactionStore.close(TransactionStore.java:217)
at t2test2.H2TestMain5.main(H2TestMain5.java:28)
Caused by: java.io.NotSerializableException: org.h2.mvstore.db.TransactionStore$VersionedValue
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1184)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
at org.h2.mvstore.type.ObjectDataType.serialize(ObjectDataType.java:352)
... 12 more
If the opening of the auxMap is moved to the commented line:
//auxMap = s.openMap("testMap");
then the program works correctly.
In addition, it seems that after line:
ts.close();
the TransactionMap testMap is still open.
Shouldn't it be closed because the TransactionStore used to open it is now closed?