Slides10 Concurrency
Slides10 Concurrency
- Concurrence Control
Vũ Tuyết Trinh
Learning objectives
1
Outline
1. Transaction
2. ACID properties
3. Transaction Management Interface
4. Concurrence control
5. Isolation levels
Example
500USD
Account A Account B
read(A)
If A > 500 then
2
1. Transaction
• A sequence of read and write operations on data items that
logically functions as one unit of work
• Ensuring data integrity and correctness
500USD
Account A Account B
read(A)
If A > 500 then
B:=B+500
A:=A-500
5
2. ACID Properties
2.1. Atomicity
2.2. Consistency
2.3. Isolation
2.4. Durability
3
2.1. Atomicity
• Guarantee that either all of the tasks of a transaction are
performed or none of them are.
T: Read(A,t1);
If t1 > 500 {
Read(B,t2);
t2:=t2+500;
crash
Write(B,t2);
t1:=t1-500;
Write(A,t1);
}
2.2. Consistency
• Ensures that the DB remains in a consistent state before the
start of the transaction and after the transaction is over.
T: Read(A,t1); A+B = C
If t1 > 500 {
Read(B,t2);
t2:=t2+500;
Write(B,t2);
t1:=t1-500;
Write(A,t1);
} A+B = C
4
2.3. Isolation
• Ability of the application to make operations in a transaction
appear isolated from all other operations.
A= 5000, B= 3000
T: Read(A,t1);
If t1 > 500 {
Read(B,t2);
t2:=t2+500;
Write(B,t2); T’: A+B
t1:=t1-500; (= 5000+3500)
Write(A,t1); (A+B = 4500+3500)
}
9
2.4. Durability
• Guarantee that once the user has been notified of success, the
transaction will persist, and not be undone.
A= 5000, B= 3000
T: Read(A,t1);
If t1 > 500 {
Read(B,t2);
t2:=t2+500;
Write(B,t2);
t1:=t1-500;
Write(A,t1);
} crash
A= 4500, B=3500
10
10
5
3. Transaction Management Interface
11
11
12
12
6
3.1. Transaction States
• Active
• Begin Trans
• Commit ()
• Abort()
• Savepoint Save()
• Rollback (savepoint)
(savepoint = 0 ==> Abort)
13
13
4. Concurrent control
4.1. Objective
4.2. Scheduling
4.3. Lock
14
14
7
4.1. Objective
• Ensures that database transactions are performed concurrently without the
concurrency violating the data integrity.
• Guarantees that no effect of committed transactions is lost, and no effect
of aborted (rolled back) transactions remains in the related database.
• Example
15
15
4.2. Scheduling
16
8
4.2. Scheduling
17
17
4.3. Lock
18
18
9
4.3. Lock
• Example
19
19
4.3. Lock
• Example
20
20
10
5. Isolation levels
Set isolation level <level>
21
21
Summary
• Transaction
• Sequence of actions
• ACID
• Properties of a transaction
• Concurrence control
• Mechanism allows multiple transactions accessing the same resource
in the same time
• Isolation level
• Defining the level DBMS must ensure data integrity and correctness in
processing concurrent accesses
22
22
11