0% found this document useful (0 votes)
10 views30 pages

Transaction Management

Uploaded by

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

Transaction Management

Uploaded by

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

Complete schedule:

It is a schedule of transactions where each transaction is committed before terminating. The example is shown below where transactions T1 and T2 terminates after committing the transactions.
Example:

T1 T2
A=1000
Read(A)
A=A+100
Write(A) Read(A)
B=A-100
Write(B)
Commit
Read(B)
Write(B)
Serializability

• Serializability of schedules ensures that a non-serial


schedule is equivalent to a serial schedule. It helps in
maintaining the transactions to execute simultaneously without
interleaving one another.
Schedules in DBMS are of two types:
• Serial Schedule - A schedule in which only one transaction is
executed at a time, i.e., one transaction is executed completely
before starting another transaction.
Example
Transaction-1 Transaction-2

R(a)

W(a)

R(b)

W(b)

R(b)

W(b)

R(a)

W(a)
Non-serial Schedule -

• A schedule in which the transactions are interleaving or


interchanging. There are several transactions executing
simultaneously as they are being used in performing real-world
database operations. These transactions may be working on the
same piece of data. Hence, the serializability of non-serial schedules
is a major concern so that our database is consistent before and
after the execution of the transactions.
Example
Transaction-1 Transaction-2

R(a)

W(a)

R(b)

W(b)

R(b)

R(a)

W(b)

W(a)
Anomalies due to interleave execution of transaction:

Anomalies due to Interleaved execution • There are three main


situations when the actions of two transactions T1 and T2 conflict with
each other in the interleaved execution on the same data object.

Write-Read (WR) Conflict: Reading Uncommitted data.


Read-Write (RW) Conflict: Unrepeatable Reads
Write-Write (WW) Conflict: Overwriting Uncommitted Data
Reading uncommitted values(WR
conflicts):
1.If you try to the read the value which
is not written on to the data base(not
committed) will leads to write-read
conflict which is called dirty read
operation.
Un repeatable reading data operation(RW conflicts):

Reading the same object twice before committing the transaction might
yield an inconsistency

–Read-then-Write (RW) Conflicts (Write-After-Read)

Unrepeatable problem means we get different values in different


reads. For example in S1 say T2 read initially x=5 then T1 updated
x=1 so now T2 will read x=1 here T2 has read two different values
during consecutive reads This shouldn't have been allowed as T1 has
not committed
Overwriting uncommitted data(WW conflicts)

WW conflicts if one transaction could over write


the value of an object A
which has been already modified by other
transaction T1 while first transaction still in
progress .This kind of conflict refer to blind write
conflict.
Lock-Based Concurrency Control
• Locking is a concurrent control technique used to ensure
serializability. •
• There are two types of locks.
• A transaction needs to acquire a lock before performing a
transaction. •
• The read lock is known as shared lock and write lock is known as
exclusive lock. •
• A locking protocol is a set of rules that a transaction follows to attain
serializability
Strict Two-Phase Locking (Strict 2PL)
Protocol

The Strict 2PL has the following two rules:


Rule 1: A transaction can read data only when it acquires a
shared lock and can write data only when it acquires an
exclusive lock on object.
Rule 2: A transaction should release the locks when it is
completed.
Concurrency Control Techniques are
1.Two-phase locking Protocol
2.Time stamp ordering Protocol
3.Multi version concurrency control
4.Validation concurrency control
Two Phase Locking

• Locking is an operation which secures: permission to


read, OR permission to write a data item. Two phase
locking is a process used to gain ownership of shared
resources without creating the possibility of deadlock.
The 3 activities taking place in the two phase update
(i) Lock are:
algorithm Acquisition
(ii) Modification of Data
(iii) Release Lock
Cont..

• Two phase locking prevents deadlock from occurring in


distributed systems by releasing all the resources it has acquired,
if it is not possible to acquire all the resources required without
waiting for another process to finish using a lock. This means that
no process is ever in a state where it is holding some shared
resources, and waiting for another process to release a shared
resource which it requires. This means that deadlock cannot
occur due to resource contention. A transaction in the Two Phase
Locking Protocol can assume one of the 2 phases:
Cont..

• Growing Phase: In this phase a transaction can only


acquire locks but cannot release any lock. The point
when a transaction acquires all the locks it needs is
called the Lock Point.

• Shrinking Phase: In this phase a transaction can only


release locks but cannot acquire any.
Time Stamp Ordering
• A timestamp is a tag that can be attached to any transaction
or any data item, which denotes a specific time on which the
transaction or the data item had been used in any way. A
timestamp can be implemented in 2 ways. One is to directly
assign the current value of the clock to the transaction or data
item. The other is to attach the value of a logical counter that
keeps increment as new timestamps are required. The
timestamp of a data item can be of 2 types:
• (i) W-timestamp(X): This means the latest time when the
data item X has been written into.
• (ii) R-timestamp(X): This means the latest time when the
data item X has been read from. These 2 timestamps are
updated each time a successful read/write operation is

You might also like