Beruflich Dokumente
Kultur Dokumente
By :
Mrs. Suman Madan
suman.madan@jimsindia.org
Transaction Concept
A transaction is a unit of program execution that accesses and
possibly updates various data items.
• Useful for text editors, but extremely inefficient for large databases:
executing a single transaction requires copying the entire database.
Concurrent Executions
• Multiple transactions are allowed to run
concurrently in the system. Advantages are:
– increased processor and disk utilization, leading to
better transaction throughput: one transaction can
be using the CPU while another is reading from or
writing to the disk
– reduced average response time for transactions:
short transactions need not wait behind long ones.
write_item(X);
read_item(Y); write_item(X);
Y:=Y + N;
write_item(Y);
Temporary Update (Dirty Read)
time T1 T2
read_item(X);
X:=X - N;
write_item(X);
read_item(X);
X:=X+M;
write_item(X);
read_item(Y);
T1 fails and aborts
Incorrect Summary Problem
time T1 T2
sum:=0;
read_item(X); read_item(A);
X:=X-N; sum:=sum+A;
write_item(X);
read_item(X);
sum:=sum+X;
read_item(Y); read_item(Y);
Y=Y+N
sum:=sum+Y
Write_item(Y)
What Can Go Wrong?
• System may crash before data is written back to disk
= Problem of atomicity
• System may not be able to obtain one or more of the data items
• System may not be able to write one or more of the data items
= Problems of atomicity
y
Example : Precedence graph
T1 T2
Read(N)
Read(N)
N=N-1
N= N-1
Write(N)
Write(N)
Precedence graph
T1 T2
Read(N)
Read(N)
N=N-1
T2
N= N-1 N
Write(N) N
Write(N) T1
x
No equivalent serial schedule
(cycle x(T1T2),y(T2T1)) y y,z
(cycle x(T1T2),yz(T2T3),y(T3T1))
T3
Examples (Precedence Graph)
Assume we have another schedule for the same transactions:
– Conservative (Pessimistic)
• Locking
• Time stamping
– Time-stamping
• ordering transactions such that older transactions get priority in the
event of a conflict.
• Timestamping is one approach to resolving situations such as deadlock.
Optimistic
– Conflict is rare
– Disk failure : all disk or some disk blocks may lose their data
• Type of schedules :
– recoverable scheduls : once a transaction T is
commited , it should never rollbacked.