0% found this document useful (0 votes)
81 views96 pages

Transaction Management in Databases

Uploaded by

dhyanardave
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)
81 views96 pages

Transaction Management in Databases

Uploaded by

dhyanardave
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

Database Management System

Topic 3
Transaction Management & Concurrency
Control

12.06.2021
Course Instructor
Santosh K. Vishwakarma
santoshscholar@gmail.com
ICE GATE
Database Management System
Recap

➢ Transaction – Definition

➢ Examples of Transaction

➢ ACID Properties

➢ Transaction States

➢ GATE Questions

➢ Schedule – Serial vs Concurrent

➢ Number of Schedules
Database Management System
Today

➢ Conflict Conditions

➢ Problems in Concurrent Schedule

➢ Recourability - Recourable, Cascadeless, Strict Schedules

➢ Serializability
➢ Conflict Serializability – Conditions, Topological Sorting,

➢ View Serializability
Database Management System
Transaction Management

➢ Logical Unit of work


➢ Deposit Amount in Account
➢ Fund Transfer
➢ Book a Ticket
➢ Opening a Account

➢ A transaction is a unit of program execution that accesses and possibly updates


various data items.

➢ Logical unit of database processing that includes one or more access operations
(read -retrieval, write - insert or update, delete)

➢ The following two operations are integral to the transaction


➢ Read – Secondary to Primary Memory
➢ Write - Primary to Secondary Memory
Database Management System
Transaction Management

RAM RAM

Hard Disk Hard Disk

Read Operation Write Operation


Database Management System
Transaction Management

➢A transaction (set of operations) may be stand-alone specified in a high level


language like SQL submitted interactively, or may be embedded within a
program

➢An application program may contain several transactions separated by the


Begin and End transaction boundaries.
Database Management System
Transaction Management

Transaction

Deposit Rs. 1000 to the Bank Account A

1.read(A)
2.A := A + 1000
3.write(A)
Database Management System
Transaction Management

Transaction

Withdrawal of Rs. 600 to the Bank Account B

1.read(B)
2.B := B - 600
3.write(B)
Database Management System
Transaction Management

Transaction

Fund Transfer of Rs. 50 Account A to Account B

1.read(A)
2.A := A – 50
3.write(A)
4.read(B)
5.B := B + 50
6.write(B)
Database Management System
Transaction Management

➢ Transaction Properties are also known as ACID Properties.

➢ Atomicity
➢ Process all of a transaction or none of it; transaction cannot be further subdivided (like an atom)

➢ Consistency
➢ Data on all systems reflects the same state

➢ Isolation
➢ Transactions do not interact/interfere with one another; transactions act as if they are independent

➢ Durability
➢ Effects of a completed transaction are persistent
Database Management System
Transaction Management
Database Management System
Transaction Management

➢ Concurrent Execution

➢ Validity of the Data (Atomicity)

➢ Organized Execution of Transactions (Serializability)

➢ Correctness of the Operations (Consistency)

➢ Record all the updates before final commit

➢ Rollback for failure or abort state


Database Management System
Concurrent Execution

➢ Many users can use the same database at the same time in a multi-user scheme

➢ It helps multiple users on a multi-user device to run the same database at the same time
Database Management System
Conflicting operations

➢ Two operations are said to be in conflict, if they satisfy all the following three conditions:

➢ Both the operations should belong to different transactions.

➢ Both the operations are working on same data item.

➢ At least one of the operation is a write operation.


Database Management System
Conflicting operations - Examples
Database Management System
Problems in concurrent execution
Database Management System
Lost Update Problems (W-W Conflict)
Database Management System
Lost Update Problem - Example
Lost Update Problem
T1 T2
Read (A)
Write (A)
Write (A)

S = R1(A) W1(A) W2(A)

SCHEDULE

T1 READS A = 2
MULTIPLY A BY 10 = 20
WRITES A = 20

T2 WRITE A = 500
Database Management System
Lost Update Problems (W-W Conflict)

Example:

Time t𝑥 ty Explanation Value of A


t1 READ(A) ----------- Transaction TX reads the value of account A 300
t2 A=A-50 transaction TX deducts 50 from account A 250
t3 ----------- READ (A) Alternately, at time t3, transaction TY reads the value of 300 (TX did not update the
account A value)
t4 ----------- A=A+100 TY adds 100 to account A 400
t5 ----------- -----------
t6 WRITE(A) ----------- transaction TX writes the updated value of account A 250 (TY did not update the
value)
t7 WRITE(A) TY writes the values of account A 400
Database Management System
Concurrency Control

• Dirty Read Problems (W-R Conflict)

The dirty read problem occurs when:

A transaction fails as it attempts Another transaction accesses the


to upgrade a database object modified object until the data is
rolled around
Dirty Read Problem
T1 T2
Read (A)
Write (A)
Read (A) = dirty read
Computing
Write (A)
commit
abort
Dirty Read Problem
T1 T2 T3 T4 T5
READ (X) = 4
WRITE (X) = 9
READ (X) = 9
…….. READ (X) = 9
READ (X) = 9
READ (X) = 9
ABORT

MEMORY X = 4 9 4

ABORT T3
SYSTEM WILL ROLLOBACK ALL T4, T5, T1, T2
CASCADING ROLLBACK PROBLEM
Database Management System
Concurrency Control
Database Management System
Concurrency Control

• Unrepeatable Read Problem (W-R Conflict)


W-R

This is also known as the Problem of


Inconsistent Retrievals

When a transaction reads two separate


values from a data base object, this
occurs
Database Management System
Concurrency Control

Time t𝑥 ty Explanation Value


of A
t1 READ(A) ----------- Transaction TX reads the value of account A 300
t2 ----------- READ(A) Transaction TY reads the value from account A 300
t3 ----------- A=A+100 Transaction TY adds 100 and updates the value of 400
account A
t4 ----------- WRITE(A) Transaction TY writes the updated value 400
t5 READ(A) ----------- Transaction TX reads the available value of account A 400
Unrepeatable Read Problem ( Phantom Pb)
T1 T2
Read (A) = 3
Read (A) = 3
Write (A) = 6
Read (A) = 6
1. Recourable Schedule
For a recourable schedule;
T1 T2
Read (X) WRITE – READ PAIR BETWEEN TWO TRANSACTIONS
Write (X)
The transaction which write first, should commit first
Read (X)

Commit

COMMIT
1. Recourable Schedule
T1 T2 T3
Read (A)
Read (B)
Wrtite (B)
Write (A)
commit
Read (B)
commit

commit
1. Recourable Schedule
T1 T2 T3
Read (A)
Read (B)
Wrtite (B)
Write (A)

Read (B)
commit

commit
commit
2. Cascadeless Schedule
T1 T2
Read (A)
Write (A)
Commit
Read (A)
2. Cascadeless Schedule
T1 T2 T3
Read (A)
Write (A)
Read (B)
Read ( C )
Write (B)

Commit
Read (B)
Database Management System
Strict Schedule
Database Management System

Serializability is the classical concurrency scheme. It ensures that a


schedule for performing concurrent transactions is identical to one in
which the transactions are executed sequentially in any order.

It is assumed that all database accesses are performed using read and write operations
Database Management System
Transaction Management

➢ Serializability is an important technique to check that the concurrent schedule is


correct

➢ Serializability
➢ Conflict (Precedence Graph )
➢ View (Initial Read, Write – Read Pair, Final Write)

➢ Conflict Serializability is not the sufficient criteria to check whether a schedule is


correct or not

➢ There exists schedules which may not be conflict serializable, but they are view
serializable
Database Management System

Types of
Serialisable

Conflict View
Serialisable Serialisable
Database Management System
Transaction Management

Concurrent Schedule

Conflict View
Serializable Serializable

Serializable Not Serializable


Database Management System

Conflict Serialisable:
Conflict serialisability refers to a schedule's ability to turn into a serial
schedule after switching non-conflicting operations. If there is conflict
equal to a serial schedule, the schedule would be conflict serialisable.

View Serialisable:
View serialisability is a concept used to determine whether or not
schedules are view-serialisable.
Schedule 1
T1 T2
Read (A)
Write (A)
Read (A)

T2
T1

The given schedule is conflict serializable because there is no cycle between any
transaction.
Schedule S2
T1 T2
Read (A)
Write (A)
Read (A)
Write (A)

This schedule in not conflict serializable because there exist a loop


between transaction.

T1
T2
T1 READ (A) – T2 WRITE (A) : CONFLICT

Schedule S3 NO LOOP OR CYCLE


THEREFORE

THE SCHEDULE IS CONFLICT SERIALIZABLE


MEANS IT IS CORRECT

T1 T2 T3
Read (A)
Write (A)
Read (A)
Read (A)
Write (A)

T1 T2

T3
Schedule S3
T1 T2 T3
Read (A)
Write (A)
Read (A)
Read (A)
Write (A)

T1 T2

T3
Schedule S4: Conflict Serializable ?
T1 T2 T3
Read (A)
Write (A)
Read (B)
Read (A)
Write (B)
Read (C)
Read ( C )
Write (B)
Write ( C)
HINT: DRAW ITS PRECEDENCE GRAPH
NO LOOP OR CYCLE
T1 T2
THEREFORE,

THE SCHEDULE IS CONFLICT


SERIALIZABLE (CORRECT)
T3
Schedule S5: Conflict Serializable ?
T1 T2 T3
Read (A)
Write (A)
Read (B)
Read (A)
Write (A)
Read (A)
Read ( C )
Write (B)
Write ( C)
HINT: DRAW ITS PRECEDENCE GRAPH
Transaction = different
T1 T2
Variable = same
Write
If all above cond satisfies, then there is a
conflict
T3 THE SCHEDULE S5 IS NOT CONFLICT
SERIALIZABLE
Concurrent Schedule S6
T1 T2
R(P)
R (P )
W (Q)

BLIND WRITE OPERATION


GATEYOU
THANK PYQ
THANK YOU
THANK YOU
THANK YOU
THANK YOU
THANK YOU
THANK YOU
THANK YOU
THANK YOU
THANK YOU
THANK YOU
THANK YOU
THANK YOU

You might also like