3

I can't understand where and when I have to put these two instruction when using MapDB:

db.commit()
db.close()  

Commit is for when I modify the data in the db, ok. But every time I instantiate this kind of objects in a method (that is, every time I need access to the db):

DB db = DBMaker.newFileDB(new File(FILE_NAME)).closeOnJvmShutdown().make();
ConcurrentNavigableMap<Integer, Offers> offerts= db.getTreeMap("offers");  

do I have to put the db.close() instruction at the end of the method? And what about the db.commit()? Only if I modify the data?
I'm asking this because I'm facing this kind of error:

java.lang.RuntimeException: Writer thread failed
Caused by: 
java.lang.ArrayIndexOutOfBoundsException: -1811939328
at org.mapdb.Volume$ByteBufferVol.tryAvailable(Volume.java:273)
at org.mapdb.Volume.ensureAvailable(Volume.java:58)
at org.mapdb.StoreWAL.replayLogFile(StoreWAL.java:621)
at org.mapdb.StoreWAL.commit(StoreWAL.java:579)
at org.mapdb.EngineWrapper.commit(EngineWrapper.java:95)
at org.mapdb.AsyncWriteEngine.access$201(AsyncWriteEngine.java:72)
at org.mapdb.AsyncWriteEngine.runWriter(AsyncWriteEngine.java:230)
at org.mapdb.AsyncWriteEngine$WriterRunnable.run(AsyncWriteEngine.java:156)
at java.lang.Thread.run(Unknown Source)  

My MapDB version is 0.9.7.

JamieITGirl
  • 161
  • 1
  • 11

1 Answers1

2

0.9.7 had bugs, please update to newer version.

If you create new collection, you need to make commit, else changes will not be preserved.

Jan Kotek
  • 1,084
  • 7
  • 4
  • I've updated to 1.0.9 but this error still persists. I know there are newer versions but I needed to use this version. I found a workaround, anyway. The interesting thing is that the same code on a Mac pc works fine, on my Windows 7 64bit machine I had that issue. – JamieITGirl Feb 09 '18 at 18:54