当前位置:网站首页>Blocking protocol for concurrency control
Blocking protocol for concurrency control
2022-07-05 21:59:00 【Short section senior】
What is a blockade agreement
Using X Lock and S When locking data objects , Some rules need to be agreed , These rules are blocking agreements (Locking Protocol).
When to apply for X Lock or S lock
Holding time
When to release
There are different rules for the way of blockade , There are different kinds of blockade agreements , They provide a certain guarantee for the correct scheduling of concurrent operations to varying degrees .
Three level blockade agreement
1. First level blockade protocol
2. Secondary blockade protocol
3. Three level blockade agreement
First level blockade protocol
First level blockade protocol
Business T Modifying data R It must be added before X lock , Not released until the end of the transaction .
Normal end (COMMIT)
Abnormal end (ROLLBACK)
The first level blocking protocol can prevent the loss of modification , And make sure that things T It's recoverable .
In the first level blockade agreement , If you just read the data and don't modify it , It doesn't need to be locked , So it's not guaranteed to be repeatable or unreadable “ dirty ” data .
Use blocking mechanism to solve the problem of lost modification

No changes lost
Business T1 reading A Make changes to A Add X lock
When T2 Ask again for A Add X Lock rejected
T2 Can only wait for T1 Release A Get the right after locking on A Of X lock
At this time T2 Read about A It's already T1 Updated value 15
T2 Click here to the new A Value is calculated , And the result value A=14 Write back to disk . Avoid losing T1 Update .
Secondary blockade protocol
Secondary blockade protocol
First level blocking protocol plus transactions T Reading data R It must be added before S lock , After reading, you can release S lock .
The secondary blocking protocol can prevent loss, modification and reading “ dirty ” data .
In the secondary blockade agreement , Because the data can be released after reading S lock , So it's not guaranteed to be repeatable .
Use the blocking mechanism to solve the read problem “ dirty ” Data problems

Do not read “ dirty ” data
Business T1 In the face of C Before making changes , First pair C Add X lock , Modify its value and write it back to disk
T2 Request in C add S lock , because T1 Already in C Added X lock ,T2 Can only wait for
T1 Be revoked for some reason ,C Restore to original value 100
T1 Release C Upper X After locking T2 get C Upper S lock , read C=100. Avoided T2 read “ dirty ” data
Three level blockade agreement
Three level blockade agreement
First level blocking protocol plus transactions T Reading data R It must be added before S lock , Not released until the end of the transaction .
The three-level blocking protocol can prevent loss and modification 、 Read dirty data and non repeatable data .
Use blocking mechanism to solve the problem of non repeatable reading

Repeatable
Business T1 reading A,B Before , First pair A,B Add S lock
Other affairs can only be right again A,B Add S lock , Instead of X lock , That is, other transactions can only read A,B, It can't be modified
When T2 To modify B And the application is right B Of X When the lock is rejected, you can only wait T1 Release B The lock on the
T1 Read again for checking A,B, Now read B Is still 100, The sum result is still 150, Can be read repeatedly
T1 Release at the end A,B Upper S lock .T2 To get the right B Of X lock
Summary of blockade agreement
The main differences between three-level agreements
What operations need to be blocked and when to release the lock ( That is, lock holding time )
Different blocking protocols make transactions reach different consistency levels
The higher the level of blockade agreement , The more consistent 
Welcome to join me for wechat exchange and discussion ( Please note csdn Add )
边栏推荐
- Getting started with microservices (resttemplate, Eureka, Nacos, feign, gateway)
- Dbeaver executes multiple insert into error processing at the same time
- Sitge joined the opengauss open source community to jointly promote the ecological development of the database industry
- Analysis and test of ModbusRTU communication protocol
- The real situation of programmers
- 华为快游戏调用登录接口失败,返回错误码 -1
- Regular expressions and re Libraries
- ESP32
- Image editor for their AutoLayout environment
- 资深电感厂家告诉你电感什么情况会有噪音电感噪音是比较常见的一种电感故障情况,如果使用的电感出现了噪音大家也不用着急,只需要准确查找分析出什么何原因,其实还是有具体的方法来解决的。作为一家拥有18年品牌
猜你喜欢

The real situation of programmers

极狐公司官方澄清声明

场景化面试:关于分布式锁的十问十答

Recursive query of multi-level menu data

A number of ventilator giants' products have been recalled recently, and the ventilator market is still in incremental competition

Making global exception handling classes with aspect

Ethereum ETH的奖励机制

MMAP

Summarize the reasons for 2XX, 3xx, 4xx, 5xx status codes

Countdown to 92 days, the strategy for the provincial preparation of the Blue Bridge Cup is coming~
随机推荐
A long's perception
Environment configuration problem record
大约SQL现场“这包括”与“包括在”字符串的写法
About the writing method of SQL field "this includes" and "included in" strings
多家呼吸机巨头产品近期被一级召回 呼吸机市场仍在增量竞争
装饰器学习01
"Chris Richardson microservices series" uses API gateway to build microservices
Evolution of large website architecture and knowledge system
854. String BFS with similarity K
MMAP学习
Regular expressions and re Libraries
Countdown to 92 days, the strategy for the provincial preparation of the Blue Bridge Cup is coming~
oracle 控制文件的多路复用
【愚公系列】2022年7月 Go教学课程 003-IDE的安装和基本使用
Sorting out the problems encountered in MySQL built by pycharm connecting virtual machines
Multiplexing of Oracle control files
Kingbasees v8r3 data security case - audit record clearing case
How to use tensorflow2 for cat and dog classification and recognition
Oracle检查点队列–实例崩溃恢复原理剖析
PIP install beatifulsoup4 installation failed