Week 3 - Lock-Based Concurrency Control Flashcards
What is the most the most widely used protocol Lock-Based Concurrency Control
Strict Two-phase Locking, or Strict 2PL
What is a lock-based concurrency control?
he lock-based concurrency control,
the basic idea is to use locks to lock data items, that we kind of suspecting if there is a conflict that might lead to inconsistency
if these data items are read or written
What happen in a Strict 2PL
1) If T wants to read an object, first obtains an S lock.
2) If T wants to modify an object, first obtains X lock.
3) Hold all locks until end of transaction.
What are the advantages of Strict 2PL
Guarantees serializability, and avoids cascading aborts, too!
also avoids WW problems!
3Items of Strict 2PL
1) Each transaction must obtain a Shared lock on object before reading, and an exclusive lock on object before writing.
2) All locks held by transaction are released when the transaction completes
3) Only allows serializable schedules
What controls all the locking
Lock manager -
Keeps track of what kind of lock this item
What does a lock manager do?
1) Handled lock and unlock requests
2) Locking and unlocking have to be attomic operations
3) Lock upgrade
What does a Lock upgrade do?
Transactions that holds a shared lock can be upgraded to hold an exclusive lock
Strict two-phase locking gets is name from:
1) The two phases, lock acquisition and lock release
2) The two types of locks used
3) The two phases, locking/unlocking and cleanup
4) The two phases, lock acquisition and data write
1) The two phases, lock acquisition and lock release
What is a deadlock
Cycle of transactions waiting for locks to be released by each other.
A deadlock means that
one transaction wants to acquire a lock on a data item, and this data item is already
locked by another transaction.
On the other hand, this other transaction also want to acquire a lock on a data item
that is already also locked by the other transaction.
They’re both waiting on each other,
Two ways to avoid Deadlocks
1) here are deadlock prevention algorithms. So you add extra logic
into your concurrency control so that
you account for deadlocks. - Overhead
2) let the deadlock happen and take steps to actually break that deadlock.
One way to detect Deadlocks
Waits-for graph
What is a Waits-for graph
A waits-for graph is you
have the nodes in the graph or the transactions, and there is an edge between two transactions.
If one transaction is waiting for the other transaction to release a lock.
What kind of lock must a transaction acquire in order to read from a database?
1) Concurrency lock
2) Read lock
3) Shared lock
4) Exclusive lock
3) Shared lock
What kind of lock must a transaction acquire in order to write to a database?
1) Write lock
2) Atomicity lock
3) Exclusive lock
4) Shared lock
3) Exclusive lock