当前位置:网站首页>Shared lock, exclusive lock, mutex lock, pessimistic lock, optimistic lock, row lock, table lock, page lock, non repeatable read, lost modification, read dirty data
Shared lock, exclusive lock, mutex lock, pessimistic lock, optimistic lock, row lock, table lock, page lock, non repeatable read, lost modification, read dirty data
2022-07-24 08:06:00 【Small source】
Catalog
Pessimistic locking 、 Optimism lock :
Four conditions for deadlock generation :
Shared lock (S lock ):
Also known as read lock , A data lock that can be viewed but cannot be modified or deleted . If the transaction T Data pair A After adding the shared lock , Then other affairs can only be for A Add shared lock , You can't lock it . Transactions that are allowed to share locks can only read data , Can't modify data . Under the shared lock, other users can read concurrently , Query data . But it can't be modified , increase , Delete data . Resource sharing .
Exclusive lock (X lock ):
Also known as write lock 、 An exclusive lock , If business T For data objects A add X lock , Only T Read and modify A, Nothing else can be right A Add any type of lock , until T Release A The lock on the . This ensures that other things are T Release A The lock on can't be read or modified before A
The mutex :
In programming , The concept of object mutex is introduced , To ensure the integrity of shared data operations . Each object corresponds to a can be called " The mutex " The tag , This sign is used to guarantee that at any moment , Only one thread can access the object .
Pessimistic locking 、 Optimism lock :
Pessimistic locking : Always assume the worst , Every time I go to get the data, I think others will modify it , So every time I get the data, I lock it , So people who want to take this data will block it until it gets the lock . There are many lock mechanisms used in traditional relational databases , For example, line locks. , Table lock, etc. , Read the lock , Write locks, etc. , It's all locked before the operation . Another example Java Synchronization primitives inside synchronized The realization of key words is also pessimistic lock .
Optimism lock : seeing the name of a thing one thinks of its function , Is very optimistic , Every time I go to get the data, I think other people won't modify it , So it won't lock , But in the process of updating, we will judge whether other people have updated this data during this period , You can use mechanisms like version numbers . Optimistic lock is suitable for multi read applications , This can improve throughput , Similar to what the database provides write_condition Mechanism , In fact, they are all optimistic locks . stay Java in java.util.concurrent.atomic The atomic variable class under the package is an implementation of optimistic lock CAS Realized .
Row-level locks :
The line lock is MySQL The lock with the finest granularity , Indicates that only the row of the current operation is locked . Row level lock can greatly reduce the conflict of database operation , The lock granularity is the smallest , But locking costs the most . Row level lock is divided into shared lock and exclusive lock . Spending big , Lock the slow ; A deadlock occurs ; Locking granularity minimum , The lowest probability of lock collisions , The highest degree of concurrency .
Table lock :
The watch lock is MySQL The lock with the largest granularity , Indicates to lock the whole table of the current operation , It's easy to implement , Less resource consumption , By most MySQL Engine support . Most commonly used MyISAM And InnoDB Table level locking is supported . Table level locks are divided into table shared read locks ( Shared lock ) Write lock exclusive to table ( Exclusive lock ). Low overhead , Locked fast ; A deadlock will not occur ; Large locking size , The highest probability of lock conflict is , Lowest degree of concurrency .
Page level lock :
Page level lock is MySQL A lock whose granularity is between row level lock and table level lock . The watch lock is fast , But there are many conflicts , Less line level conflict , But the speed is slow. . therefore , Take a compromise page level lock , Lock an adjacent set of records at a time .BDB Support page level lock . Cost and lock time are between table lock and row lock ; A deadlock occurs ; Lock granularity is between table lock and row lock , The concurrency is average .
Missing changes :
Refers to affairs 1 And transaction 2 Read in the same data and modify it at the same time , Business 2 The result of the commit destroys the transaction 1 Results submitted , Cause transaction 1 Changes made are missing .
It can't be read repeatedly :
A time after a transaction reads some data , Read the previously read data again , But the data they read has changed 、 Or some records have been deleted !
Read dirty data :
Business T1 Modify a data , And write it back to disk , Business T2 After reading the same data ,T1 Revoked 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 , be T2 The data we read is zero " dirty " data , That is, incorrect data .
Deadlock :
Two or more processes in execution , A blocking phenomenon caused by competition for resources or communication with each other , If there is no external force , They will not be able to move forward . At this point, the system is said to be in a deadlock state or the system has produced a deadlock , These processes that are always waiting for each other are called deadlock processes
Four conditions for deadlock generation :
1) mutual exclusion : Refers to the exclusive use of resources allocated by the process , That is, a resource is occupied by only one process in a period of time . If there are other processes requesting resources at this time , Then the requester can only wait , Until the process of taking possession of resources is completed and released .
2) Request and hold conditions : Means that the process has kept at least one resource , But new resource requests were made , And the resource has been occupied by other processes , The request process is blocked , But keep up with other resources .
3) Conditions of non deprivation : Refers to the resources obtained by the process , Before use , Can't be deprived of , It can only be released by itself after use .
4) Loop waiting condition : When a life and death lock is issued , There must be a process —— Circular chain of resources , That is, process set {P0,P1,P2,···,Pn} Medium P0 Waiting for one P1 Occupied resources ;P1 Is waiting for P2 Occupied resources ,……,Pn Waiting for has been P0 Occupied resources .
End of the flower !!!
Friends, this is the end of our article , The content of this article is still very simple , If there are any friends who can't, we can talk together ~
If your friends feel that the content of the article is helpful to you , Sure give the thumbs-up , Follow articles and columns as well as Pay attention to me , Hey, hey, I'll update the article regularly , Thank you for your support !
边栏推荐
- P3916图的遍历 题解
- Project practice - document scanning OCR recognition
- 学习笔记总结篇(一)
- Intelligent robots and intelligent systems (Professor Zhengzheng of Dalian University of Technology) -- 3. Industrial robots
- 33-SparkSql的介绍、DataFrame和DataSet
- 13. Unity2d horizontal version of two-way platform that can move up, down, left and right (two-way walking + movable + independent judgment) + random platform generation
- Common DOS commands
- 【MATLAB】(三)MATLAB在高等数学中的应用
- Collection of sorting topics
- Starting from scratch C language intensive Part 3: Functions
猜你喜欢

The vision group of Hegong University Sky team trained Day1 - machine learning, and learned to use the Yolo model

Generative model and discriminant model

*Code understanding * common function parsing in pytoch

Kotlin coprocess analysis (III) -- understanding the context of coprocess

MySQL 啥时候用表锁,啥时候用行锁?

Hcip day 7
![[matlab] (IV) application of MATLAB in linear algebra](/img/c8/97fddb4105008990173247b1b4a155.png)
[matlab] (IV) application of MATLAB in linear algebra

Learning to track at 100 FPS with deep progression networks
![[target detection] IOU (intersection and combination ratio)](/img/16/d1bd89582e0e04a627e7909eb4f31d.png)
[target detection] IOU (intersection and combination ratio)

Learning dynamic Siamese network for visual object tracking full text translation
随机推荐
Opencv project - credit card recognition (learning record)
Vertex buffer and shader (the cherno + leranopongl) notes
Uva572 oil deposits problem solution
Introduction of some functions or methods in DGL Library
SIFT feature point extraction
Semantic slam: Probabilistic Data Association for semantic slam
Kotlin coroutine (I): foundation and deepening
[MySQL] installation tutorial and master-slave configuration
Thesis reading: geotransformer
Detailed notes on pytoch building neural network
MS SQL Server 2019 learning
CNN-VINS
My six months at Microsoft
Database system - Basic Concepts
Learn - use do... While loop according to the formula e=1+1/1+ 1/2!+ 1/3!+…+ 1/n! Calculate the value of E (accuracy is 1e-6)
Digital twin demonstration project -- Talking about simple pendulum (2) vision exploration and application scenarios
NFT概念究竟是怎么回事。。全面了解NFT市场、技术和案例
EZDML逆向工程导入数据库分析实操教程
Qt|字符串生成二维码功能
Debug No1 summarizes common solutions to bugs