Vous êtes sur la page 1sur 3

Ronald Jay S.

Villamer
MIT

Reaction Paper
Outline
In databases and transaction processing, two-phase locking (2PL) is a concurrency
control method that guarantees serialize ability. It is also the name of the resulting set of
database transaction schedules (histories).
When multiple transactions, which change the data, are executed simultaneously, it is
required to control the order of processing these transactions to satisfy the ACID
(Atomicity, Consistency, Integrity, Durability) property of the database. Executing
multiple transactions simultaneously should lead to the same result as executing each
transaction independently, in other words, one transaction should not be affected by
another transaction.
If different data is changed for each transaction, no interference between transactions is
made, so there is no issue. However, if the same data is simultaneously changed by
multiple transactions, the order of processing each transaction should be controlled.
The Two Phase Protocol (2PL) protocol has found wide spread implementation in
distributed database systems and research continues on how better to detect and
prevent deadlocks in the 2PL protocol in distributed database systems. In this
discussion we take a review of the 2PL protocol, definitions of terms involved to 2PL,
the deadlocks, and some suggestions on how to avoid deadlocks in the 2PL Protocol.
Introduction
Even though the 2PL Protocol finds wide use in distributed database systems, the 2PL
Protocol is essential in operating systems and to better grasp the 2PL protocol, a look at
Serializability and Locking Protocol is an important first step, as these concepts are
foundational to understanding the 2PL Protocol.

Serialize Ability
Serialize ability is a situation where multiple transactions are active simultaneously, and
each transaction is atomic, the concurrent execution of transactions have to be
equivalent in order to execute the processes serial. To ensure serialize ability, each data
item has to be associated with a lock and that each lock follow a locking protocol that
sets rules on how locks are acquired and released.
Locking protocol
Locking Protocols by and large align admission to mutual shared data using locks which
can be turned on or off when a transaction acquires or releases the shared data.
Silberschatz Et al describe the two conditions of locking protocol as follows, with each
data transaction forced to ask for lock in a suitable mode on a data item Q, as per type
of activity it will do:

Shared: If a transaction Ti has acquired a shared-condition lock on a data


item Qi, then Ti can read the item but cannot write Q
Exclusive: If a transaction Ti has received an exclusive-condition lock on a data
item Q, then Ti can both read and write Q.

As described by Silberschatz et al, the problem associated with locking protocol is that
serialize ability is not guaranteed when a transaction unlocks a data item instantly after
use.
Two Phase Protocol
One protocol that is said to guarantee serialize ability is the Two Phase Protocol (2PL).
The 2PL Protocol oversees locks by determining when transactions can acquire and
release locks. The 2PL protocol forces each transaction to make a lock or unlock
request in two steps:

Growing Phase: A transaction may obtain locks but may not release any locks.
Shrinking Phase: A transaction may release locks but not obtain any new lock.

The transaction first enters into the Growing Phase, makes requests for required locks,
then gets into the Shrinking phase where it releases all locks and cannot make any

more requests. Transactions in 2PL Protocol should get all needed locks before getting
into the unlock phase.
While the 2PL protocol guarantees serialize ability, it does not ensure that deadlocks do
not happen. Silberschatz, et. Al point out that for a given set of transactions, there could
be conflict-serialize able schedules that cannot be obtained by using 2PL protocol.
Also challenges arise when 2PL protocols are faced with transactions that require
communication between data sets. This is becomes a challenge in distributed
applications like distributed database systems.
In distributed database systems for example, each site is required to keep and maintain
a wait for graph. The nodes in the graph are the transactions requesting for or currently
holding a lock. The system should be able to detect any cycles and terminate any
deadlocks.
Conclusion
The Two Phase Protocol (2PL) protocol is widely implemented in distributed database
systems and research continues on how better to detect, prevent deadlocks, and
optimization in the 2PL protocol in distributed database systems.

Vous aimerez peut-être aussi