0% found this document useful (0 votes)
2 views1 page

Two-Phase Locking DDM

Two-phase locking (2PL) is a concurrency control protocol in databases that ensures serializability by dividing the transaction process into a growing phase, where locks are acquired, and a shrinking phase, where locks are released. It utilizes shared and exclusive locks to manage access to data items, preventing conflicts and ensuring that transactions do not interfere with each other. While 2PL guarantees serializability, it can lead to deadlocks, necessitating additional mechanisms for detection and resolution.

Uploaded by

lendus1900
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

Two-Phase Locking DDM

Two-phase locking (2PL) is a concurrency control protocol in databases that ensures serializability by dividing the transaction process into a growing phase, where locks are acquired, and a shrinking phase, where locks are released. It utilizes shared and exclusive locks to manage access to data items, preventing conflicts and ensuring that transactions do not interfere with each other. While 2PL guarantees serializability, it can lead to deadlocks, necessitating additional mechanisms for detection and resolution.

Uploaded by

lendus1900
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Two-phase locking (2PL) is a fundamental concurrency control protocol in database systems, designed

to ensure serializability—the gold standard for transaction correctness. Serializability means the outcome
of executing transactions concurrently is the same as if those transactions were executed one after
another, in some order.

Phases of 2PL
Growing Phase (Expanding Phase):
•The transaction can acquire locks (shared or exclusive) on data items as needed.
•No locks can be released during this phase.
•The transaction continues to acquire locks until it has all it needs for its operations.
•This phase ends at the “lock point,” after which no new locks can be acquired.

Shrinking Phase:
•Begins once the transaction releases its first lock.
•During this phase, the transaction can only release locks; it cannot acquire any new ones.
•This phase continues until the transaction ends (commit or rollback).

Types of Locks
•Shared Lock (S): Allows a transaction to read a data item. Multiple transactions can hold shared locks
on the same item simultaneously.
•Exclusive Lock (X): Allows a transaction to both read and write a data item. Only one transaction can
hold an exclusive lock on an item at a time; no other transaction can hold any lock on it simultaneously.

How 2PL Guarantees Serializability


Conflict Prevention: By forcing all locks to be acquired before any are released, 2PL ensures that once a
transaction releases a lock, it cannot interfere with other transactions by acquiring new locks. This
prevents cycles in the precedence (serialization) graph, which are the root cause of non-serializable
schedules.

Blocking and Waiting: If a transaction requests a lock that is incompatible with locks held by other
transactions, it must wait. This queuing ensures that conflicting actions are serialized.

Example: If Transaction T1 holds an exclusive lock on a record and Transaction T2 requests a shared
lock, T2 must wait until T1 releases its lock. This ensures T2 cannot read or write until T1’s changes are
complete, preserving serializability.

Strict 2PL Variant


Strict 2PL is a common variation where all exclusive locks are held until the transaction commits or
aborts. This prevents cascading rollbacks and further strengthens consistency guarantees.

Deadlocks
2PL can lead to deadlocks, where two or more transactions wait indefinitely for each other to release
locks. Deadlock detection and resolution mechanisms (like wait-die or wound-wait) are often used
alongside 2PL.

You might also like