Transactions and Concurrency Control: Lecturer: Assistant Pro. Aslamzai Prepared By: Nazifa Kazimi Attendance #: 41
Transactions and Concurrency Control: Lecturer: Assistant Pro. Aslamzai Prepared By: Nazifa Kazimi Attendance #: 41
Transactions and
Concurrency Control (CH16)
Lecturer: Assistant pro. Aslamzai
• Isolation: Only one transaction at a time. If two transaction have same output
when they execute in isolation and in concurrency, then we can say that they
enjoy isolation.
Or if two or more transactions are not effected by each other while they are
running concurrently, we can say that they are in isolation.
Concurrency control is a module which takes care of isolation.
6
ACID continue…
• Durability: changes must be committed to DB irrespective of hardware and
software failure. Recovery Management component take cares of Durability.
• Distributes transaction:
Transaction which is
Initiated in one site and
Can update or access
Multiple sites.
9
Distributed Transaction example
• Atomicity is
Important
feature
In distribute
Transaction
Too.
10
Distributed Transaction example
• Atomicity is
Important
feature
In distribute
Transaction
Too.
Two phase commit 11
12
Transaction state and lifetime
13
Transaction state and lifetime
• Active: until and unless a transaction is in execution.
• Failure: when a transaction is executing, if there occur some failure
You can not continue with normal execution. You automatically switch to failure
state.
• Partially committed: whatever changes the transaction has done, are properly
executed but they are still stored in local buffer in main memory.
• Committed: if you are in partially committed sate and you are sure you done
everything correctly, then you go to committed state. When switching in this
state database will be updated according to your changes.
14
Continue…
• Failure: when the system face to failures.
• Aborted state: when the transaction face to some failure, you can go to aborted
state. In this state all changes will be cleared because the changes are still in local
buffer.
• Tip: Either you committed or aborted, in both case the system is in consistent
state
15
Why should we have multiple transaction?
Advantages of concurrency:
• Waiting time
• Response time
• Resource utilization
• Efficiency
Serial Schedule
Non-Serial Schedule
20
Concurrency Control
• Concurrency control: is the process of managing simultaneous execution of
transactions in shared database, to ensure the serializability of transactions.
Read Write
Read Shared Exclusive
Write Exclusive Exclusive
22
Simple locking scheme
• Simple locking: lock before you access, Release after you access.
Lock Types:
1. Shared/Read lock------- lock-s(x)
2. Exclusive/Write/Read lock-------lock-x(x)
23
Transaction failure
1. System failure or system crash
2. Transaction or system error
3. Concurrency control enforcement: assume in when deadlock occurs,
in order to control concurrency, the system will enforce one transaction
to fail
4. Local errors or exceptions
5. Disk failure
24
Recoverable and Non-Recoverable
Recoverable: means that if we can go to previous stable state while we face to
failure.
Recoverable
25
Deadlock
• A system is in a deadlock state if there exists a set of transactions such
that every transaction in the set is waiting for another transaction in
the set.
26
Necessary condition in Deadlock
• Hold and Wait
• Mutual Exclusion
when T1 has non-sharable lock and T2 request for it.
• No preemption
Means you are done with transaction but you are still holding lock.
• Circular waiting