Session 4 : Concurrency Control Flashcards
Concurrency Control?
Managing multiple transactions in shared database systems
to prevent interference between operations from different users or applications.
Purpose of Concuttency control?
- Prevent conflict between transaction
- Maintain data consistency and integrity
- Establish the correct order of concurrent transactions.
Problems due to concurrency?
- Loss Updates : When two transactions update the same data, and one update is overwritten, causing data loss.
- Uncommitted Data : When one transaction makes changes but is not committed, and another tansaction reads these uncommited data.
- Inconsistent Retrieval : When a transaction reads data that is an inconsistent or intermediate state dute to the interleaving of other transactions.
The Scheduler?
A special program within DBMS that determines the order in which operations from concurrent transactions are executed.
it is important bcoz,
the order of the operations becomes critical if the transactions access the same or related data, but it dosn’t matter if they access unrelated data.
The Scheduler ensures?
- Serializanility and Isolation of transactions by managing the order of opearations.
- Efficient use of CPU
Problems with first-come, first-served?
- Inefficient
- Waste CPU time
Solution : Improve system efficiency by making better use of unused CPU time.
Concurrency control methods?
- Locking methods (Two-Phase Locking)
- Time Stamping
- Optimistic
What is a Lock?
A mechanism used to control access to data items when multiple users need to access the same data concurrently.
Types of Locks?
- Binary Locks
* Has two possible states, Locked(1) and Unlocked(0)
* If Locked, data item is unavailable to other transactins, and if Unlocked it is available to accessed by any transaction. - Shared (Read) Locks
* Allow transaction to read, but not modify a data item.
* Multiple transactions can hold shared locks on the same data at the same time, as long as no exclusive lock is held. - Exclusive (Read & Write) Locks
* Allows a transaction to read & write a data item, but prevent any other transaction from accessing the same data item - not even for reading.
* Only one transaction can have an exclusive lock on a data item at any given time.
Limitations of Binary Locks?
- Too restrictive for optimal performance.
- Concurrency issues : even when transactions only read data, binary locks may unnecessarily block access to the same data.
Lock compatibility matrix?
- S + S : True (allowed)
- S + X : False (not allowed)
- X + X : False (not allowed)
Lock Manger?
A crucial component in DBMS,
responsible for controlling lock information by assigns, monitors and enforces rules for the locks.
Rules enforced by the Lock Manager?
- Lock Request : must Lock the item first
- Lock Granting : if not already locked, the lock will be granted.
- Lock Compatibility Check : if locked, check compatibility, then granted/wait
- Lock Holding & Release : hold a lock, until it is explicitly released.
Exclusive locks releasing….
must be released before the effects of any write operation become visible to other transactions.
Lock Granuarlity?
The level of detail or size of the data that a lock protects.
Two-Phase Locking (2PL)?
- Mange how transactions get and release locks.
- Ensures the same results as if the transactions were run sequently.
Key rules of 2PL?
- No conflicting Locks
- Unlockin happens last
- Locked point
2 phases of 2PL?
- Growing phase : transaction gets all the locks it needs.
- Shrinking phase : Once done, transaction release all the locks.
Problems of 2PL?
- High transaction processing cost
- Deadlocks
Deadlocks?
When two or more transactions wait for each other to release resources, and none of them can move forward, leaving them stuck.
Only occur when one transaction is trying to acquire an exclusive lock on a data item
Deadlock control techniques?
- Deadlock prevention : aborting transactions and reschedule (rolled back) before they can lead to a deadlock.
(High deadlock risk) - Deadlock detection : DBMS checks for deadlocks, if detected, one transaction is aborted and restart.
(Low deadlock risk) - Deadlock avoidance : Prevents dead locks by managing the sequence of lock acquisition.
(Low system time priority)
What is time stamps?
Assigning a unique value to each transaction when it starts.
Properties of timestamps?
- Uniqueness
- Monotonicity
Disadvantages of timestamps methods?
- Additional storage requirements
- Increased memory and Processing Overhead
- High resource consumption