An XA Filesystem

November 27, 2008

A long post, sorry!  Most is pasted code though.

Update: If you get to the bottom of this post, you may be interested in this update.

One of the underlying design tenets of my application is that everything should happen, or nothing should happen. This covers all the database access, as well as file access, and there will be a lot of the latter. This means transactions for databases and transactions for filesystems, and since both database changes and filesystem changes will be required together, this means XA transactions across the database(s) and the filesystem(s).

There are two big problems with the above requirement: firstly, DDL is rarely transactional (PostgreSQL and Informix can do it, but since choice of RDBMS is my customer’s, not mine, I can’t rely on them); and secondly, filesystems aren’t transactional either.

The DDL issue is a major one, and one not easily resolved. Given that it won’t be transactional, is it worth pursuing transactions in the other areas? I think so – the effort of writing recovery code is so much more otherwise. The layer which abstracts the application from the database can be written to understand the capabilities of the RDBMS – so if transactional DDL is supported, then it can be used.

That’s for another day though, today I’m concerned with filesystem transactions. Luckily here some work has been done. Filesystem transactions in Java are supported by the Commons Transaction Apache project. I used this really nice step-by-step tutorial to get up and running.


package txtest;

import org.apache.commons.transaction.file.FileResourceManager;
import org.apache.commons.transaction.util.Log4jLogger;
import org.apache.log4j.Logger;
import org.junit.Test;

public class CommonsTxTest {
    private static final Logger logger = Logger.getLogger(CommonsTxTest.class);

    @Test
    public void test() {
        try {
            FileResourceManager fileResourceManager = new FileResourceManager(
                    "/Users/mdneale/txtest/store",
                    "/Users/mdneale/txtest/work",
                    false,
                    new Log4jLogger(logger));

            fileResourceManager.start();

            String txId = fileResourceManager.generatedUniqueTxId();

            fileResourceManager.startTransaction(txId);
            fileResourceManager.createResource(txId, "new.file");
            fileResourceManager.commitTransaction(txId);

            fileResourceManager.stop(FileResourceManager.SHUTDOWN_MODE_NORMAL);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

And it works. Running this short program creates the new file “new.file” in the folder /Users/mdneale/txtest/store. Now swap the line:

fileResourceManager.commitTransaction(txId);

for:

fileResourceManager.rollbackTransaction(txId);

Remove the file “new.file” that was created by the last run of the program, and run the program again. This time the file doesn’t appear. So far, so good.

The next step is XA. I’m going to explain here how to interface the Commons Transaction File Resource Manager to a J2EE Transaction Manager so that the Transaction Manager can control the resource as part of an XA Transaction.  It shouldn’t be difficult to convert it for a non-J2EE Transaction Manager if necessary.
Read the rest of this entry »


Book Meme

November 13, 2008

“Bourdelle had spent a decade working on the details, gradually building them up on a pivot that turned on a naked warrior whose outstretched left arm, it is true, defies the laws of anatomy – though photographs show that Bourdelle used his own left arm as a model.”  From the chapter on Montparnasse in Metrostop Paris by Gregor Dallas.

The chapter is about the French Sculptor Antoine Bourdelle and the sentence describes the memorial sculpture for those who died in the Franco-Prussian War that he was commissioned to produce for his home town of Montauban.

Book Meme:

  • Grab the nearest book.
  • Open it to page 56.
  • Find the fifth sentence.
  • Post the text of the sentence in your journal along with these instructions.
  • Don’t dig for your favorite book, the cool book, or the intellectual one: pick the CLOSEST.

Book Meme seen on Leah Culver.

An excellent book by the way, if you’re interested in the history of Paris. The subject matter of each chapter is wildly different, so some chapters may interest you more than others, but on the whole very interesting.

By the way, each day I feel a little more guilty about not writing anything here.  The excuse is that I’m very busy, but that’s always the excuse isn’t it? This will galvanise me into action…


10 things I’ll remember about you…

August 1, 2008

Purely for amusement – ten slightly odd captures from around my desk and office in the weeks leading up to my last day at Comverse.  I wanted to be able to remind myself in future of what I saw around me every day.  Each photo has a description if you click through to the photos on flickr.


Desk Detail #1Desk Detail #2Desk Detail #3Desk Detail #4Desk Detail #5

Desk Detail #6SDG Musical ToysDesk Detail #7Goodbye Adelphi Building, John Adam StThe Last Muffin

Who am I? What is this blog for?

July 16, 2008

It’s now a week until my employment at Comverse ends and my new (ad)venture begins. For somewhere between six months and a year I’m bootstrapping myself to flesh-out and build some technologies that have been rattling around in my head for some time. I don’t know at this point exactly where this will lead, the ideas are dragging me in a few directions, but it will be a challenge, and for that reason alone it’s worth undertaking.

After nearly fifteen years in the software industry, I’ve seen much of the good and bad. After the first few weeks of my first job in 1995 I was left wondering why, though we were writing exciting software to solve our client’s problems, we didn’t harness software in the same way to solve our own problems. Between that point and today the complexity of designing, developing, testing, configuring, shipping and maintaining software has got ever more complicated. Through all this increase in complexity, I haven’t seen software that looks inwards and solves the problems inherent with that increased complexity.

Now there has been some improvement, and the more I look, the more I see. Since I started thinking about this venture, I’ve uncovered huge numbers of really exciting things happening that I never knew about. So, perhaps the first thing I’ll use this blog for is to highlight some of those. My bookmarks are full of companies writing software tools that may revolutionise what we’re doing. However, in amongst all of them I still can’t find what I’m looking for.

So what is this blog for? There was one idea above, but other than that I’m not entirely clear. It’s definitely a page to represent me beginning something new, and I suspect that for the time being it may just be a source of amusement for myself. However over the next year I’m going to have to learn a lot – and maybe (if I have time) I’ll share some of it here.  I’ll also definitely need some feedback on what I’m doing, so having a place to document and explain what I’m doing will also be useful.

If you work in the software industry, whether in development, test, professional services or management and you’re interested in harnessing technology to improve and automate the software life-cycle, or if you’re part of a globally distributed team and want to improve collaboration within your team, maybe I’ll have something here for you.

I know I’ve not told you much, sorry for that. There will be more to come.