Professional Documents
Culture Documents
Transaction and Concurrency Control - Update
Transaction and Concurrency Control - Update
Concurrency Control
UNIT-4
-Navjot Kaur
What we will cover?
• Transaction system concepts
• Desirable properties of transactions
• Schedules
• Serializability of schedules
• Concurrency control
• Recoverability
Transaction Processing Systems
A
Write (1) 5000 to 7000
Atomicity requirement
– if the transaction fails after step 3 and before step 6, money will be
“lost” leading to an inconsistent database state
– the system should ensure that updates of a partially executed
transaction are not reflected in the database
Durability requirement — once the user has been notified that the
transaction has completed (i.e., the transfer of the $50 has taken
place),
the updates to the database by the transaction must persist even if
there are software or hardware failures
Transaction Properties: Example
Consistency requirement:
– the sum of A and B is unchanged by the execution of the
transaction
In general, consistency requirements include
• primary keys and foreign keys
• Implicit integrity constraints
• A transaction must see a consistent database.
• During transaction execution the database may be temporarily
inconsistent.
• When the transaction completes successfully the database must be
consistent
– Erroneous transaction logic can lead to inconsistency
Transaction Properties: Example
Isolation requirement
— if between steps 3
and 6, another
transaction T2 is
allowed to access the
partially updated
database, it will see an
inconsistent database
(the sum A + B will be
less than it should be).
Transaction Properties: Example
Isolation can be ensured by running transactions serially
– that is, one after the other.
Durable: Once database has committed a transaction, the changes made by the
transaction should be permanent.
e.g. if a person has credited $50000 to his account, bank cant say that the
update has been lost.
2. Serial Schedule
Each schedule consists of a sequence of instructions from various
transactions where the instructions belonging to one single transaction
appear together in that schedule.
Schedule Types
2. Serial Schedule
If transactions are executed from start to finish, one by one then that
schedule is called Serial Schedule.
T1 T2
A=A+100
B=B-100
A=A*2.8
B=B*2.8
Schedule Types
3. Non-Serial Schedule
A schedule in which the operations from a set of concurrent transactions
are interleaved.
T1 T2
A=A+100
A=A*2.8
B=B-100
B=B*2.8
Schedule Types
4. Equivalent Schedule
Effect of execution of one schedule is identical to second.
5. Serializable Schedule
A non-serial schedule that is equivalent to some serial execution of
transactions is called serializable schedule
Conflict of operations
• The order of read/write operations in a schedule can be changed depending
upon the data objects they related to, but sometimes orders cant be
changed.
1. If two transactions only read, they do not conflict and the order is not
important
2. If two transactions read/write completely separate data objects, they
don’t conflict and order is not important
3. If one transaction writes a data object and another either reads or writes
the same data object, the order of execution is important.
Conflict of operations
• There are some rules to define conflict operations:
1. If two transactions only read, they do not conflict and the order is not
important
2. If two transactions read/write completely separate data objects, they
don’t conflict and order is not important
3. If one transaction writes a data object and another either reads or writes
the same data object, the order of execution is important.
Conflicting Instructions
T1 T2
R(A)
W(A)
R(A)
R(B)
W(A)
W(B)
R(B)
W(B)
T1 T2 T1 T2
R(A) R(B)
W(A) W(B)
R(B) R(A)
W(B) W(A)
Conflict Serializability
T1 T2 T1 T2
A=A+100 A=A+100
A=A*7.06 B=B-100
B=B-100 A=A*7.06
B=B*7.06 B=B*7.06
Examples: Schedule 1
• Let T1 transfer $50 from A to B, and T2 transfer 10% of the balance from A to B.
• A serial schedule in which T1 is followed by T2 :
A= 1000
B=2000
Schedule 2
• A serial schedule where T2 is followed by T1
Schedule 3
Schedule 3 Schedule 1
Schedule 4
T1 T2
R(X)
R(X)
Performed some operation
W(X)
R(X)
Phantom Read Problem
Reading an
attribute which
does not exists
T1 T2
R(X)
R(X)
Delete X
R(X)
Not read any
Lost Update Problem value. We call it
as blind write
T1 T2
R(A) Which value
this
W(A)
transaction is
W(A) writing?
Commit
Commit
Question
In a dirty read problem …….