当前位置:网站首页>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 )
边栏推荐
- 【愚公系列】2022年7月 Go教学课程 003-IDE的安装和基本使用
- 使用Aspect制作全局异常处理类
- Gcc9.5 offline installation
- MMAP
- Advantages of robot framework
- Summary of data analysis steps
- Dbeaver executes multiple insert into error processing at the same time
- Kingbasees v8r3 cluster maintenance case -- online addition of standby database management node
- 2.2.3 output of documents
- 大约SQL现场“这包括”与“包括在”字符串的写法
猜你喜欢
Li Kou ----- the maximum profit of operating Ferris wheel
1.2 download and installation of the help software rstudio
MMAP
Oracle checkpoint queue - Analysis of the principle of instance crash recovery
MMAP
华为联机对战如何提升玩家匹配成功几率
PIP install beatifulsoup4 installation failed
Implementing Lmax disruptor queue from scratch (IV) principle analysis of multithreaded producer multiproducersequencer
KingbaseES V8R3集群维护案例之---在线添加备库管理节点
使用Aspect制作全局异常处理类
随机推荐
K210 learning notes (IV) k210 runs multiple models at the same time
Environment configuration problem record
Kingbasees v8r3 cluster maintenance case -- online addition of standby database management node
递归查询多级菜单数据
2.2.5 basic sentences of R language drawing
Sitge joined the opengauss open source community to jointly promote the ecological development of the database industry
Deeply convinced plan X - network protocol basic DNS
CRM creates its own custom report based on fetch
An exception occurred in Huawei game multimedia calling the room switching method internal system error Reason:90000017
大约SQL现场“这包括”与“包括在”字符串的写法
Implementing Lmax disruptor queue from scratch (IV) principle analysis of multithreaded producer multiproducersequencer
POJ 3237 tree (tree chain splitting)
DataGrid directly edits and saves "design defects"
微服务入门(RestTemplate、Eureka、Nacos、Feign、Gateway)
Scenario interview: ten questions and ten answers about distributed locks
使用Aspect制作全局异常处理类
Reptile practice
Sorting out the problems encountered in MySQL built by pycharm connecting virtual machines
datagrid直接编辑保存“设计缺陷”
How to use tensorflow2 for cat and dog classification and recognition