Understanding Transactional Enhancements
This article presents transactional enhancements to Windows Server 2008. The companion topic, Developing with Transactional Enhancements provides a detailed discussion of programming using these technologies. The Transactional Enhancements Samples topic contains sample applications that demonstrate using the new transactional features.
The transactional enhancements discussed in this article simplify building transaction-aware applications that preserve data integrity, isolate uncommitted changes, and reliably handle error conditions. Applications use transactions to group operations on resources and ensure that the operations either succeed or fail as a single unit (that is, atomically). For example, a content management application that stores documents in the file system and metadata for the documents in a database must coordinate updates to ensure that the database and file system are both updated or neither is updated. Without transactions, the application must include complex error handling and recovery logic to handle situations where only part of the update is able to succeed or a catastrophic error occurs, such as a system crash. Using transactions, applications rely on resource managers within the operating system to ensure that updates to resources are atomic, consistent, isolated, and durable (ACID).
Kernel Transaction Manager
The Kernel Transaction Manager (KTM) infrastructure manages transactions. Developers can also use KTM to develop custom resource managers that support atomic operations and enforce concurrent updates and data consistency. Applications have complete control over when transactions are used with resources; it is possible to access a resource both within the scope of a transaction and outside the scope of any transaction. For example, an application can modify a set of files as part of a single transaction and update a log file regardless of the transaction's outcome.
The Microsoft Distributed Transaction Coordinator (DTC) is a component of the operating system that manages transactions that involve multiple resource managers, including distributed transactions that cross computer boundaries. The DTC coordinates transactions with user-mode resource managers such as SQL Server. The DTC can work with kernel-mode resources that are using KTM.
Transactional NTFS (TxF) is built on the KTM infrastructure. TxF allows applications to perform file operations on an NTFS volume in a transacted manner. Using TxF, an application can update files in a consistent and reliable manner.
Applications often require complex procedures to ensure that files are recoverable in the event of a system failure. For example, it is not uncommon to overwrite a file by creating a new temporary file with the new content, renaming the original file to a temporary name, renaming the new file to the original file name, and, if each step has been successful, finally deleting the original file. Using TxF, an application can simply open the file as part of a transaction and write the new content. If any operation within the transaction fails, TxF is responsible for recovering the previous version of the file. Not only does this functionality simplify coding and testing efforts, it improves application reliability in scenarios where data corruption is likely to occur, such as a power failure. After such an event, a transaction involving TxF resources that was in progress is automatically rolled back with no action required on the part of the application.
TxF supports a single transactional writer and multiple concurrent readers; a file cannot be modified by multiple concurrent transactions. Until a transaction is committed, the readers will see a consistent view of the file that does not reflect changes made by the transactional writer.
TxF operations can participate in DTC transactions so changes to the file system can be coordinated with changes to SQL Server databases and any other resource manager that works with DTC.
The Transactional Registry (TxR) is built on the KTM infrastructure. TxR allows applications to perform registry operations in a transacted manner. A common scenario for using TxR is during software installation. TxF and TxR can participate in a shared transaction so that files are copied to the file system and information is stored in the registry as a single operation. If the installation fails or is canceled by the user, modifications to the file system and registry are discarded.
TxR operations can participate in DTC transactions so changes to the registry can be coordinated with changes to SQL Server databases, NTFS, and any other resource manager that works with DTC.