Unit5 dbms
Unit5 dbms
SYSTEM
BDA202/BDA252
Unit-5
TRANSACTION
The transaction is a set of logically related
operation. It contains a group of tasks.
Open_Account(X)
Old_Balance = X.balance
New_Balance = Old_Balance - 800
X.balance = New_Balance
Close_Account(X)
Y's Account
Open_Account(Y)
Old_Balance = Y.balance
New_Balance = Old_Balance + 800
Y.balance = New_Balance
Close_Account(Y)
OPERATIONS OF TRANSACTION:
Following are the main operations of transaction:
Read(X): Read operation is used to read the value of
1. R(X);
2. X = X - 500;
3. W(X);
transaction is 4000.
The first operation reads X's value from database and stores it
in a buffer.
The second operation will decrease the value of X by 500. So
buffer will contain 3500.
The third operation will write the buffer's value to the
database. So X's final value will be 3500.
But it may be possible that because of the failure of hardware,
software or power, etc. that transaction may fail before
finished all the operations in the set.
Property of Transaction
Atomicity
Consistency
Isolation
Durability
ATOMICITY
It states that all operations of the transaction take place at
once if not, the transaction is aborted.
There is no midway, i.e., the transaction cannot occur partially.
Each transaction is treated as one unit and either run to
completion or is not executed at all.
Atomicity involves the following two operations:
Read(A) Read(B)
A:= A-100 Y:= Y+100
Write(A) Write(B)
record is done here. But all the records are still not
saved to the database.
Partially committed
In the partially committed state, a transaction
Failed state
If any of the checks made by the database recovery
Explanation:
Read(A): In T4,no subsequent
writes to A, so no new edges
Read(C): In T4, no subsequent
writes to C, so no new edges
Write(A): A is subsequently
read by T5, so add edge T4 → T5
Read(B): In T5,no subsequent writes to B, so no new edges
Write(C): C is subsequently read by T6, so add edge T4 → T6
Write(B): A is subsequently read by T6, so add edge T5 → T6
Write(C): In T6, no subsequent reads to C, so no new edges
Write(A): In T5, no subsequent reads to A, so no new edges
Write(B): In T6, no subsequent reads to B, so no new edges
Hence The schedule S2 is serializable
CONFLICT SERIALIZABLE SCHEDULE
A schedule is called conflict serializability if after
swapping of non-conflicting operations, it can
transform into a serial schedule.
The schedule will be a conflict serializable if it is
Conflicting Operations
The two operations become conflicting if all
conditions satisfy:
Both belong to separate transactions.
Example:
equal.
NON-CONFLICT
T1 T2
Read(A)
Write(A)
Read(B)
Write(B)
Read(A)
Write(A)
Read(B)
Write(B)
serializable.
The view serializable which does not conflict serializable
1. Initial Read
An initial read of both schedules must be the same.
3. Final Write
A final write must be the same between both the
Above two schedules is view equal because Final write operation in S1 is done by
T3 and in S2, the final write operation is also done by T3.
Example:
CONTD….
Schedule S
With 3 transactions, the total number of possible
schedule
= 3! = 6
S1 = <T1 T2 T3>
S2 = <T1 T3 T2>
S3 = <T2 T3 T1>
S4 = <T2 T1 T3>
S5 = <T3 T1 T2>
S6 = <T3 T2 T1>
T1 → T2 → T3
RECOVERABILITY OF SCHEDULE
Sometimes a transaction may not execute
completely due to a software issue, system crash or
hardware failure. In that case, the failed transaction
has to be rollback. But some other transaction may
also have used value produced by the failed
transaction. So we also have to rollback those
transactions.
CONTD….
The above table 1 shows a schedule which has two
transactions. T1 reads and writes the value of A and that value
is read and written by T2. T2 commits but later on, T1 fails.
Due to the failure, we have to rollback T1. T2 should also be
rollback because it reads the value written by T1, but T2 can't
be rollback because it already committed. So this type of
schedule is known as irrecoverable schedule.
Irrecoverable schedule: The schedule will be irrecoverable if
Tj reads the updated value of Ti and Tj committed before Ti
commit.
CONTD…
The above table 2 shows a schedule with two transactions.
Transaction T1 reads and writes A, and that value is read and
written by transaction T2. But later on, T1 fails. Due to this,
we have to rollback T1. T2 should be rollback because T2 has
read the value written by T1. As it has not committed before
T1 commits so we can rollback transaction T2 as well. So it is
recoverable with cascade rollback.
follows:
1. Check the following condition whenever a transaction Ti
issues a Read (X) operation:
If W_TS(X) >TS(Ti) then the operation is rejected.
X.
W_TS(X) denotes the Write time-stamp of data-item
X.
Advantages and Disadvantages of TO protocol:
growing phase.
Downgrading of lock (from X(a) to S(a)) must be done
in shrinking phase.
Example:
The following way shows how unlocking and locking work with
2-PL.
Transaction T1:
Transaction T2:
END OF UNIT-5