Distributed Systems Reading notes (17)-----Distributed transactions

Source: Internet
Author: User

Introduction

The difference between a distributed transaction and a common transaction mentioned in the previous article is that he has more than 1 servers involved. A distributed transaction may be 1-tier or nested-layered. In order to coordinate distributed transactions, there is an atomic commit protocol, and the more famous 2PC protocol is one example. Prior to the 3 methods of concurrency control lock control, optimistic concurrency control, timestamp sequence method, after a certain extension can also be used in distributed transactions above. On distributed transactions, the recovery manager is also provided for the recovery of objects, operations. It has been discussed before to implement object access on a single server, but on a separate server, a coordinator is needed to coordinate the transaction.

single-layer and multi-tiered nested distributed transactions

In a single-layer transaction, a client makes a request to a server, and the server can control the access of the object through a lock in a short time, and in a multi-layered nested distributed transaction, the upper part can be used as the coordinator and the sub-transaction is reconciled. Each coordinator maintains a list of participants, and each participant also has a reference to the facilitator.

Atomic Commit Protocol1. One-stage submission Agreement

The atomic properties of a transaction also require that the execution of the distributed transaction is either completed or not executed at all. The simplest implementation of atomic protocols is to allow the facilitator to communicate with all participants until the recovery of each participant is judged whether they have been executed, which is called a one-stage commit protocol. The disadvantage of a one-phase commit protocol is that the Coordinator does not know if the server has crashed or is deadlocked, causing the coordinator to wait for the requested reply.

2.2 Phase Submission Agreement

In order to cover the defects of the above protocol, there is the 2PC protocol, 2-phase commit protocol, so of course it is divided into 2 phases. The first stage of the image is that in the collection of participants in the voting stage, the agreement will ask the participants whether they can submit a transaction, waiting for the coordinator to obtain the response of all participants, know what to do next step to the second stage. 2, the second phase of the coordinator issue Docommit () or doabort () command to each participant, each participant completes the operation, the return operation value represents the operation completed, since the end of this 2pc process.

3, the performance of the 2PC protocol

It is clear that there must be some delay in the time when the facilitator collects the participants ' votes, because the response of so many participants, followed by the frequent message transfer in the 2 phases, consumes a great amount of bandwidth.

concurrency control in distributed transactions

In a distributed environment, each server manages a collection of objects, and they have a responsibility to keep those objects in a consistent state when they are accessed by a distributed transaction.

1. Lock mode

Lock mode can also be problematic in distributed transactions, resulting in distributed deadlocks.

2. Time Stamp sequence

One of the difficulties in distributing the concurrency control method of timestamp sequence is how to ensure the uniqueness of the global timestamp, and each coordinator has his own timestamp, which requires some synchronization between the coordinators to allocate a unique timestamp sequence number.

3. Optimistic concurrency control

The core of optimistic concurrency control in distributed is the global validation detection, which is no longer a local pure detection.

Distributed Deadlock1. Wait-for Graph Waiting Graph

Distributed deadlocks are also most likely to occur in distributed transactions, and the detection of distributed deadlocks can be done through a timeout mechanism (the control of time interval is also a difficulty), and a circular reference is found in the wait diagram for each transaction. The local wait graph (wait-for graph) can be built from the lock manager on the local server, and if a loop is found in the wait graph, a deadlock is shown.

2. Edge Tracking

The edge chasing method is a distributed way of detecting deadlocks by sending a message to the next node through each node, sending a message to the node that the node is waiting for, and if a loop appears in the last message, then the description also has a deadlock, the format of the message is <T->U> , on behalf of the transaction T waits for the transaction U to release the lock, if the sending u,u is just waiting for W, then the message will be changed to <t->u->w> In general, it is a pattern of message building.

Recovery of transactions

Failure handling of a transaction is important throughout the transaction, and you want to ensure that all States can revert to what happened before the transaction. The main principle here is to recover data by recording records in permanent storage. Transaction management can be implemented through a simple mechanism----the Recovery Manager transaction manager.

1. Recovery Manager

The transaction manager has some of the following features: (1), for committed transactions, to save objects to persistent storage. (2), after the server down, you can restore these objects. (3), the ability to reorganize recovery files to improve the performance of recovery. (4), reallocate the storage space in the recovery file.

2. Recovery file

The recovery file mainly contains 3 things: 1, object, the value of the objects. 2. The status of the Transaction status transaction. 3, intentions list, save the transaction in the execution of the process of saving a temporary, the format of <objectid, Pi>,pi for the object in the location of the recovery file. This allows you to complete the recovery for the object.

3, logging

Log technology acts as a record of transaction history in the process of recovering transactions. Through the completion of the transaction commit, constantly at the end of the recovery file append content, to complete the record, in order to do the recovery operation, from the back to the forward recovery.

4, shadow versions

Shadow versions technology uses an adjustable way to organize a recovery file. Because he uses a graph to map the local object version to a place called version store, which means that in the version store file, many versions of object are maintained. Shadow version's technology is better in performance than the log technology, because he uses graph mapping in this way.


References: <<distributed sysytems Concepts and design>> original version fifth, Author:george Coulouris,jean Dollimore, Tim Kindberg,gordon Blair

Distributed Systems Reading notes (17)-----Distributed transactions

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.