I wanted to cross-post an article I just wrote on the benefits of transactions in a massively parallel environment (not just a distributed system), not just because some may find it interesting in itself, but also because it references some of the work we've been doing in the project over the past decades. I'm hoping that as we do more work on STM and mobile transactions, to name but two areas of work, that we'll bring some of the techniques that were written about 20+ years ago to a new audience and maybe out of the realm of research. We have got a great transaction system and team here that is second to none. I'm convinced that just as Arjuna pushed the boundaries of standards and adoption of transactions for the past decades, so too can JBossTS/Narayana into the future.
Friday, April 6, 2012
Saturday, March 24, 2012
Update to STM API
Container
Sample1 obj1 = theContainer.create(new SampleImple(10));
Sample1 obj2 = theContainer.create(new SampleImple(10));
Sample1 obj3 = theContainer.clone(new SampleImple(), obj1);
Sample1 obj4 = theContainer.clone(new SampleImple(), obj2);
It no longer matters whether they are @Pessimistic or @Optimistic (the default) - the syntax remains the same. Here we have two objects, obj1 and obj2 and two clones (copies) of them, obj3 and obj4. They're all recoverable (state will not survive a machine crash), since that's the default behaviour for Container, but that can be changed via the constructor which allows for PERSISTENT or RECOVERABLE to be specified at creation time.
Friday, March 16, 2012
The Future of XTS
About Me
First of all I'll take this opportunity to introduce myself. I've worked in the field of transactions and Java middleware for over 10 years. I started out in 2001 as a software engineer on the XTS project, recently after it was founded by Hewlette Packard. Here I helped to develop the industry's first Web service transaction implementation. In those days we were implementing the BTP standard. Since then I headed up the consultancy arm of Arjuna Technologies, helping high-profile customers deploy JBoss Transactions, JBossWS and also Arjuna's Cloud Computing product. In late summer of 2011 I made the jump to Red Hat to lead the XTS project. I have also received a PhD in middleware and non-repudiation from the University of Newcastle upon Tyne, where I now hold the role of Visiting Research Fellow. In this role I teach JEE and distributed transactions as part of a masters course.
After reviewing where the XTS project currently stands we've had a good think about what areas of improvement we should be focusing on over the coming months and years. We've found that these improvements tend to fall into one of four 'themes'; usability, modernization, streamlining and consistency.
Usability
Improving usability is our number one priority. In particular we will be introducing quickstarts (JBTM-870) and making significant improvements to the XTS java API.
Currently we have a fantastic demonstrator that shows the developer how to use, pretty much, every feature of XTS. The problem is that it is not an easy place to start for those new to XTS. Recently we added a number of basic quickstarts to the JBossAS 7 quickstart project. These quickstarts are designed as a place to start when beginning to use XTS. We also have plans to provide additional quickstarts as part of the Narayana quickstart project (JBTM-870). These quickstarts will focus on more advanced features, such as recovery. These quickstarts will adhere to the same strict guidelines imposed by the JBossAS team. This will bring a high level of quality as well as familiarity. We also intend to provide unit tests with every quickstart; and those in the Narayana quickstart project will undergo continuous integration on our Hudson servers (JBTM-1068). This should ensure our quickstarts always work in the intended environment. We have an idea of what quickstarts we should initially provide, but we feel it would be best to be community driven in the future. So if you have an idea for a quickstart, or maybe you have one to contribute, then please get in touch on the forum.
The biggest changes around usability are coming as part of our new sub-project; currently named the 'TXFramework'. The TXFramework is a new and novel framework for writing portable ACID and NoACID transactional applications. It provides an abstract annotation based API for specifying transactional requirements. This decouples the application logic from the actual transaction model used (WS-AT, REST_AT, JTA, etc). It also removes a lot of boilerplate code that's currently needed by WS-AT and WS-BA services. The TXFramework also provides seamless bridging between different transaction protocols. This subject could cover many blog postings, so I won't discuss it in any more detail here. Stay tuned for more posts on this subject in the coming months. I'll also be presenting the TXFramework at JUDCon2012:Boston on the 25th June. Hope to see you there!
Modernisation
The next focus is around modernization. There's been a lot of exciting new technology emerging over the last few years and we are making many improvements to take advantage of it. In particular, Arquillian and Git.
The XTS functional tests need to run in a container. Before JBoss developed the Arquillian project, we were forced to create an in-container test-runner to run our functional tests. By migrating to Arquillian we are now able to remove this test-runner code and take advantage of additional benefits that Arquillian brings. In particular we can run any/all of the XTS tests from with the IDE as regular JUnit tests. Arquillian also manages the setup and teardown of the test environment, making it a lot easier to run the tests. This improvement is going to remove a lot of code from the XTS codebase and bring great simplification to the way we write and run tests. JBTM-954, JBTM-955, JBTM-956
Narayana and Blacktie were recently migrated from SVN to Git and Github (See here). Git has been gaining a lot of traction recently in the world of open source and most JBoss projects have now made the leap. After reviewing the benefits of moving, we decided now was the time to make the jump. In particular it was the improvements to collaboration provided by Git and GitHub that made us feel that this was the right thing to do. If you are a contributor, you're going to find it a lot easier to get involved with XTS and Narayana.
We've also moved the entire Narayana project to maven, which is making it a lot easier for our contributors to get up and running quickly and is making it easier for us to maintain our build system. We're also beginning to use JaCoCo to check our test coverage JBTM-952. This ensures that XTS is fully tested and helps find redundant code.
Streamlining
We are doing some streamlining too to the XTS code base. We are taking two approaches here; as mentioned above we are using JaCoCo to help find redundant code. This should cut down the amount of code we need to maintain and help contributors get up to speed more quickly as they don't need to sift through unused code (JBTM-741). The second approach we are taking is to replace code with third party libraries where we can be sure that they will provide an equal or better implementation. For example, as stated above we are in the process of replacing our test-harness code with Arquillian (JBTM-953).
Consistency
Being productive and helping our contributors be productive is very important to us. Having to switch between and understand different practices when working with our projects does not help with this goal. Therefore, we are aiming to bring as much consistency as we can between XTS and Narayana and to some extent between Narayana and the other JBoss projects. A move to improved consistency also brings with it an opportunity to re-use ideas that have been proven elsewhere. In particular, our quickstarts are now in the process of being moved to a single repository and follow the strict guidlines set out by the JBossAS team. The XTS codebase is being re-structured to follow the default maven layout (JBTM-968). This should make it easier for new contributors to follow our layout.
Getting Involved
Of course, we would love the community to get involved with XTS and the Narayana project. I mentioned many pieces of work in this post; you should follow the Jira issue links and vote up the ones that matter to you. If you have an idea for something you would like to be included, please start a discussion on the Narayana forum. You can also fork our GitHub projects if you'd like to get involved with the coding side.
Sunday, March 11, 2012
Transactions and NoSQL - not reinventing the wheel!
- the compensation REST transactions work;
- a history of extended transactions;
- a comparison of two of the original standards efforts in the area of compensation transactions;
- a couple of presentations on early standards effort around Web Services and transactions;
- an overview of the wider expanse of work that has been done around extended transactions, workflow, messaging, choreography etc.
Sunday, February 19, 2012
Optimistic STM
@Transactional
public class SampleLockable implements Sample
{
public SampleLockable (int init)
{
_isState = init;
}
@ReadLock
public int value ()
{
return _isState;
}
@WriteLock
public void increment ()
{
_isState++;
}
@WriteLock
public void decrement ()
{
_isState--;
}
@State
private int _isState;
}
RecoverableContainer
Sample obj1 = theContainer.enlist(new SampleLockable(10));
@Transactional
@Optimistic
public class SampleLockable implements Sample
{
public SampleLockable (int init)
{
_isState = init;
}
@ReadLock
public int value ()
{
return _isState;
}
@WriteLock
public void increment ()
{
_isState++;
}
@WriteLock
public void decrement ()
{
_isState--;
}
@State
private int _isState;
}
RecoverableContainer
Sample obj1 = theContainer.enlist(new SampleLockable(10));
Sample obj2 = theContainer.enlist(new SampleLockable(10),
theContainer.getUidForHandle(obj1));
Thursday, January 12, 2012
connecting the dots
Programming in the large is all about abstraction, loose coupling and separation of concerns. Java EE promotes the ability to use complex functionality without understanding how it is implemented. As long as you follow the instructions this works surprisingly well. With an app server at your disposal you require only the sketchiest understanding of distributed transactions to write code that consumes a message and updates a database in an ACID fashion. Which on the whole is a good thing, since not all that many people actually want to understand all the plumbing that makes it work. There is a snag though: this apparent simplicity can cause some users to think the Java EE container is not doing all that much work and can easily be replaced or done without. Likewise it makes it difficult to tell the difference between a full fledged container that will support the functionality you need and a cut down framework or lightweight container that may not.
Let's debunk a few myths...
Spring is not a JTA.
It's an abstraction layer on top of a transaction manager, not an implementation of one. For transactions involving only a single resource, it simply delegates the hard bits to that resource manager - so called 'native transactions'. Simple, fast and mostly adequate if you need only a single resource. You don't get transaction lifecycle events, but you're probably using an ORM that provides the equivalent of the beforeCompletion hook for its cache anyhow.
For transactions with more than one resource, you need to wire in a real transaction manager to Spring. You can do this with bitronix, atomikos or JBossTS, usually just by specifying the right TransactionManager and UserTransaction implementation bean classes. But your problems don't end there, because...
Spring is not a JCA.
The roles, responsibilities and relationship between the JTA and JCA components of an app server are critical considerations when you're trying to do without one. The JTA manages transaction lifecycle - begin/commit/rollback. Most importantly, it make appropriate calls on any enlisted XAResources as the transaction progresses. But here is the bit that most users don't pay attention to: A JTA does not magically know what resources you want to participate in the transaction. Telling it that is the JCA's job.
In a full on app server, the JCA manages connections to resource managers such as databases and message queues. If you deploy those drivers/connectors in a manner that identifies them as XA enabled, the JCA ensures that they are correctly associated with the transaction. Application code simply e.g. looks up the JNDI name for a connection pool and calls getConnection(). The JCA intercepts the call, get the XAResource for the connection and passes it to the transaction manager.
In some cases you don't need a full JCA. You can often make do with a transaction manager aware XA connection pool, which is essentially a subset of the JCA functionality. But you can't get away with only an XA aware driver or a non-XA connection pool. Trying to do that leads to some interesting behaviour: your app will deploy and run, but you have a transaction and a connection that know nothing about one another. Committing or rolling back the transaction won't commit or rollback the work in the database. oops.
So, you also need to wire in a JCA or suitable connection pooling implementation. Most 'standalone' JTA implementations ship with a simple connection management solution that is suitable for light use. The one in JBossTS is called the TransactionalDriver. For serious deployments you want IronJacamar or some other JCA that has robust and fast connection management.
So now you have wired up your JTA and JCA in Spring, but you are still not done because...
The standard contract between JTA and JCA does not include recovery management setup. Wiring up resources for crash recovery requires a proprietary solution that differs for each transaction manager. The connection manager that ships with the transaction manager may do this more or less automatically, but third party JCAs or XA aware connection pools probably won't. So, go read the transaction manager documentation and write a few test cases.
phew, that was a lot of work, wasn't it? Spring is good at what it does, but its not an out of box replacement for all the transactional plumbing in a Java EE app server. Nor is tomcat - you'll have much the same steps to perform there. In both cases it is possible, but not as simple as unzipping and starting JBossAS. Do you really want to make your life harder than it has to be?