Concurrency Control Flashcards
What are the 3 parts to Concurrency Control?
Transactions, Locks, Concurrent processing
What are transactions?
- Definition: A logical unit of work that must be completed in its entirety or be aborted - A transaction is created every time you read from and/or write to a database - Many transactions consist of two or more database requests - A transaction that changes the contents of the database must alter the database from one consistent state to another - A consistent database state is one in which all integrity constraints are satisfied
What are the transaction Properties?
All transactions must adhere to the ACID rules: - Atomicity - Consistency - Isolation - Durability
What is atomicity?
Either the effects of all or none of its operations remain when a transaction is completed (committed or aborted respectively) - In other words, to the outside world a committed transaction appears to be indivisible, atomic - A transaction is a unit of work that appears as if it is either performed in its entirety, or not performed at all (“all or nothing” semantics)
What is consistency?
Every transaction must leave the database in a consistent state, i.e., maintain the predetermined integrity rules of the database –All constraints (Entity, Domain and Referential Integrity) must be satisfied with each update - A transaction must transform a database from one consistent state to another consistent state
What is isolation?
Transactions cannot interfere with each other - The effects of an incomplete transaction are not visible to another transaction –A lock guarantees exclusive use of a data item to a current transaction - Providing isolation is the main goal of concurrency control
What is durability?
Effects of successful (committed) transactions must persist through crashes or system failure - Typically by recording the transaction’s effects and its commit event in a non-volatile memory (disk)
What is Concurrent Processing?
The co-ordination of simultaneous execution of transactions in a multi-processing database system - To ensure serializability of transactions–Execution of transactions in the correct sequence
What is concurrency control?
Need to avoid data integrity and consistency problems – Lost update •one record simultaneously updated by two different users –Uncommitted data •Two concurrent transactions, the first is rolled back after the second has accessed the uncommitted data, violating isolation property –Inconsistent retrievals •One transaction is executing calculations on a set of data while a second transaction is updating the same data
What are Locks?
- Guarantee exclusive use of a data item to a current transaction • Released when transaction is committed • Managed by a lock manager • Lock levels: –Database –Table –Page –Row –Field
What is the Two Phase Locking Protocol (2PL)
- Defines how transactions acquire and release locks • Guarantees serializability • Does not prevent deadlocks • Two phases –Growing phase: a transaction acquires all required locks, without unlocking any data, until lock point –Shrinking phase: a transaction releases all locks and cannot obtain any new lock
What are the 2PL Protocol Rules?
- Two transactions cannot have conflicting locks
- No unlock operation can precede a lock operation in the same transaction
- No data are affected until all locks have been obtained
What are the different Lock modes?
Shared lock
–One user asks to read a record
– Other users may read it
– No user can update it
Update lock
– Temporary state before Exclusive lock
Exclusive lock
– One user asks to modify a record
– No other user can read it or modify
What is a Deadlock?
A DeadLock - AKA “The Deadly Embrace”
• Occurs when two transactions wait for each other to unlock data
– T1 obtains a lock on X
– T2 obtains a lock on Y
– T1 requests a lock on Y
– T2 requests a lock on X
• Only exists with exclusive lock
How can you control posisble deadlocks?
• Prevention
– Transaction is aborted and rescheduled if possibility of deadlock exists
• Detection
– If a deadlock is found, one transaction is aborted (rolled back) and rescheduled while the other continues
• Avoidance
– Obtain all locks, in succession, before executing
– increase action response times
• Recommendations:
– Low probability: detection
– High probability: prevention
– Use avoidance where response time is a low priority