当前位置:网站首页>Granularity of blocking of concurrency control
Granularity of blocking of concurrency control
2022-07-05 21:59:00 【Short section senior】
The size of the blocking object is called blocking granularity (Granularity)
Blocked objects : Logical unit , Physical unit
example : In a relational database , Block the object :
Logical unit : Property value 、 A collection of attribute values 、 Tuples 、 Relationship 、 Index entry 、 The whole index 、 The whole database, etc
Physical unit : page ( Data page or index page )、 Physical records, etc
Choose the principle of blocking granularity
Blocking granularity is closely related to the concurrency of the system and the overhead of concurrency control .
The greater the granularity of the blockade , The fewer data units a database can block , The less concurrency , The lower the system overhead ;
The smaller the size of the blockade , High concurrency , But the more overhead there is
example
If blocking granularity is data page , Business T1 Tuples need to be modified L1, be T1 Must include L1 The entire data page A Lock . If T1 Yes A After lock transaction T2 To be modified A Zhongyuan group L2, be T2 Forced to wait , until T1 Release A.
If the blocking granularity is tuple , be T1 and T2 Can be right at the same time L1 and L2 Lock , There's no need to wait for each other , The parallelism of the system is improved .
And so on , Business T You need to read the entire table , If blocking granularity is tuple ,T Every tuple in the table must be locked , It costs a lot
Multi granularity blocking (Multiple Granularity Locking)
Multiple blocking granularity are supported in one system for different transaction choices
Select block granularity
Consider both blocking overhead and concurrency , Select appropriate blocking granularity
User transactions that need to handle a large number of tuples of multiple relationships : Take the database as the blocking unit
User transactions that need to handle a large number of tuples : Take the relationship as the blocking unit
Handle user transactions with only a small number of tuples : In tuples
Multi granularity blocking
Multi granularity tree
Multi level blocking granularity is represented by tree structure
The root node is the entire database , Represents the maximum data granularity
Leaf nodes represent the smallest data granularity
example : Three level granularity tree . The root node is the database , The child nodes of the database are relationships , The child node of the relationship is tuple .
Multi granularity blocking protocol
Allow each node in the multi granularity tree to be locked independently
Locking a node means that all descendant nodes of the node are also locked of the same type
In multi granularity blocking, a data object may be blocked in two ways : Explicit blocking and implicit blocking
Explicit blocking and implicit blocking
Explicit blocking : A block directly added to a data object
Implicitly block : The data object is not locked independently , The data object is locked because its parent node is locked
Explicit blocking has the same effect as implicit blocking
When the system checks for blocking conflicts
To check for explicit blocking
Also check for implicit blocking
Such as transaction T To the relationship R1 Add X lock
The system must search its parent node database 、 Relationship R1
And search R1 Child node of , namely R1 Every tuple in
If one of the data objects has an incompatible lock , be T Must wait
Lock a data object , The system needs to be checked
The data object
Whether there is an explicit blockade conflict with it
All parent nodes
Check whether the explicit blocking of this transaction conflicts with the implicit blocking on the data object :( Caused by the blockade added by the parent node )
All child nodes
See whether the above explicit blocking is different from the implicit blocking of this transaction ( The block that will be added to the child node ) Conflict
Intent locks
Introduction of intention lock (intention lock) Purpose
Improve the efficiency of system checking when a data object is locked
If you add intention lock to a node , It means that the lower node of the node is being locked
Add a basic lock to any node , You must first add intention lock to its upper node
for example , When locking any tuple , You must first add an intentional lock to the database and relationship it is in
Common intention locks
Intention sharing lock (Intent Share Lock, abbreviation IS lock )
Intention exclusive lock (Intent Exclusive Lock, abbreviation IX lock )
Sharing intention exclusive lock (Share Intent Exclusive Lock, abbreviation SIX lock )
IS lock
If you add... To a data object IS lock , Represents its descendant node ( Intention ) Add S lock .
for example : Business T1 Right R1 Add... To a tuple in S lock , First of all, the relationship R1 And database plus IS lock
IX lock
If you add... To a data object IX lock , Represents its descendant node ( Intention ) Add X lock .
for example : Business T1 Right R1 Add... To a tuple in X lock , First of all, the relationship R1 And database plus IX lock
SIX lock
If you add... To a data object SIX lock , To add to it S lock , add IX lock , namely SIX = S + IX.
example : Add... To a watch SIX lock , It means that the transaction needs to read the whole table ( So add S lock ), Individual tuples are also updated ( So add IX lock ).
Consistency matrix of intention lock
The strength of the lock
The strength of a lock is its rejection of other locks
It is safe for a transaction to replace weak lock with strong lock when applying for blocking , Otherwise
Multi granularity blocking method with intention lock
When applying for a blockade, it should be done in a top-down order
The release of the blockade should be done in a bottom-up order
for example : Business T1 To the relationship R1 Add S lock
First, add... To the database IS lock
Check the database and R1 Whether incompatible locks have been added (X or IX)
No more searching and checking R1 Whether the tuples in are locked with incompatible locks (X lock )
Multi granularity blocking method with intention lock
It improves the concurrency of the system
Reduce the cost of locking and unlocking
It is widely used in practical database management system products
Welcome to join me for wechat exchange and discussion ( Please note csdn Add )
边栏推荐
- HYSBZ 2243 染色 (树链拆分)
- Database tuning solution
- How can Huawei online match improve the success rate of player matching
- Decorator learning 01
- database mirroring
- Dbeaver executes multiple insert into error processing at the same time
- How to view Apache log4j 2 remote code execution vulnerability?
- ESP32
- Create a virtual machine on VMware (system not installed)
- 他们主动布局(autolayout)环境的图像编辑器
猜你喜欢
Implementation technology of recovery
2.2 basic grammar of R language
R language learning notes
怎么利用Tensorflow2进行猫狗分类识别
Decorator learning 01
总结出现2xx、3xx、4xx、5xx状态码的原因
Xlrd common operations
Efficiency difference between row first and column first traversal of mat data types in opencv
MySQL连接断开报错MySQLdb._exceptions.OperationalError 4031, The client was disconnected by the server
QML reported an error expected token ";", expected a qualified name ID
随机推荐
The solution to the problem that Oracle hugepages are not used, causing the server to be too laggy
Interprocess communication in the "Chris Richardson microservice series" microservice architecture
使用Aspect制作全局异常处理类
Installation of VMware Workstation
ESP32
Defect detection - Halcon surface scratch detection
SQL common syntax records
AD637 usage notes
EBS Oracle 11g 克隆步骤(单节点)
Evolution of large website architecture and knowledge system
GCC9.5离线安装
How to add new fields to mongodb with code (all)
PIP install beatifulsoup4 installation failed
The Blue Bridge Cup web application development simulation competition is open for the first time! Contestants fast forward!
Database recovery strategy
SQL knowledge leak detection
ICMP introduction
微服务入门(RestTemplate、Eureka、Nacos、Feign、Gateway)
让开发效率提升的跨端方案
【愚公系列】2022年7月 Go教学课程 004-Go代码注释