. NET short talk about the nature of transactions

Source: Internet
Author: User

 

This article mainly introduces the nature of transaction processing.

In fact, transaction processing is no stranger to us, but many people seem to be confused about transaction processing, and feel that transaction processing only exists in the database. There is a reason for this. When we begin to prepare for learning programming, we start to learn from some programming languages, unlike other foreign countries that will learn concepts, principles, and models first, we will associate some technologies with some languages and platforms, this makes it hard for us to learn other languages or platforms.

In school, you can also learn by yourself. In order to get started quickly, you will learn some tools before learning the technologies related to our daily development, it is only technical implementation, but it does not go into the root of the question "why ". In fact, as our software developers, we need a correct learning method like concept, principle, and technical implementation to keep up with good development, or a sorting process, I only know it, but I don't know why. This will be confusing.

Enter the topic. Through the learning method described above, we will first go from concept to principle to technical implementation to clarify the transaction. It will not only be used in databases, transactions are used everywhere in the computer field.

Overview, features, and principles of transactions:

The overview of transaction processing is everywhere on the Internet, but almost every article uses databases as the case for transactions, rather than using a programming language or combining the two.

So for beginners, the transaction is a database transaction. I also tried to search for it on the Internet. 80% is a database transaction. What is BeginTran ............. I think this article is worth writing. I hope that the explanation in this article will give you a new understanding of the transaction and do not associate the transaction with the database, the database is only a management tool for transaction processing.

Overview:A transaction is a logical region in which the executed code belongs to a large logical operation. That is to say, this is an atomic operation, either done or not done. This ensures that any problem in any stage can be restored to the status before the initial call.

Figure 1:

Features:What are the features of transactions? A transaction is a logical region. All resources and functions involved in transaction processing are incorporated into a unified management center for unified coordination and management to jointly complete a major transaction. Features are some principles and features of transactions, such as the state of transactions and the isolation of transactions. transactions must possess these features. Only these features can be considered transactions.

Atomicity: the Atomicity of a transaction. It means that all operations in a transaction are regarded as a whole, either successfully or not executed. If we use transactions to implement a data cut function, first cut the data and then paste it. If the paste fails, we must ensure that the data is restored to the original state, although these are two actions, they are an action in the transaction.

Consistency: Consistency ensures that the data modification during the execution of the transaction is correct in the end, whether it is successful or failed. As mentioned above, when we cut the data, when there is a problem with the paste, it cannot be terminated at will. In the transaction, we need to save the changes to the data, if the transaction fails, the initial data recovery is required. If the transaction succeeds, the modified data is used to guarantee the final result.

Isolation: Isolation is easy to understand. Access to the same resource from multiple transactions must be isolated from each other, your modifications will not be affected by me, and your modifications will not interfere with my execution. This ensures data integrity. The data accessed during the execution of the transaction is the persistent data, that is, the data after the consistency, and will not attempt to access the internal data of another transaction.

Durability: Durability means that once a transaction is executed, data changes are permanent. At this time, the intermediate state in the transaction no longer exists, and all resources occupied by the transaction during execution have been released. Therefore, data cannot be restored to the initial state at this time, unless the Resource Manager supports this, our database management system can be restored through logs. (The Principles of resource manager will be discussed later)

Recommended books: Transaction Processing: Concepts and technologies-Computer Science Series

Principle:

We have learned about the concept and features of a transaction. How is the implementation principle of the transaction, here we only discuss the theory of transactions, which has nothing to do with the specific language implementation or database. Only by figuring out these theories can we fully understand transaction processing, I promise you will have a new understanding of database transaction processing.

Then how can we make the transaction operate, that is, the transaction implementation model. Any tool in any language will encode the transaction implementation in accordance with the principle, so we will temporarily put aside those messy database transactions. To understand the implementation principle of transactions, which are the major parts of the transaction and how they are coordinated to complete the transaction.

Transaction Manager: the start and end of a transaction requires a center in this cycle to manage the participants in the transaction scope. The transaction may contain multiple operation points. Let's look at a solution.

Figure 2:

First, the initiator of the transaction initializes the global transaction environment, except that only one initiator object exists in this environment. Then, as the call continues to extend, the transaction environment is constantly radiating, the transaction environment can be large or small. It depends on the application scope of the transaction. A common database transaction is very simple, and the scope of the transaction will not exceed the database engine, but now large online transaction processing is designed to process transactions between multiple database engines.

So how do callers participate in transactions? I think this is related to the specific language platform. Different languages may have different platform implementations. Later, we will use. NET transactions to explain how transactions are used in. NET.

I just talked about how transactions spread the transaction environment, so what is involved in the transaction lifecycle, which involves the core of transaction processing, these models support the entire lifecycle of a transaction.

Figure 3:

We will explain how transactions are implemented and how they can be implemented on different platforms in different languages. The key is to understand the implementation principles.

Transaction initiator (customer): this is also the beginning of the transaction. The environment is created by it, and the Environment propagation is automatically extended through the transaction environment induction, however, in some cases, you need to manually spread and separate the transaction environment.

 

Resource Manager: The resource manager is responsible for the data to be operated by the transaction. The resource manager should work with the execution of the transaction to ensure that the data can be smoothly persisted when appropriate. Resource Manager is the database management system we use everyday. However, the database management system is very powerful and can complete complex data processing, including support for distributed transactions and DTC. Therefore, we need to understand that Database Transaction processing is within the scope of the database management system, and we can also write our own transactional software tools.

How the specific transaction manager participates in the transaction environment depends on the specific platform. The following article introduces how to implement transaction processing, distributed transactions, and database transactions in. NET.

Transaction Manager: This is the overall axis of the transaction environment, responsible for all management in the transaction environment, including registration notifications to the resource manager and so on.

[Wang qingpei has all rights reserved. For more information, please sign it.]

Recommended books: Principles of transaction processing (2nd edition) (foreign classical computer science textbooks)

<Script> </script>

Related Article

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.