Download presentation
Presentation is loading. Please wait.
1
Distributed Database Management Systems
Lecture 26
2
In this Lecture Transaction Management Basics
Properties of Transaction
3
Database consistency A transaction is a logical unit of work Consistent transaction.
4
May be Temporarily Inconsistent Consistent State of DB Consistent State Begin Transaction T Execution of Transaction T End of Transaction T
5
Transaction Management is difficult in case of the concurrent access to the database by multiple users.
6
Multiple read-only transactions cause no problem at all, however, if one or more of concurrent transactions try to update data, that may cause problem.
7
A transaction is considered to be a sequence of read or/and write operations; it may even consist of a single statement.
8
Transaction Example T-SQL
Transaction BUDGET_UPDATE begin EXEC SQL UPDATE J SET BUDGET = BUDGET * 1.1 WHERE JNAME = “CAD/CAM" end
9
Example Database Airline Reservation System
FLIGHT(fNo, fDate, fSrc, fDest, stSold, fCap) CUST(cName, cAddr, cBal) FC(fNo, fDate, cName, cSpecial)
10
Begin_transaction Reservation
input(flight_no, dt, c_name); EXEC SQL Select stSold, cap into temp1, temp2 where fNo = flight_no and date = dt if temp1 = temp2 then output("no free seats"); Abort else EXEC SQL update flight set stSold = stSold + 1 where fNo = flight_no and date = dt; EXEC SQL insert into FC values (flight_no, dt, c_Name, null); Commit; output("reservation completed") end
11
Transaction commits or aborts
No execution in case of an abort Commit makes permanent changes.
12
Read and Write are major operations of DB concern in a transaction
Read set (RS): The set of data items that are read by a transaction.
13
Write set (WS): The set of data items whose values are changed by this transaction
Base set (BS) = RS U WS RS and WS need not to be mutually exclusive.
14
Above Characterizations are simple since they do not consider insert and delete, so concern more a static DB Dynamic Trs have to deal with Phantoms.
15
Let Oij(x) be some operation Oj of transaction Ti operating on data item x, where Oj ∈ {read,write} and Oj is atomic Set of operations of Transaction Ti, OSi = Uj Oij.
16
Ni ∈{abort,commit} Transaction Ti is a partial order Ti = {∑i, <i} where 1- ∑i = OSi U {Ni } 2- For any two operations Oij, Oik ∈ OSi , if Oij = R(x) and Oik = W(x) for any data item x, then either OijiOik or Oik <i Oij.
17
3- ∀ Oij ∈ OSi, Oij <i Ni Ordering between operations exists in applications Ordering between conflicting ops has to exist in <i, where …..
18
Conflicting Operations
Two operations Oi(x) and Oj(x) are said to be in conflict, Oi = write or Oj = write (at least one of them is write and they access the same data item).
19
Consider a transaction T
Read(x) Read(y) x = x + y Write(x) Commit Then
20
∑ = {R(x), R(y), W(x), C} < = {(R(x), W(x)), (R(y), W(x)), (W(x), C), (R(x), C), (R(y), C)} Notation normally used is T = {R(x), R(y), W(x), C}
21
ACID Properties of a Transaction
22
1- Atomicity: also known as “all or none” property
refers to the atomicity of entire Tr rather than an individual operation It requires from system to define some action in case of any interruption in execution of Tr.
23
2- Consistency: refers simply to the correctness of a transaction
Two types of failures requiring procedures from Transaction Recovery or Crash Recovery 2- Consistency: refers simply to the correctness of a transaction A Transaction should transform the DB from one consistent state to another consistent state.
24
Concern of Semantic Integrity Control and Concurrency Control
Classification of consistency for Transaction uses the term “Dirty Data”; data that has been updated by a Transaction before its commitment.
25
Degree 3 Consistency 1- T does not overwrite dirty data of other Transaction 2- T does not commit any writes until it completes all its writes (i.e., until end of Transaction) 3- T does not read dirty data from other Transaction 4- Other Transaction do not dirty any data read by T before T commits
26
3- Isolation A Transaction cannot reveal its results to other Transaction before commitment Required in particular when one of the Transaction is updating a common data item
27
Two possible serial executions are T1, T2 or T2, T1
Consider two Trs T1 and T2 T1: Read(X) T2: Read(x) x = x+1 x = x+1 Write(X) Write(X) Commit Commit Two possible serial executions are T1, T2 or T2, T1 First Tr gets 50 and makes it 51, other makes it 52 In any case it will be 52 at the end of both Trs
28
An interleaved execution may result “Lost Update” Like
(T1:Read(x), T1:x =x+1, T2:Read(x), T1:Write(x), T2:x=x+1, T2:write(x), T1:commit, T2:commit)
29
Thanks
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.