Concurrency Control (lecture 10)
Part 1: Concurrent Transactions and need for Locks
Concurrent transactions are faster.
Things to worry about (concurrency control)
Lost Update - when two transactions try access the same data at the same time
Uncommitted Dependency - if a transaction makes bad data, and a second uses that data and creates changes
Inconsistent Analysis - A function reads data that has changed and some data that hasnt changed yet
Lost update & Locks
/Untitled.png)
A lock - locks abit of data so that this wont happen
Lock Manager - keeps record of all the locks
eXclusive locks (xlock) - only one transaction can use it
Shared lock (slock) - multiple transactions can use it, only read it tho
/Untitled%201.png)
/Untitled%202.png)
Uncommitted Dependency Example
/Untitled%203.png)
Needs to be atomic - either committed or rolled-back
FIX extend lock till after commit or roll-back
/Untitled%204.png)
Inconsistent Analysis
/Untitled%205.png)
Problem: Value of ACC3 changed during lifetime of TA
Shared locks fix this (read only lock)
/Untitled%206.png)
Part 2: Serialisability
Is the condition that we can garantee that transactions will not interfere with one another
Growing phase = making locks or convert S to X
Shrinking phase = releasing locks or convert X to S
2-phase locking protocol (2PL)
- Before operating on data, transaction must acquire a lock
- After releasing a lock, the transaction must NOT acquire anymore locks, i.e. all locks must be got at the start
/Untitled%207.png)
Must use locks
/Untitled%208.png)
Locks Must be held for the entire transaction
/Untitled%209.png)
Part 3: Deadlocks
When two transactions are waiting for one another
/Untitled%2010.png)
Solution: create a ‘wait for graph’, stores who is waiting for who
Detect if two transactions are depenet on one another
OR look if how long a transaction has held a lock
/Untitled%2011.png)
Then rollback one of the transactions
Extra TIMESTAMP lock alternative
/Untitled%2012.png)
It is way less efficient than using a lock
/Untitled%2013.png)
/Untitled%2014.png)