Thursday, October 21, 2010

XA Transactions

Reading MySQL documentation I have found a good description of how XA distributed transactions and two-phases commit work. I like to share it because it's short, clear and applies in general situations. It also teaches us why distributed transaction, being much more complex, should be managed very carefully to avoid severe performance penalties.
Applications that use global transactions involve one or more Resource Managers and a Transaction Manager:

A Resource Manager (RM) provides access to transactional resources. A database server is one kind of resource manager. It must be possible to either commit or roll back transactions managed by the RM.

A Transaction Manager (TM) coordinates the transactions that are part of a global transaction. It communicates with the RMs that handle each of these transactions. The individual transactions within a global transaction are “branches” of the global transaction. Global transactions and their branches are identified by a naming scheme described later.

The MySQL implementation of XA MySQL enables a MySQL server to act as a Resource Manager that handles XA transactions within a global transaction. A client program that connects to the MySQL server acts as the Transaction Manager.

To carry out a global transaction, it is necessary to know which components are involved, and bring each component to a point when it can be committed or rolled back. Depending on what each component reports about its ability to succeed, they must all commit or roll back as an atomic group. That is, either all components must commit, or all components musts roll back. To manage a global transaction, it is necessary to take into account that any component or the connecting network might fail.

The process for executing a global transaction uses two-phase commit (2PC). This takes place after the actions performed by the branches of the global transaction have been executed.

In the first phase, all branches are prepared. That is, they are told by the TM to get ready to commit. Typically, this means each RM that manages a branch records the actions for the branch in stable storage. The branches indicate whether they are able to do this, and these results are used for the second phase.

In the second phase, the TM tells the RMs whether to commit or roll back. If all branches indicated when they were prepared that they will be able to commit, all branches are told to commit. If any branch indicated when it was prepared that it will not be able to commit, all branches are told to roll back.

In some cases, a global transaction might use one-phase commit (1PC). For example, when a Transaction Manager finds that a global transaction consists of only one transactional resource (that is, a single branch), that resource can be told to prepare and commit at the same time.

Sunday, October 3, 2010

Mounting Alfresco as a WebDAV Network Folder

I like Alfresco Share's beautiful UI and I like Alfresco's CIFS capability of being mounted as a remote SMB/CIFS network drive. Anyway, one of the few shortcomings of Share is that you cannot download multiple files from the Web UI (you can upload multiple files), something you can easily do by mounting Alfresco as a SMB/CIFS drive, dragging & dropping files in and out.

Note: I think one of the coolest features we should add to Share's UI would be the ability to download a selection of folders as a ZIP file in one shot.

CIFS is not enabled by default, so there are Alfresco deployments where you cannot mount it locally on your workstation, for security reasons or because of a lazy sys admin. However, to interact with Alfresco easily you always have an option: mount it as a WebDAV network folder, which is easy to do from any operating system and it's enabled by default in Alfresco (unless your sys admin disabled it on purpose).

On the Alfresco Wiki you can find instructions for mounting WebDAV on Windows. Here I want to quickly show you the same thing on  Mac OSX and Finder, which is even easier (of course, it's a Mac....).

First of all, Alfresco's WebDAV is available from address: http(s)://hostname:port/alfresco/webdav/
in my case I'm using a local Alfresco server, within my home network, so it is: http://myalfresco.it:8080/alfresco/webdav
Beware that in most cases Alfresco is configured to be accessible to the external world via HTTPS and not plain HTTP, so write your URL accordingly.

Now open the Finder and press ⌘K to open the server connection dialog, adding you Alfresco's WebDAV URL like this:


After pressing "connect" (sorry, my screenshots are in Italian....) and entering your own Alfresco's username and password, you'll get this:


Now you could go to your Alfresco's User Home, in my case it's mturatti, and start dragging and dropping file into Alfresco, or from Alfresco into your desktop.