A friend of mine made a good comment on my last post about TxF: "what the heck does TxF do and why should developers care?" I hope to answer that question in this post. If you've never heard of TxF, read on. If you have and still don't "grok it", read on. If you just happen to love the wonderful language that is expelled from my tranquil appendages as they dance over the keyboard, then by all means, read on as well :).
So, what is TxF? TxF is the "nick name" for a new technology coming with Vista and Longhorn Server: Transactional NTFS. You may have read about or used logging file systems in the past, and you may have used journaling file systems in the past as well. But TxF is a fully-transactional file system, all built on top of NTFS. And when I say "fully-transactional", I mean it supports full ACID transactions on the file system itself.
Why should you care about TxF? You should care about TxF because the transactions that operations are contained in are not only specific to the file system. When working with TxF, there is full support for the Distributed Transaction Coordinator as well. This means that now I can coordinate transactions between the file system and SQL. Heck, this also means that I can coordinate transactions between the file system and Windows Communication Foundation.
Just stop for a second, and think about the scenarios that this opens up to us as developers. Let's look at a Document Management System, for example. If I were to submit a new version of a file into the system, the database may have to store a hash of the file as well as a pointer to the file on the file system. The problem is that we have to now guarantee that the hash of the file in the database in identical to the version of the file on the file system (I'm of course assuming that we aren't just shoving everything into blob fields).
If we update the file on the file system first, there are at least two situations that can occur that we might have to deal with: 1) If someone tries to pull down the file before the database has been updated, then the hash comparison will fail and the file will falsely be identified as corrupt. 2) If the database update fails for any reason at all, we now have to write extra code to roll back the file manually, and in the meantime, users pulling down the file could have it falsely identified as corrupt again.
So, let's change the order. Let's say we update the database first and then the file. Unfortunately, we're not in a better position, only reversed from before. Either way we go, there is more code for us to write if we want a stable system. This is where TxF can come in to make our systems more stable and robust. We can use TxF's ability to coordinate with DTC to manage all of this for us.
First of all, it would be completely Atomic. By using DTC for our database update, and TxF for our file update, they can coordinate with each other to guarantee that either they both succeed or none of them do. That's right, if the database update fails, the file system update will be rolled back, and vice versa. The transaction is also Consistent. At the same time, the file system update is also Isolated. After we update the file and before we commit the transaction, every one outside of the transaction will still see the old version of the file (how cool is that?!?!?). And the system is Durable. If we commit the transaction and the system crashes, when it restarts, the file will be guaranteed to be updated. And all of this is handled by TxF (well, handled by the new Kernel Transaction Manager, to be specific).
That's just the beginning of the story though. Imagine this on a distributed scale. We can use TxF to manage file operations across multiple machines. We can also coordinate TxF with WCF using System.Transactions :D. So, let's say I wrote a Music Download service. As a user, I want to ensure that my credit card is not charged unless I download the file completely. This is a scenario that becomes a lot easier with TxF. If my credit card was not able to be charged, I should be not be able to keep the file. On the other hand, if I was not able to download the file successfully, my credit card should not be charged (disclaimer: there are some obvious security holes to work through in this example :P).
By adding transactional support into the file system, we are also hoping to make your lives easier in the long run. You no longer have to write extra code to self-manage the file system when dealing with distributed systems. By leveraging TxF and System.Transactions, all you basically need to do is code against "The Happy Path." You just have to ensure that if anything fails, all of it is rolled back (which is ultimately handled by the system). There are a couple of sayings I like to keep in mind as a developer: 1) The fastest running code is code that doesn't run at all (I believe I got this one from Rico M.) and 2) Code that isn't written is code that doesn't have to be tested. Easier lives through transactions :).
It's not all glitz and glamour though. In my last post on TxF, I discussed some of the "down side" of TxF as the API exists today. There were two "features" that are not implemented that I didn't mention. Mainly, at this time, we do not have support for transactions on streams, or transactions when dealing with encryption. The latter, I am told, is because of some interesting security challenges that we need to iron out first.
One of the challenges I have ahead of me as a Technical Evangelist is "spreading the word" of TxF. Even before I joined Microsoft, I had only heard about it because of a couple of things: 1) the job posting for the job I interviewed for and 2) A video about TxF made by Channel 9. There really isn't a lot of information out there on TxF. And the information you can find is largely based on Vista Beta 2 or earlier, meaning, it is now quite out of date.
When chatting with Carlos about it, he said (and I quote): "I read a lot of blogs and that's the first I've ever heard of it." I'm pretty sure he's not the only one that would have this same reaction. Time to spread the word, my friends :). I only hope I can get a fraction of you out there as excited about TxF as I am. If I can do this, then hopefully the technology will speak for itself and word of it will spread fairly quickly.