Currently I’m working on a 2 phase commit in Multiverse; a Java based Software Transactional Memory implementation. The cool thing about the 2 phase commit in Multiverse is that isn’t slow (something most developers fear when they hear about 2 phase commit). It only says that the transactions should do the commit in 2 parts:
- prepare: make sure that the transaction has no read/write conflicts and make sure that the sources are ‘locked’ so that a commit is going to succeed
- commit: does the actual writing of the changes
So if multiple transactions need to commit/abort atomically; the all need to be prepared first. If this succeeds, they all can continue to the commit (that is not going to fail). And if the prepare of one of the transactions fails, they are all aborted. A 2 phase commit in Multiverse can be done completely in memory in a single JVM without any network communication, so it is very very fast.
I’m still working on a nice ‘synchronization’ structure called the CommitGroup. The CommitGroup is the token that needs to be shared between all transactions that all need to commit atomically:
CommitGroup group = new CommitGroup();
When a transactions want to participate in the commit group, and are not able to complete it, you can do something like:
And if it is the transaction that is able to complete all the commits of the CommitGroup, you can do something like this:
Isn’t that cool? The 2 phase commit and the CommitGroup are going to be part of Multiverse 0.4 which is going to be released at the end of this month on the new location at Codehaus, including a complete new website with a big reference manual, tutorials, introductions and of course a lot of new features and performance improvements. The main focus is going to shift from creating a cool toy project, to something really usable like Hibernate.