Documente Academic
Documente Profesional
Documente Cultură
What is a transaction?
A transaction is an executing program that forms a logical
unit of database processing.
1
Example of Transaction processing system
2
Features & Requirements of
Transaction processing system
Features
Large database &
Hundreds of concurrent users!
Requirements
High availability &
Fast response time
3
Transaction on a bank database
Transaction T1
Transfer Rs.50000/- from a/c no. 1259 to a/c no 3245.
Transaction T2
Checking balance in a/c no. 3245.
Transaction T3
Deposit Rs.70000/- into a/c no. 3245.
4
Transactions on university database
Transaction T4
Register courses for the next semester
Transaction T5
View attendance status
Transaction T6
View semester results
Transaction T7
Withdraw from a course
5
ACID properties of transaction
A Atomicity
C Consistency
I Isolation
D Durability
6
Atomicity (All or Nothing)
7
Consistency
8
Isolation
9
Durability
10
Data model used in transaction processing
11
Disk blocks and memory buffers
12
Data transfer between disk and memory takes place in units of disk block.
Basic database access operation
read_item(X)
Reads database item named X into the
program variable X.
write_item(X)
Write the value of the program variable X into
the database item named X.
13
read_item(X) involves following steps
1. Find the address of the disk block that
contains data item X.
14
write_item(X) involves the following steps
1. Find the address of the disk block that contains
data item X.
2. Copy that disk block into a buffer in main
memory (if that disk block is not already in
some main memory buffer).
3. Copy data item X from the program variable
named X into its correct location in the buffer.
4. Store the updated block from the buffer back
to disk (either immediately or at some later
point in time).
15
Representation of a transaction in terms of read
and write
Transaction T1
Transfer Rs.50000/- from a/c no. 1259 to a/c no 3245.
read_item(X);
X := X – 50000;
write_item(X);
read_item(Y);
Y:= Y + 50000; X = Balance in account number 1259
Y = Balance in account number 3245
write_item(Y);
16
State transition diagram illustrating the states for
transaction execution
17
States for transaction execution
BEGIN_TRANSACTION. This marks the beginning of
transaction execution.
READ or WRITE. These specify read or write operations
on the database items that are executed as part of a
transaction.
END_TRANSACTION. This specifies that READ and
WRITE transaction operations have ended and marks the
end of transaction execution. However, at this point it
may be necessary to check whether the changes
introduced by the transaction can be permanently
applied to the database (committed) or whether the
transaction has to be aborted because it violates
serializability or for some other reason.
18
States for transaction execution
COMMIT. This signals a successful end of the transaction
so that any changes (updates) executed by the
transaction can be safely committed to the database
and will not be undone.
ROLLBACK (or ABORT). This signals that the transaction
has ended unsuccessfully, so that any changes or effects
that the transaction may have applied to the database
must be undone.
19
System log
20
Commit point of a transaction
21
Database cache
(also known as DBMS cache)
22
Main memory & DBMS cache
DBMS cache
Data buffers
DBMS cache
Log buffers
Indexes in use
Accessed by OS
23
Two transactions T1 & T2
24
A serial schedule consisting of T1 & T2
27
Concurrent execution of transactions of a schedule
28
Concurrent execution of T1 & T2 in an interleaved
fashion. (A non-serial schedule)
30
Concurrent execution of multiple transactions
leads to several problems
31
Concurrent execution of multiple transactions
leads to several problems
34
r3(A); … r1(X); w1(X); … r3(X); r3(Y); r1(Y); w1(Y);
Problems with concurrent execution of multiple
transactions
4) Unrepeatable read
Transaction T
read_item(X) (X = no. of seats available in flight 1)
read_item(Y) (Y = no. of seats available in flight 2)
read_item(Z) (Z = no. of seats available in flight 3)
.
.
.
--- Book N tickets on flight 1
read_item(X)
X := X – N (may fail!)
35
Schedule of transactions (formal definition)
36
Serial and non-serial schedule (formal definition)
37
Serial schedule
Sa: r1(X); w1(X); r1(Y); w1(Y); r2(X); w2(X); Sb: r2(X); w2(X); r1(X); w1(X); r1(Y); w1(Y);
38
Non-serial schedule
Sc: r1(X); r2(X); w1(X); r1(Y); w2(X); w1(Y); Sd: r1(X); w1(X); r2(X); w2(X); r1(Y);
39
Serializable schedule
A non-serial schedule is called SERIALIZABLE
if it is equivalent to a serial schedule.
40
Equivalence of schedules
41
Two types of equivalence
Conflict equivalence
View equivalence
42
Conflict (conflicting operations)
Two operations in a schedule are said to conflict if they
satisfy all the three conditions viz.
43
Conflict equivalent schedules
44
Conflict serializable schedule
45
Testing conflict serializability of schedule
Sd:r1(X);w1(X);r2(X);w2(X);r1(Y);w1(Y);
r1(X);w2(X)
w1(X);r2(X)
w1(X);w2(X)
Sd is conflict serializable
46
Testing conflict serializability of schedule
Sc:r1(X);r2(X);w1(X);r1(Y);w2(X);w2(Y);
r1(X);w2(X)
r2(X);w1(X)
w1(X);w2(X)
47
Algorithm to test conflict serializability
51
A non-serial schedule of T1, T2 & T3
r2(Z);r2(Y);w2(Y);r3(Y);r3(Z);r1(X);w1(X);w3(Y);w3(Z);r2(X);r1(Y);w1(Y);w2(X)
52
Precedence graph
53
Another non-serial schedule of T1, T2 & T3
r3(Y);r3(Z);r1(X);w1(X);w3(Y);w3(Z);r2(Z);r1(Y);w1(Y);r2(Y);w2(Y);r2(X);w2(X)
54
Precedence graph
55
View equivalence
S: …wj(X);…wj(Y);…ri(Y);…ri(X);…wk(Z); …
S’: …wj(Y);…ri(Y);…wj(X);…ri(X);…wk(Z); …
56
View equivalence of schedule
57
View serializable
58
Characterizing schedules based on serializability
59
Characterizing schedule based on recoverability
60
Characterizing schedule based on recoverability
61
Characterizing schedule based on recoverability
62
Characterizing schedule based on recoverability
63
Cascadeless schedule
64
Cascadeless schedule
65
Strict schedule
66
Strict, Cascadeless, Recoverable
Any strict schedule is also cascadeless, and any
cascadeless schedule is also recoverable.
The cascadeless schedules will be a subset of
the recoverable schedules, and the strict
schedules will be a subset of the cascadeless
schedules.
Thus, all strict schedules are cascadeless, and
all cascadeless schedules are recoverable.
67
Exercise problem
Which of the following schedules is (conflict)
serializable? For each serializable schedule,
determine the equivalent serial schedules.
a) r1(X); r3(X); w1(X); r2(X); w3(X);
b) r1(X); r3(X); w3(X); w1(X); r2(X);
c) r3(X); r2(X); w3(X); r1(X); w1(X);
d) r3(X); r2(X); r1(X); w3(X); w1(X);
68
Exercise problem
Consider the three transactions T1, T2, and T3, and the
schedules S1 and S2 given below. Draw the serializability
(precedence) graphs for S1 and S2, and state whether
each schedule is serializable. If a schedule is serializable,
write down the equivalent serial schedule(s).
T1: r1 (X); r1 (Z); w1 (X);
T2: r2 (Z); r2 (Y); w2 (Z); w2 (Y);
T3: r3 (X); r3 (Y); w3 (Y);
S1: r1 (X); r2 (Z); r1 (Z); r3 (X); r3 (Y); w1 (X); w3 (Y);
r2 (Y); w2 (Z); w2 (Y);
S2: r1 (X); r2 (Z); r3 (X); r1 (Z); r2 (Y); r3 (Y); w1 (X);
w2 (Z); w3 (Y); w2 (Y);
69
Exercise problem
Consider schedules S3, S4, and S5 below.
Determine whether each schedule is strict,
cascadeless, recoverable, or non-recoverable.
S3: r1(X); r2(Z); r1(Z); r3(X); r3(Y); w1(X); c1;
w3(Y); c3; r2(Y); w2(Z); w2(Y); c2;
S4: r1(X); r2(Z); r1(Z); r3(X); r3(Y); w1(X);
w3(Y); r2(Y); w2(Z); w2(Y); c1; c2; c3;
S5: r1(X); r2(Z); r3(X); r1(Z); r2(Y); r3(Y);
w1(X); c1; w2(Z); w3(Y); w2(Y); c3; c2;
70