0% found this document useful (0 votes)
6 views

DBMS_UNIT-5_protocols-1[1]

The document discusses concurrency control in databases, focusing on lock-based protocols and the two-phase locking protocol, which ensures conflict-serializable schedules through a growing and shrinking phase. It also covers timestamp-based protocols, including read and write rules, and introduces Thomas' Write Rule, which allows for greater concurrency by ignoring obsolete write operations. The document highlights the advantages and disadvantages of these protocols, including issues like cascading rollbacks and deadlocks.

Uploaded by

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

DBMS_UNIT-5_protocols-1[1]

The document discusses concurrency control in databases, focusing on lock-based protocols and the two-phase locking protocol, which ensures conflict-serializable schedules through a growing and shrinking phase. It also covers timestamp-based protocols, including read and write rules, and introduces Thomas' Write Rule, which allows for greater concurrency by ignoring obsolete write operations. The document highlights the advantages and disadvantages of these protocols, including issues like cascading rollbacks and deadlocks.

Uploaded by

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

Contents

• concurrency-control
• Lock-Based Protocols
• The Two-Phase Locking Protocol
CONCURRENCY CONTROL
• When several transactions execute concurrently in the
database, the isolation property may no longer be preserved.
• To handle this, the system must control the interaction among
the concurrent transactions.
• This control is achieved through concurrency-control schemes.
The concurrency-control schemes are all based on the
serializability property. All the schemes ensure that the
schedules are serializable.
Lock-Based Protocols
• A lock is a mechanism to control concurrent access to a data item
• Data items can be locked in two modes :
1. exclusive (X) mode. Data item can be both read as well as
written. X-lock is requested using lock-X instruction.
2. shared (S) mode. Data item can only be read. S-lock is
requested using lock-S instruction.
• Lock requests are made to the concurrency-control manager by the
programmer.
• Transaction can proceed only after request is granted.
Lock-Based Protocols (Cont.)
• A transaction may be granted a lock on an item if the requested lock is
compatible with locks already held on the item by other transactions
• Any number of transactions can hold shared locks on an item, But if
any transaction holds an exclusive on the item no other transaction
may hold any lock on the item.
• If a lock cannot be granted, the requesting transaction is made to wait
till all incompatible locks held by other transactions have been
released. The lock is then granted.
• Lock-compatibility matrix
Lock-Based Protocols (Cont.)
• Example of a transaction performing locking:
T2: lock-S(A);
read (A);
unlock(A);
lock-S(B);
read (B);
unlock(B);
display(A+B)
• Locking as above is not sufficient to guarantee serializability — if A
and B get updated in-between by any other transaction in schedule,
the read of A and B, the displayed sum would be wrong.
The Two-Phase Locking
Protocol
• A locking protocol is a set of rules followed by all transactions
while requesting and releasing locks. Locking protocols restrict the
set of possible schedules.
• This protocol ensures conflict-serializable schedules.
• Phase 1: Growing Phase
• Transaction may obtain locks
• Transaction may not release locks
• Phase 2: Shrinking Phase
• Transaction may release locks
• Transaction may not obtain locks
The Two-Phase Locking
Protocol (Cont.)
• Initially, a transaction is in the growing phase. The transaction
acquires locks as needed. Once the transaction releases a lock, it
enters the shrinking phase, and it can issue no more lock requests.
• The point in the schedule where the transaction has obtained its final
lock is called the lock point of the transaction. Transactions can be
ordered according to their lock points.
• this ordering is a serializability ordering for the transactions.
The Two-Phase Locking
Protocol (Cont.)
• Another variant of two-phase locking is the rigorous two-phase
locking protocol, which requires that all locks be held until the
transaction commits.
• We can easily verify that, with rigorous two-phase locking,
transactions can be serialized in the order in which they commit.
• Most database systems implement either strict or rigorous two-
phase locking.
The Two-Phase Locking
Protocol (Cont.)
• 2PL does not ensure freedom from deadlock. Cascading rollback may
occur which can be avoided by a modification of two-phase locking
called the strict two-phase locking protocol.
• Strict two-phase locking protocol: This protocol requires not only
that locking be two phase, but also that all exclusive-mode locks
taken by a transaction be held until that transaction commits.
• It ensures that any data written by an uncommitted transaction are
locked in exclusive mode until the transaction commits, preventing
any other transaction from reading the data.
Lock Conversions
• a refinement of the basic two-phase locking protocol, in which
lock conversions are allowed.
• Upgrade: Conversion from shared to exclusive modes.
• Downgrade: Conversion from exclusive to shared.
• Upgrading can take place in only the growing phase, whereas
downgrading can take place in only the shrinking phase.
Lock Conversions
• Two-phase locking with lock conversions:
– First Phase:
• can acquire a lock-S on item
• can acquire a lock-X on item
• can convert a lock-S to a lock-X (upgrade)
– Second Phase:
• can release a lock-S
• can release a lock-X
• can convert a lock-X to a lock-S (downgrade)
• This protocol assures serializability.
Content

 What is Timestamp based Protocol


 Thomas’ Write Rule
Timestam
p
2. Time Stamp is associated with Data Items:

• This protocol maintains two timestamp values for each data Q :


• W-timestamp(Q) is the largest time-stamp of any transaction that executed
write(Q) successfully.
• R-timestamp(Q) is the largest time-stamp of any transaction(Youngest) that
executed read(Q) successfully.
Time Stamp Based
Protocol
• The main idea for this protocol is to order the transactions based on their
Timestamps.
• A schedule in which the transactions participate is then serializable.
• The timestamp ordering protocol ensures that any conflicting read and write
operations are executed in timestamp order.
• Whenever some Transaction T tries to issue a R_item(X) or a W_item(X), the Basic
Timestamp algorithm compares the timestamp of T with R_TS(X) & W_TS(X) to
ensure that the Timestamp order is not violated.
Read Rules
This describe the Basic TO protocol in following two cases.
Case 1: Suppose a transaction Ti issues a read(Q)
1. If TS(Ti) < W-timestamp(Q), then Ti needs to read a value of Q that was already
overwritten.
 Hence, the read operation is rejected, and Ti is rolled back.
2. If TS(Ti) W-timestamp(Q), then the read operation is executed, and R-
timestamp(Q) is set to max(R-timestamp(Q), TS(Ti)).
T1 Tx
read(X)
TS(T1 ) =5
write(X)
W-timestamp(Q) =10
i.e. TS(Tx ) =10 read(X)
Write Rules
• Case 2: Suppose that transaction Ti issues write(Q):
1. If TS(Ti) < R-timestamp(Q), then the value of Q that Ti is producing was needed
previously, and the system assumed that that value would never be produced.
 Hence, the write operation is rejected, and Ti is rolled back.
2. If TS(Ti) < W-timestamp(Q), then Ti is attempting to write an obsolete value of Q.
 Hence, this write operation is rejected, and Ti is rolled back.
3. Otherwise, the write operation is executed, and W-timestamp(Q) is set to TS(Ti).

T1 Tx W-timestamp(Q) =10 T1 Tx
TS(T1 ) =5
write(X) write(X)
R- write(X)
i.e. TS(Tx ) =10 read(X)
timestamp(Q)=
10 write(X) write(X)
Advantage
s

• Schedules produced by Basic Timestamp ordering protocol are


guaranteed to be conflict serializable.
• Schedules are serializable.
• No waiting for the transaction, which eliminates the possibility of
deadlocks!
Disadvantage
s

• Cascading Rollback is still possible.


• Suppose we have a Transaction T2 has used a value written by T1. If T1 is
aborted and resubmitted to the system then, T2 must also be aborted and rolled
back. So the problem of Cascading aborts still prevails.
• Starvation is possible if the same transaction is restarted and continually
aborted.
• The schedule may not be cascade-free, and may not even be recoverable.
Thomas’ Write
Rule

• Modified version of the timestamp-ordering protocol in which obsolete write


operations may be ignored under certain circumstances.
• When Ti attempts to write data item Q, if TS(Ti) < W-timestamp(Q), then Ti is
attempting to write an obsolete value of {Q}.
• Rather than rolling back Ti, as the timestamp ordering protocol would have
done, this write operation can be ignored.
• Otherwise this protocol is the same as the timestamp ordering protocol.
• Thomas' Write Rule allows greater potential concurrency and saves time.
• Allows some view-serializable schedules that are not conflict-serializable.

You might also like