Transaction Processing: Akash Yadav (07716412812) Shubham Digra (06616412812) B.Tech ECE 5 Semester
Transaction Processing: Akash Yadav (07716412812) Shubham Digra (06616412812) B.Tech ECE 5 Semester
Akash Yadav(07716412812)
Shubham Digra(06616412812)
B.Tech ECE 5th Semester
Introduction
Why Concurrency?
Allowing only serial execution of user programs
may cause poor system performance
Low throughput, long response time
Poor resource utilization (CPU, disks)
Concurrent execution of user programs is
essential for good DBMS performance.
Because disk accesses are frequent, and
relatively slow, it is important to keep the
CPU humming by working on several user
programs concurrently
Transaction Processing
T1
CPU
I/O
Time
Non-serial schedule
Time units = 41
CPU
I/O
T2
T3
T4
Time
Transaction Processing
T1
T2
T3
T4
CPU
I/O
Time
Non-serial schedule
Time units = 22
CPU
Use 2 disks
I/O 1
I/O 2
Time
Transaction Processing
Transaction
Example: Transaction
Account(Ano, Name, Type, Balance)
A user want to
update Account set Balance = Balance 50
where Ano = 10001
update Account set Balance = Balance + 50
where Ano = 12300
Let A be account w/ Ano=10001, B be account
w/ Ano=12300. The transaction is
R(A), W(A), R(B), W(B)
* Download a video, reservation of airline seat
Transaction Processing
States of a Transaction
begin
transaction
partially
committed
end
active transaction
exception
commit
committed
failure
failed
abort
aborted
read/write
Transaction Processing
Consistency of Transaction
12
Atomicity of Transactions
A transaction might commit after completing
all its actions, or it could abort (or be aborted
by the DBMS) after executing some actions.
A very important property guaranteed by the
DBMS for all transactions is that they are
atomic. That is, a user can think of a
transaction as always executing all its actions
in one step, or not executing any actions at all.
DBMS logs all actions so that it can undo the
actions of aborted transactions.
Transaction Processing
13
14
Durability
DBMS often save data in main memory buffer
to improve system efficiency. Data in buffer is
volatile (may get lost if system crashes)
When a transaction commits, DBMS must
guarantee that all updates make by the
transaction will not be lost even if the system
crashes later
DBMS uses the log to redo actions of
committed transactions if necessary
Transaction Processing
15
Isolation
Users submit transactions, and can think of
each transaction as executing by itself (in
isolation)
Concurrency is achieved by the DBMS, which
interleaves actions (reads/writes of DB
objects) of various transactions
DBMS guarantees that interleaving
transactions do not interfere with each
other
Transaction Processing
16
17
Transaction Processing
18
B=B-100
B=1.06*B
T1: A=A+100,
T2: A=1.06*A,
B=B-100
B=1.06*B
Transaction Processing
19
20
Schedule (cont.)
Represents some actual sequence of database
actions.
In a complete schedule, each transaction ends
in commit or abort.
A schedule transforms database from an initial
state to a final state
Initial
state
A schedule
Transaction Processing
Final
state
21
Schedule (cont.)
22
23
Transaction Processing
24
Serial Schedule
Serial
Non-serial
25
26
Final
X = 60
Final
X = 50
S2: R2(X) W2(X) C2 R1(X) W1(X) C1
Transaction Processing
27
final
X=50
Y=30
28
Serializable Schedules
Serializable schedule: Equivalent to a serial
schedule of committed transactions.
Non-serial (allow concurrent execution)
Acceptable (final state is what some serial
schedule would have produced)
Types of Serializable schedules: depend on how
the equivalency is defined
Conflict: based on conflict operations
View: based on viewing of data
Ex: p.645, text does not show commits
Transaction Processing
29
30
Cascading Aborts
When a transaction aborts, all its actions are
undone. DBMS uses a log to keep track of
actions of each transaction
If T1 reads uncommitted data written by T2
(dirty read) and T2 must aborted, then T1 must
also be aborted (cascading aborts)
T1: R(A) W(A)
Abort
T2:
R(A) W(A)
Cascadeless schedule: transactions only read
data from committed transactions
Transaction Processing
31
Recoverability
If a transaction fails, the DBMS must return
the DB to its previous state
1.
2.
3.
4.
Transaction Processing
32
Recoverability
If T1 reads data from T2, commits and then
T2 needs to abort, what should DBMS do?
This situation is undesirable!
A schedule is recoverable if very transaction
commits only after all transactions from which
it reads data commit.
Cascadeless schedules are recoverable (but not
vice-versa!).
Real systems typically ensure that only
recoverable schedules arise (through locking).
Transaction Processing
33
Summary
34
Summary (cont.)
Schedule models concurrent execution of
transactions
Conflicts arise when two transactions access
the same object, and one of the transactions is
modifying it
Serial execution is our model of correctness
Serializability allows us to simulate serial
execution with better performance
Concurrent execution should avoid cascade
abort and be recoverable
Transaction Processing
35