当前位置:网站首页>Overview of concurrency control
Overview of concurrency control
2022-07-05 21:59:00 【Short section senior】
Multi user database system a database system that allows multiple users to use at the same time
Aircraft booking database system
Bank Database System
characteristic : The number of transactions running concurrently at the same time can reach hundreds or thousands
Multi transaction execution mode
(1) Transactions are executed serially
There is only one transaction running at a time , Other transactions must wait until this transaction is completed before running
Unable to make full use of system resources , Give full play to the characteristics of database sharing resources 
(2) Cross concurrency (Interleaved Concurrency)
In a single processor system , The parallel execution of transactions is that the parallel operations of these parallel transactions run alternately
Parallel transactions in a single processor system do not really run in parallel , But it can reduce the idle time of the processor , Improve the efficiency of the system 
(3) Concurrent mode (simultaneous concurrency)
In a multiprocessor system , Each processor can run a transaction , Multiple processors can run multiple transactions at the same time , Realize the real parallel operation of multiple transactions
The most ideal way of concurrency , But subject to the hardware environment
More complex concurrency mechanisms
Problems caused by concurrent transaction execution
Multiple transactions access the same data at the same time
Incorrect data may be accessed and stored , Destroy transaction isolation and database consistency
Database management system must provide concurrency control mechanism
Concurrency control mechanism is one of the important marks to measure the performance of a database management system
Transaction is the basic unit of concurrency control
The task of concurrency control mechanism
Schedule concurrent operations correctly
Ensure the isolation of transactions
Ensure database consistency
Concurrent operations lead to inconsistent data instances
[ example ] A sequence of activities in an aircraft booking system
① A ticket office ( Business T1) Read the ticket balance of a flight A, set up A=16;
② B ticket counter ( Business T2) Read the ticket balance of the same flight A, Also for the 16;
③ A ticket office sells a ticket , Modify the balance A←A-1, therefore A by 15, hold A Write back to the database ;
④ B ticket office also sells a ticket , Modify the balance A←A-1, therefore A by 15, hold A Write back to the database
As a result, Ming Ming sold two tickets , The balance of air tickets in the database only decreases 1
This situation is called database inconsistency , Is caused by concurrent operations .
In the case of concurrent operations , Yes T1、T2 The scheduling of the operation sequence of two transactions is random .
If you execute according to the above scheduling sequence ,T1 The modification of the transaction is lost .
reason : The first 4 In step T2 Transaction modification A And write it back and overwrite it T1 Modification of transactions
Data inconsistency caused by concurrent operations
1. Missing changes (Lost Update)
2. It can't be read repeatedly (Non-repeatable Read)
3. read “ dirty ” data (Dirty Read)
mark
R(x): Reading data x
W(x): Writing data x
Missing changes
Two transactions T1 and T2 Read in the same data and modify ,T2 The submission of the results destroyed T1 Results submitted , Lead to T1 The modification of is lost .
The above example of plane booking is of this kind 
It can't be read repeatedly
Non repeatable reading refers to transactions T1 After reading data , Business T2 Perform an update operation , send T1 The previous read result cannot be reproduced .
Non-repeatable reads involve three situations :
(1) Business T1 After reading some data , Business T2 It was modified , When a transaction T1 When the data is read again , I get a different value than I did before
for example :
T1 Read B=100 Carry out operations
T2 Read the same data B, After modification, it will B=200 Write back to the database .
T1 In order to proofread the read value, reread B,B Already been 200, Inconsistent with the first read value
(2) Business T1 After reading some data records from the database under certain conditions , Business T2 Some of these records were deleted , When T1 When the data is read again under the same condition , Found that some records mysteriously disappeared .
(3) Business T1 After reading some data records from the database under certain conditions , Business T2 Some records were inserted , When T1 When the data is read again under the same condition , Some more records were found .
The latter two non repeatable phenomena are sometimes called phantom phenomena (Phantom Row)
read “ dirty ” data
read “ dirty ” The data refers to :
Business T1 Modify a data , And write it back to disk
Business T2 After reading the same data ,T1 It was withdrawn for some reason
At this time T1 The modified data is restored to the original value ,T2 The data read is not consistent with the data in the database
T2 The data we read is zero “ dirty ” data , That is, incorrect data
for example 
T1 take C Value is modified to 200,T2 Read C by 200
T1 To withdraw for some reason , Its modification is invalid ,C Restore original value 100
At this time T2 Read about C by 200, Inconsistent with database content , Namely “ dirty ” data
Data inconsistency : Because concurrent operations destroy the isolation of transactions
Concurrency control is to schedule concurrent operations in the right way , Enables the execution of a user transaction without interference from other transactions , So as to avoid data inconsistency
The application of databases sometimes allows some inconsistencies , For example, some statistical work involves a large amount of data , Read some “ dirty ” The data have no effect on the statistical accuracy , Consistency requirements can be reduced to reduce system overhead
The main technology of concurrency control
The blockade (Locking)
Time stamp (Timestamp)
Optimistic control
Multi version concurrency control (MVCC)
Welcome to join me for wechat exchange and discussion ( Please note csdn Add )
边栏推荐
- About the writing method of SQL field "this includes" and "included in" strings
- Cross end solutions to improve development efficiency
- AD637使用筆記
- Oracle检查点队列–实例崩溃恢复原理剖析
- oracle 控制文件的多路复用
- HDU 4391 Paint The Wall 段树(水
- Analyse des risques liés aux liaisons de microservices
- 华为快游戏调用登录接口失败,返回错误码 -1
- Create a virtual machine on VMware (system not installed)
- Installation of VMware Workstation
猜你喜欢

【愚公系列】2022年7月 Go教学课程 003-IDE的安装和基本使用

"Grain mall" -- Summary and induction

Ad637 notes d'utilisation

The real situation of programmers

Drawing HSV color wheel with MATLAB

深信服X计划-网络协议基础 DNS

The Blue Bridge Cup web application development simulation competition is open for the first time! Contestants fast forward!

A number of ventilator giants' products have been recalled recently, and the ventilator market is still in incremental competition
![[Yugong series] go teaching course 003-ide installation and basic use in July 2022](/img/9d/7d01bc1daa61f6545f619b6746f8bb.png)
[Yugong series] go teaching course 003-ide installation and basic use in July 2022

每日刷题记录 (十四)
随机推荐
Bitbucket installation configuration
crm创建基于fetch自己的自定义报告
About the writing method of SQL field "this includes" and "included in" strings
EBS Oracle 11g 克隆步骤(单节点)
Summarize the reasons for 2XX, 3xx, 4xx, 5xx status codes
HDU 4391 paint the wall segment tree (water
使用Aspect制作全局异常处理类
极狐公司官方澄清声明
总结出现2xx、3xx、4xx、5xx状态码的原因
GCC9.5离线安装
Oracle HugePages没有被使用导致服务器很卡的解决方法
MATLAB | App Designer·我用MATLAB制作了一款LATEX公式实时编辑器
Type of fault
Xlrd common operations
Emotional analysis of wechat chat records on Valentine's day based on Text Mining
阿里云有奖体验:用PolarDB-X搭建一个高可用系统
Regular expressions and re Libraries
大约SQL现场“这包括”与“包括在”字符串的写法
Code bug correction, char is converted to int high-order symbol extension, resulting in changes in positivity and negativity and values. Int num = (int) (unsigned int) a, which will occur in older com
Kingbasees v8r3 cluster maintenance case -- online addition of standby database management node