Transactions in Graph Engine

267 views Asked by At

Is it possible to implement transactions in Graph Engine?

I like to do multiple updates on different cells and then commit or rollback these changes.

Even with one cell it is difficult. When I use the next code the modification is not written to disk but the memory is changed!

using (Character_Accessor characterAccessor = Global.LocalStorage.UseCharacter(cellId, CellAccessOptions.StrongLogAhead))
{
    characterAccessor.Name = "Modified";
    throw new Exception("Test exception");
}
2

There are 2 answers

0
Andreas Hassmann On

My understanding is: Regardless of you throwing this Exception or not: The changes are always only in memory - until you explicitly call Global.LocalStorage.SaveStorage().

You could implement your transaction by saving the storage before you start the transaction, then make the changes, and in case you want to rollback, just call Global.LocalStorage.ResetStorage().

All this, of course, only if you do not need high-performance throughput and access the database on a single thread.

0
Yadli On

The write-ahead log is only flushed to the disk at the end of the "using" scope -- when the accessor is being disposed and the lock in the memory storage is about to be released.

This is like a mini-transaction on a single cell. Others cannot access the cell when you hold the lock. You could do multiple changes to the cell and "commit" them at the end -- or, making a shadow copy at the beginning of the using scope, and then rollback later to this copy when anything goes wrong (this is still a manual process though).

Also, please check this out: https://github.com/Microsoft/GraphEngine/tree/multi_cell_lock We are working on enabling one thread to hold multiple locks. This will make multi-entity transactions much easier to implement.