What happens when the application crashes during an execution of LevelDB batch?

207 views Asked by At

It is mentioned in the LevelDB Documentation that write batch is capable of providing atomicity for multiple operations. Yet, I just want to know what happens if the the application crashes during an execution of a write batch. Will it rollback all the changes or will it partially commit the changes?

I am referring to a scenario as below where it takes some time for the batch to complete its execution. (Code is written in Java using LevelDBJNI)

WriteBatch batch = db.createWriteBatch();

    for(int i=0;i<10000000;i++){
        batch.put(("key "+Integer.toString(i)).getBytes(),("value "+Integer.toString(i)).getBytes());
    }

    System.out.println("Batch Filled");

    db.write(batch); //takes around 5s -- what if system crashes here??
1

There are 1 answers

0
ren On

WriteBatch guarantees that either all or nothing ends up on the disk. That's in case of process crash. In case of file system crash - power loss - there are no such guarantee I think.