Database Chapter 11 Concurrency control

Source: Internet
Author: User

The 11th Chapter concurrency control

This paper introduces the problems that concurrency can cause data inconsistency, explains the basic concepts of concurrency control and the most common blocking techniques.

In multiprocessor system, each processor can run a transaction, multiple processors can run multiple transactions at the same time, to achieve a real parallel operation of multiple transactions, this parallel execution is called concurrent concurrency mode.

Concurrency control: To ensure the isolation and consistency of transactions.

Data inconsistencies caused by concurrent operations mainly include loss of modifications, non-repeatable reading and reading of "dirty" data, and so on.

Missing modifications: Two things T1 and T2 read the same data and modify it, the result of T2 commit destroys the result of the T1 submission, resulting in the loss of T1 modification. For example:

Non-REPEATABLE READ

Non-repeatable reading refers to a thing T1 after reading the data, T2 performs the update operation so that T 1 cannot reproduce the previous read result.

Read "Dirty" data

The main techniques for concurrency control are blocking (Locking), timestamp (Timestamp), and optimistic control, which are generally used by commercial DBMS.

Block: Before a transaction t makes a request to the system, locks it on a data object, such as a table, record, and so on, the other transaction cannot update the data object until the transaction T releases its lock.

The basic lock has two kinds, exclusive lock (Exclusive Locks, abbreviation x Lock) and shared lock (Share Locks, abbreviation S lock).

As with the operating system, blocking methods can cause problems such as live locks and deadlocks.

Live Lock:

If the transaction T1 block the data R, the transaction T2 also requests the Block R, so T2 waits. T3 also requested to block R, when T1 released the blockade on R after the system first approved the T3 request, T2 still waits. Then T4 again requested the blockade R,t3 released the blockade of R after the system approved the T4 request, T2 may wait forever, this is a live lock.

A simple way to avoid a live lock is to use a first-come-first-served strategy, when multiple transaction requests block the same data object, the blocking subsystem queues the transaction in the order in which it is blocked, and once the lock on the data object is released, the first transaction in the request queue is approved for lock.

Prevention of deadlocks:

One block method: One blockade request each transaction must be locked at once for all data to be used, otherwise it cannot continue execution.

Sequential blocking: Pre-set a block order for data objects, and all transactions are blocked in this order.

Diagnosis and release of deadlock

Timeout method: If a transaction waits longer than the specified time period, a deadlock is considered to have occurred.

Wait Graph method:

The serializable of concurrent scheduling

Conflicting serializable scheduling

Two-stage lock protocol

At present, the DBMS generally adopts two-segment lock (two-phase Locking, short 2PL) protocol to realize the accessibility of concurrent scheduling, thus guaranteeing the correctness of scheduling.

Is the blockade time can not be unlocked, unlock time can not be blocked.

Particle size of the blockade

The size of the blocked object is called the blocking granularity. The blocked object can be either a logical unit or a physical unit.

Multi-granularity blocking

Database Chapter 11 Concurrency control

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.