It is difficult to write applications. With time, we are discovering concepts and techniques that allow us to build large applications. Modularity, structuring an application as independent modules, allows you to build complex systems from simpler parts and to get software reuse. Object-oriented concepts, as embodied in Microsoft® Component Object Model (COM), provide a technique that allows you to write modular applications.
When an application is structured as components, the individual parts can reside together in a single computer, or they can interact by using remote procedure calls across a network. So, components give both modularity and natural distribution.
Structuring an application into independent components creates the problem of managing the components. Monolithic programs fail and are restarted as a unit. However, with a modular system, the failure of one component must not corrupt the other modules. There must be a way to isolate faults and limit fault propagation. Transactions provide modular execution and thus simplify and automate fault handling. They provide a simple conceptual execution framework for both implementers and users.
The user thinks of a transaction as a single change event that either happens or doesn't happen. Implementers think of a transaction as a programming style that allows them to write modules that can participate in distributed computations. Suppose you want to transfer money from one bank account to another. The implementers and the users want to make sure that either both accounts change or neither changes. It is hard to make this work in a distributed system¾computers can fail and messages can be lost. Transactions provide a way to bundle a set of operations into an atomic execution unit.
The atomic all-or-nothing property is not new: it appears throughout life. For example, if you enter a contract, an escrow officer coordinates the transaction: the escrow officer collects the signatures of each party to the contract. The contract is final when the escrow officer announces that everyone has signed. A minister conducting a marriage ceremony first asks the bride and groom, "Do you take this person to be your spouse?" If they both respond "I do," the minister pronounces them married. A director on a movie set first asks, "Ready on the set?" If all respond yes, the director then calls, "Action!" A helmsman on a sailboat preparing to tack first asks the crew, "Ready about?" If they all respond yes, then the helmsman shouts, "Helm's a'lee!" and turns the boat. The escrow officer makes the contract, the director makes the movie, the minister makes the marriage, and the helmsman makes the tack, an atomic transaction.
These scenarios illustrate the basic principle of a transaction: several independent entities must agree. If any party disagrees, the deal is off. Once they all agree, the transaction can occur. The Microsoft Distributed Transaction Coordinator (MS DTC) performs this transaction coordination role for the other components of the COM architecture.
In MS DTC terminology, the director is called the transaction manager. The participants in the transaction that implement transaction-protected resources, such as relational databases, are called resource managers.
An application begins a transaction by calling the transaction manager's BeginTransaction method. This creates a transaction object that represents the transaction. The application then calls the resource managers to do the work of the transaction.
The application's call to each resource manager identifies the application's current transaction. For example, if the application is using a relational database, it calls the ODBC interface, which associates the transaction object with the ODBC connection. Thereafter, all database calls made over that connection are performed on behalf of the transaction until the transaction is ended.
When a resource manager first does work on behalf of a transaction, it enlists in the transaction by calling the transaction manager. As the transaction progresses, the transaction manager keeps track of each of the resource managers enlisted in the transaction.
Typically, the application completes the transaction by calling the Commit transaction method. If the application is unable to complete the transaction, it calls the Abort transaction method, which undoes the transaction. If the application fails, MS DTC aborts the transaction.
When the application successfully completes the transaction's work and calls Commit, it calls the MS DTC to commit the transaction. MS DTC goes through a two-phase commit protocol to get all enlisted resource managers to commit. The two-phase commit protocol ensures that all the resource managers commit the transaction or all abort it. In the first phase, the MS DTC asks each resource manager if it is prepared to commit. If all participants say yes, then in the second phase MS DTC broadcasts the commit message to all of them. If any part of the transaction fails, if a resource manager fails to respond to the prepare request, or if a resource manager responds no, then MS DTC notifies all of the resource managers that the transaction aborted.
MS DTC is a big part of the COM architecture. Transaction managers are a key part of most database systems. Transaction managers are also an optional part of some operating systems. Microsoft believes that transactions are essential for distributed applications¾transactions provide modular execution, which complements COM's modular programming. So, Microsoft implemented transaction management software for both Microsoft® Windows® 95 and Microsoft® Windows NT™ operating systems.
Combining the transaction concept with COM required innovation. Traditional transaction systems required considerable skill to install and manage. The challenge of integrating MS DTC with Microsoft's operating system was to automate installation, management, and use. Many of the concepts and techniques had to be reinvented for the new client/server, object-oriented, and visual management environments.
In its first release, MS DTC works with one resource manager: Microsoft® SQL Server™. MS DTC implements the OLE transaction interfaces. All OLE transaction interfaces are public so that any resource manager can become an OLE transaction resource manager. In the future, Microsoft and other software companies will add other transactional resource managers, such as distributed object systems, transactional file systems, transaction queuing systems, and workflow management systems.