Download presentation
Presentation is loading. Please wait.
Published byFranklin Marshall Modified over 8 years ago
1
Academic Year 2014 Spring Academic Year 2014 Spring
2
MODULE CC3005NI: Advanced Database Systems “DATABASE CONCURRENCY” (PART – 2) Academic Year 2014 Spring Academic Year 2014 Spring
3
We have seen that how locking can be applied to solve the three basic concurrency problems identified. However, it has been shown that locking can lead to problems of its own: DEADLOCK Deadlock:
4
A system is in a state of Deadlock if there exists a set of transactions such that every transaction in the set is waiting for another transaction in the set. or wait Deadlock is a situation in which two or more transactions are in a simultaneous wait state, each of them waiting for one of the others to release a lock before it can proceed. Deadlock Problem:
5
Where p1 and p2 are data items At time t4, both transactions A and B are deadlocked and neither is able to proceed any further Deadlock Problem - Example:
6
Two main methods for deadlock handling Deadlock Prevention o This method is used to ensure that the system will never enter a deadlock state. Deadlock Detection and Recovery o This allows the system to enter a deadlock state then attempts to recover from it using a deadlock detection and recovery scheme. Both methods may result in transaction rollback and both incur overheads. Deadlock Handling:
7
Each transaction locks all its required data items before it begins execution. Either all data items needed are locked in one step (so the transaction can then proceed) or none are locked (to avoid locking only some of the data items needed) This scheme could be used if the probability of the system entering a deadlock state is relatively high ( for example; for long transactions needing many locks) Deadlock Prevention Scheme:
8
Disadvantages of the scheme Low data utilisation o Some data items could be locked for a long time before they are used. Possible starvation o A transaction which requires a number of data items may find itself in a indefinite wait state while at least one of the data items is always locked by some other transactions. Note that there are other deadlock prevention schemes. Deadlock Prevention Scheme:
9
Basic Idea: The state of the system is examined periodically to detect whether a deadlock has occurred in the system If it has, the system attempts to recover from the deadlock (often involving rollback) This scheme is commonly used if the deadlock probability in the system is relatively low (for example; for short transactions needing only a few data items) Deadlock Detection & Recovery:
10
General Procedure: Maintain information about the current allocation of data items to different transactions – namely, locks that have been granted Maintain information about any outstanding requests for data items – namely locks that have been requested but not granted yet. Deadlock Detection & Recovery:
11
Activate an algorithm (periodically or when required) which uses the above information to determine whether the system has entered a deadlock state If a deadlock state is entered (which may involve more than one deadlock), the system attempts to recover from the deadlock – namely, breaking the deadlock. Deadlock Detection & Recovery:
12
A Wait For Graph (WFG) can be used to detect a deadlock – a graph of ‘who is waiting for whom’. WFG is a direct graph G = (N,E) which consists of a set of nodes N and a set of edges E Create a node for each transaction Create a directed edge Ti Tj, if transaction Ti is waiting to lock an item which currently locked by Tj When Tj releases the lock(s) on the items which Ti was waiting for, the directed edge is removed from the graph Deadlock exists if and only if the WFG contains a cycle Deadlock Detection – WFG:
13
No Deadlock Yes Deadlock Deadlock Detection – WFG:
14
The question of when and how often the detection algorithm (e.g. WFG) should be invoked into action depends on several factors, including The number of transactions running in the system The waiting time of transactions The frequency of deadlock occurrences etc. Timing for Detection:
15
Assumption: The following list represents the sequence of event in an interleaved execution of a set of transactions T1, T2, … T7 in a concurrency system based on locking, where A, B, …. F are data items. Assume that FETCH A acquires an S lock on A, UPDATE A promotes that lock to an X lock, and all locks are held to the next synchpoint Question: Provide a Wait–for–Graph to determine whether there is a deadlock at time t17 and if so how the system could recover from the deadlock. A working example of WFG:
18
After a deadlock situation has been identified, the system must try to recover from it. The most common solution is to rollback one or more transactions involved in the deadlock, so that deadlock can be broken Three issues to be addressed in deadlock recovery Issue of choosing a victim Issue of rollback operation Issue of Starvation Deadlock Recovery:
19
1. Issue of choosing a victim Determine which transaction(s), among a set of deadlocked transactions, to be rolled back in order to break the deadlock. Criteria for choosing such a victim transaction often depends on cost factors. 2. Issue of Rollback operation Determine how far the chosen victim transaction should be rolled back (total rollback or partial rollback) Deadlock Recovery – 3 Issues:
20
3. Issue of starvation Avoid situations where some transaction may always be chosen as the victim due to cost factors based selection, hence never completing its job. Deadlock Recovery – 3 Issues:
21
Thank you!!! Questions are WELCOME Academic Year 2014 Spring Academic Year 2014 Spring
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.