My objective is to enable MapDB crash protection and if a crash happens, how to restore data.
I have enabled transaction for MapDB
DB db;
HTreeMap< String, String > mapDb;
db = DBMaker.fileDB( "walTest/file1.db" )
.transactionEnable()
.allocateStartSize( 64 *1024 *1024 )
.allocateIncrement( 32 *1024 *1024 )
.fileMmapEnable()
.fileMmapEnableIfSupported()
.fileMmapPreclearDisable()
.cleanerHackEnable()
.closeOnJvmShutdown()
.make();
mapDb = db.hashMap( "Test" ) //$NON-NLS-1$
.keySerializer( Serializer.STRING )
.valueSerializer( Serializer.STRING )
.createOrOpen();
for(int i=0; i<10000;i++)
{
mapDb.put(""+i, "aaaaaaaaaaa bbbbbbbbbbbbbbbbbb cccccccccccccccccccc dddddddddddddddddd");
if(i % 100 == 0) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(i == 5000)
{
db.commit();
}
}
I see that it creates 2 files, file1.db and file1.db.wal.0
And now, I restart the server and read the MapDB using below code
System.out.println(mapDb.size());
Output is 5001 The other 5000 which was not committed is not getting restored.
I tried using db.commit before doing mapDb.size() and its still not helping.
So, how is the wal file protecting against server or jvm crashes? How can we restore the wal files?