How MS DTC Communicates with the XA TM

When MS DTC communicates with the XA TM:

  1. The application provides information to the XA TM about all the resource managers (RMs) it will use. The application then begins a new transaction on the XA TM. This transaction is begun on a a Windows NT thread (referred to hereafter as thread).
  2. When a new transaction is begun, the XA TM uses the information provided by the application to inform each RM about the transaction. It does this by calling xa_start, an XA function. The RM in this example is MS DTC.
  3. When xa_start is called, MS DTC creates an entry in its association table which specifies which thread is on which transaction. The association table contains tuples of the form <Thread_Id, XID, pITransaction>. The first element is the thread identifier, the second parameter is the XID that was passed in as an argument to xa_start by the XA TM, and the third element is an OLE Transactions transaction that was created by MS DTC in correspondence with the XID.
  4. Steps 2 and 3 were executed on the thread that was used by the application to notify the TM to begin a transaction. After beginning a transaction, the thread returns to the application. The application then needs to inform the RM about the new transaction in a way that is RM-specific. For example, Microsoft SQL Server provides a new DB-Library function in its RM proxy :
    int dbEnlistInXaTrans ( dbProc, …)

The parameter dbProc indicates which DB-Library connection is being requested to participate in the distributed transaction. The DB-Library (which is the RM Proxy for MS SQL Server) knows this is an XA transaction. The DB-Library must obtain the ITransaction that corresponds to the XA transaction on which the application is requesting it to enlist the connection. Then DB-Library does the following:

As mentioned previously, MS DTC creates an entry in an association table when it is notified of a new XA transaction. MS DTC obtains the thread ID of the thread by calling the IXATransLookup::Lookup method and looks for an entry in the association table, using the thread ID as the key. After it finds the entry, it returns a reference to the corresponding ITransaction to the caller, which is DB-Library.

At the end of the task, the application calls either Commit or Abort, which goes to the XA TM. The XA TM then sends the two-phase commit messages to the RMs, including MS DTC. MS DTC receives the messages and sends the corresponding two-phase commit messages to the OLE Transactions RMs that are enlisted in the transaction.