Talk about distributed transactions II: Distributed Transaction Management Model Based on DTC [Part 1]

Source: Internet
Author: User
Tags msmq
Document directory
  • 1. Lightweight Transaction Manager (LTM: Lightweight Transaction Manager)
  • 2. Kernel transaction Manager (KTM: Kernel transaction Manager)
  • 3. Distributed Transaction Coordinator (DTC: Distributed Transaction Coordinator)
  • 4. Transaction Promotion)

Through the previous introduction, we learned that what SOA really needs is a resource that can coordinate service operations directly (accessed by the service itself) or indirectly (Resources accessed by the called service) distributed Transaction Management System for all resources accessed, which is a complex architecture system. As a distributed framework based on SOA on Windows, WCF provides comprehensive support for distributed transactions. However, instead of making full use of the existing Windows transaction control infrastructure. This section focuses on the Windows transaction processing model. First, let's take a look at the roles of each transaction participant in this model.

All transaction participants assume the following three roles according to their respective functions at each stage of the transaction lifecycle:

  • Application, Service, or Component ):Represents a user program, or a Service or Component that carries a function );
  • Resource Manager (RM: Resource Manager ):Software programs used to manage specific transaction resources, such as databases or queues (MSMQ;
  • Transaction Manager (TM: Transaction Manager ):A middleware program that manages the entire transaction and provides basic transaction control services for the application and resource manager.
I. Application, Service, and Component)

Transactions end up serving user programs, services, and components. The latter uses the special mechanism of transactions to execute a group of related operations as an inseparable whole, this ensures data consistency. In the entire model, applications (services or applications, for the sake of concise description, the subsequent sections on applications, services and components are referred to as applications) are mainly responsible for the following transaction-related tasks:

  • Start transaction:The drivers at the beginning of the transaction are always applied, but not all applications start a new transaction. Only the initial application is the start of the transaction;
  • Transaction notification and Propagation ):Encapsulate and disseminate local transactions of an application to another application or resource manager;
  • Commit transactions:The start of the transaction is also the final submission of the transaction. After the transaction-related operations are successfully completed, the application that initially started the transaction will submit the transaction.
2. Resource Manager (RM: Resource Manager)

In the transaction control model, neither the application nor the resource manager can directly access specific transaction resources, but indirectly perform operations on the target resources through an intermediary, which is the resource manager. Based on whether the target resource can be persisted, the corresponding resource manager can be divided into the following two types:

  • Durable Resource Manager ):Used to manage persistent resources, such as databases and MSMQ. When a transaction is rolled back, it can be recovered );
  • Volatile Resource Manager ):It is used to manage non-persistent loss-prone resources such as memory data and non-recoverable resources.

In the Two-Phase Commit (2 PC: Two-Phase Commit) protocol for implementing distributed transactions described later, the Two resource managers use different registers (Enlist) method. In general, the resource manager mainly undertakes the following functions throughout the transaction model:

  • Helps applications perform operations on target resources;
  • Register with the corresponding transaction manager, so that when the transaction is rolled back, it can receive the recovery request from the Transaction Manager to restore the data;
  • Report the results of local transactions to the corresponding transaction manager;
3. Transaction Manager)

The transaction manager is the core and pivot of the entire transaction control model. It controls all the participants of the transaction and coordinates all the relevant processes from the beginning to the completion of the transaction. The transaction manager provides applications and resource managers with a series of core transactional services to start, commit, and roll back transactions. Windows provides three different transaction managers, which we will introduce one by one.

1. Lightweight Transaction Manager (LTM: Lightweight Transaction Manager)

As its name implies, the lightweight Transaction Manager (LTM) has the smallest load and is the transaction manager with the highest performance. The LTM function is limited to the application domain (AppDomain) where the transaction is started, and the number of persistent resources registered to the transaction cannot exceed one.

Generally, started transactions are managed by LTM. If a transaction involves operations across application domains, the current transaction is sent back to another execution context, in this case, the transaction is out of LTM's jurisdiction. In addition, multiple Volatile resources can be registered simultaneously in LTM-based transactions, but only one persistent resource can be registered. When the second persistent resource is registered to the current transaction, the transaction will also be out of LTM's jurisdiction.

Not all persistent resources can be registered to LTM. So far, transaction resources that can be registered to a high-performance Transaction Manager such as LTM are limited to SQL Server 2005 and SQL Server 2008, even SQL Server 2000 and MSMQ on Windows do not support LTM, not to mention Oracle and DB2. We hope Microsoft can cooperate with other vendors so that transaction resources developed by third parties can also take advantage of LTM performance.

2. Kernel transaction Manager (KTM: Kernel transaction Manager)

Kernel Transaction Manager (KTM) is introduced in Windows Vista and used for subsequent Windows Server 2008 and Windows 7. The main purpose of introducing KTM is to include file management and Registry management into the scope of transactions. With the help of KTM, we can operate the file resources and registry Resources in the NTFS file system in the form of transactions. We will support transaction file systems and registries as transactional file systems (TxF) and transactional Registry (TxR ).

It is called the Kernel Transaction Manager because the KTM-based transaction control engine runs in Kernel Mode instead of User Mode. Like LTM, KTM has no restrictions on the loss-prone transaction resources, but a single persistent transaction resource is involved.

From the above introduction, we can easily see that whether it is LTM or KTM, its jurisdiction is limited to local transactions, but it is powerless for distributed transactions. Distributed transactions depend on a more powerful Transaction Manager, which is the Distributed Transaction Coordinator we will introduce next.

3. Distributed Transaction Coordinator (DTC: Distributed Transaction Coordinator)

For Distributed Transaction Coordinator, most of us refer to DTC or ms dtc for short. DTC is used to manage distributed transactions executed across boundaries (across application domains, processes, machines, and networks). It adopts the corresponding transaction management protocol, for example, Ole-Tx and WS-Atomic Transaction (WS-AT) coordinate all participants in a distributed Transaction.

Each machine has a unique DTC, and all the transaction resources of a transaction are managed by the DTC of the current machine. When transactions span multiple machines, their respective DTC needs to collaborate with each other according to the corresponding protocol to achieve consistent management of the entire transaction.

4. Transaction Promotion)

In terms of functions, DTC can coordinate and manage all transaction resources involved in a distributed transaction, regardless of the specific resource distribution. However, due to the complexity of its transaction control (generally using a two-phase commit protocol) and the need for cross-process, cross-machine, or even cross-network communication, the performance is undoubtedly the worst. Therefore, it is impossible for us to use DTC in any transaction scenario. The so-called "Although the knife is good, it is inconvenient to kill the chicken", we should select the transaction manager with the highest performance according to the needs of transaction control.

However, a transaction is a sequence of dynamically executed operations, and the system cannot predict the resource registration status after the entire transaction has been fully executed, therefore, you cannot specify a Transaction Manager customized for multiple transactions in advance. On the contrary, you can only dynamically select the Transaction Manager most suitable for the current transaction execution in the specific transaction execution process. Windows uses the transaction escalation mechanism to select the Transaction Manager.

Generally, at the beginning of a transaction, LTM is used as the current transaction manager by default. With the gradual execution of transaction operations, how the transaction involves access to a kernel transaction resource is automatically upgraded to a KTM-based transaction. Whether it is a transaction based on LTM or KTM, when the following two situations occur, the transaction based on DTC will be upgraded:

  • Transaction operations involve accessing or accessing multiple LTM resources not supported by LTM:For example, when the transaction application enables two connections based on SQL Server 2008 (LTM transaction-type resources) for data access, or the access to an Oracle-based (non-LTM transaction-type resources) to access data;
  • The current transaction is blocked aling across application domains ):For example, when a service calls another service, the current transaction is serialized to spread to the called service provider.

Since the transaction system of WCF solves the transaction flow between services and the collaboration of all transactional resources directly or indirectly accessed by service operations, such transactions are implemented through distributed transactions based on DTC. Next, let's briefly discuss implementation of distributed transactions based on DTC.

 

Distributed Transaction series:
Talk about one of distributed transactions: What transaction control methods does SOA need?
Talk about distributed transactions II: Distributed Transaction Management Model Based on DTC [Part 1]
About distributed transactions II: Distributed Transaction Management Model Based on DTC [Part II]
Distributed Transaction 3: System. Transactions transaction details [Part 1]
About Distributed Transaction 3: System. Transactions transaction details [Part II]

Author: Artech
Source: http://artech.cnblogs.com
The copyright of this article is shared by the author and the blog Park. You are welcome to repost this article. However, you must retain this statement without the author's consent and provide a clear link to the original article on the article page. Otherwise, you will be held legally liable.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.