Tải bản đầy đủ (.pdf) (29 trang)

Distributed Database Management Systems: Lecture 26

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (82.29 KB, 29 trang )

Distributed Database
Management Systems
Lecture 26


In this Lecture
• Transaction Management
–Basics
–Properties of Transaction


• Database consistency
• A transaction is a
logical unit of work
• Consistent transaction.


Consistent
State of DB

Begin
Transaction T

May be
Temporarily
Inconsistent

Execution of
Transaction T

Consistent


State

End of
Transaction T


Transaction
Management is
difficult in case of the
concurrent access to
the database by
multiple users.


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.


A transaction is
considered to be a
sequence of read or/and
write operations; it may
even consist of a single
statement.



Transaction Example T-SQL

Transaction BUDGET_UPDATE
begin
EXEC SQL UPDATE J
SET BUDGET = BUDGET * 1.1
WHERE JNAME = “CAD/CAM"
end


Example Database
Airline Reservation System
– FLIGHT(fNo, fDate, fSrc, fDest,
stSold, fCap)
– CUST(cName, cAddr, cBal)
– FC(fNo, fDate, cName, cSpecial)


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


• Transaction commits
or aborts
• No execution in case
of an abort
• Commit makes
permanent changes.


- 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.


- 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.



• 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.


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.


• Ni ∈{abort,commit}
• Transaction Ti is a partial
order Ti = {∑i, 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 Oij iOik or Oik


3- ∀ Oij ∈ OSi, Oij

• Ordering between
operations exists in
applications
• Ordering between
conflicting ops has to
exist in

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).


• Consider a transaction T
Read(x)
Read(y)
x=x+y
Write(x)
Commit

• Then


∑ = {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}


ACID Properties of a
Transaction


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.


–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.


–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.


• 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