Transaction DBMS
Transaction DBMS
T2: read(A);
temp := A * 0.1;
A := A − temp;
write(A);
read(B);
B := B + temp;
write(B).
Suppose the current values of accounts A and B are $1000 and $2000,
respectively.Suppose also that the two transactions are executed one at a
time in the order T1 followed by T2. This execution sequence appears in
Figure 14.2.
The final values of accounts A and B, after the execution in Figure 14.2
takes place, are $855 and $2145, respectively.
In the above schedule total amount of money in accounts A and B—that
is, the sum A + B—is preserved after the execution of both transactions.
With multiple transactions, the CPU time is shared among all the
transactions.Not all concurrent executions result in a correct state. To
illustrate,
It is the job of the database system to ensure that any schedule that is
executed will leave the database in a consistent state. The
concurrency-control component of the database system carries out
this task.
Serializability:
1. Conflict Serializability
2. View Serializability
Conflict Serializability:
If I and J refer to the same data item Q, then the order of the two
steps may matter.
As we are dealing with only read and write instructions, there are
four cases that we need to consider:
1. I = read(Q), J = read(Q). The order of I and J does not matter, since the
same value of Q is read by Ti and Tj , regardless of the order.
When both I and J are read instructions the order of the instructions
does not matter.
Similarly, Figure 14.10b shows the precedence graph for schedule 2 with
the single edge T2 →T1, since all the instructions of T2 are executed
before the first instruction of T1 is executed.
The precedence graph for schedule 4 appears in Figure 14.11. It contains
the edge T1 →T2, because T1 executes read(A) before T2 executes
write(A). It also contains the edge T2→T1, because T2 executes read(B)
before T1 executes write(B).
View equivalence
Schedule S:
T1 T2
R(x)
W(x)
R(x)
W(x)
R(y)
W(y)
R(y)
W(y)
T1 T2
R(x)
W(x)
R(y)
W(y)
R(x)
W(x)
R(y)
W(y)
Since a view equivalent schedule is possible, it is a view serializable
schedule.
Example:
We have a schedule "S" having two transactions t1, t2, and t3 working
simultaneously.
Schedule S:
T1 T2 T3
R(x)
W(x)
W(x)
W(x)
S':
T1 T2 T3
R(x)
W(x)
W(x)
W(x)
Cascadeless Schedules
Implementation of Isolation:
Locking
The write timestamp of a data item holds the timestamp of the transaction
that wrote the current value of the data item. Timestamps are used to
ensure that transactions access each data item in order of the transactions’
timestamps if their accesses conflict. When this is not possible, offending
transactions are aborted and restarted with a new timestamp.
Snapshot isolation:
If the transaction updates the database, that update appears only in its
own version, not in the actual database itself. Information about these
updates is saved so that the updates can be applied to the “real” database
if the transaction commits.
Snapshot isolation ensures that attempts to read data never need to wait
(unlike locking). Read-only transactions cannot be aborted; only those
that modify data can be aborted. Since each transaction reads its own
version or snapshot of the database, reading data does not cause
subsequent update attempts by other transactions to wait (unlike locking).
The problem with snapshot isolation is that, it provides too
much isolation.
If T reads some data item that T` updates and T`reads some data item that
T updates, it is possible that both transactions fail to read the update made
by the other. The result, may be an inconsistent database state that, of
course, could not be obtained in any Serializable execution.