Professional Documents
Culture Documents
Examples:
1. Railway Reservation System
2. Banking System
1
Transaction System
Collection of operation that form of single logical unit of work are called
transaction.
Write (X) : Which transfers the data item (X) from the local buffer of
the transaction that executed the write back to the database.
2
Transaction System
Ex. transaction to transfer $50 from account A to account B:
1. read(A)
2. A := A – 50
3. write(A)
4. read(B)
5. B := B + 50
6. write(B)
3
Properties of Transaction
Transaction have four basic properties, which are called ACID properties.
These properties are closely related to each other.
Atomicity requirement
if the transaction fails after step 3 and before step 6, money will be “lost” leading to an
inconsistent database state. Failure could be due to software or hardware.
the system should ensure that updates of a partially executed transaction are not
reflected in the database.
Durability requirement — once the user has been notified that the transaction has
completed (i.e., the transfer of the $50 has taken place), the updates to the database by the
transaction must carry on even if there are software or hardware failures. 5
ACID Properties Examples
Consistency requirement :
T1 T2
1. read(A)
2. A := A – 50
3. write(A)
read(A), read(B), print(A+B)
4. read(B)
5. B := B + 50
6. write(B )
Isolation can be ensured trivially by running transactions serially
that is, one after the other.
However, executing multiple transactions concurrently has significant 7
Transaction State
8
Transaction State
Active – the initial state; the transaction stays in this state while it is executing.
Failed -- after the discovery that normal execution can no longer proceed.
Aborted – after the transaction has been rolled back and the database restored to
its state prior to the start of the transaction. Two options after it has been aborted:
restart the transaction
can be done only if no internal logical error
kill the transaction
T1 T2 T3
Read (X)
Read (Y)
Z=X+Y
Write (Z)
Read (Z)
Write Z)
Read (Z)
11
Log Based Recovery
To keep track of the database transactions, the DBMS maintains special file called
log files that contain information about all updates.
The log file contains information like Transaction Identifier, Data Item Identifier,
Old Value and New Value etc.
The information contained in the log files are critical for the database recovery, two
separate copies are maintained.
In the past the log files were stored on magnetic tape. But nowadays, DBMS are
expected to recover from minor failures very quickly so that log files are stored
online on a fast Direct Access Storage Devices (DASD).
The log file are periodically archived and are stored in off-line storage. These log
files are called “Archive Log File” 12
Checkpoints
13
Backup Mechanism
14
Shadow Paging
The shadow paging scheme does not require the use of log file in a single user
environment, though a log is needed in multi users environment for concurrency
control.
The shadow paging technique maintain two directories during the transaction
current directory and shadow directory.
When the transaction starts, the two directories are the same. The shadow
directory is saved to the disk and the current directory is used by the transaction.
The shadow directory is never changed and is used to restore the database in case
of a failure. During the transaction execution, the shadow directory is never
modified. 15
Distributed Database
Distributed Database System (DDBMS) is a collection of data with
different parts under the control of separate DBMSs running on
different computers.
16
Fig. Distributed Database between MFG./Sales/HQ
17
Advantage of Distributed Database
DDBMS allows each client/ site to store and maintain its own database,
causing immediate and efficient access to data.
It allows to access the data stored at remote sites. At the same time
users can retain the control to its own client/ site to access the local data.
If one site is not working due to any reason, the system will not be down
because other client/ site of the network can possible continue
functioning.
If a user need to access the data from multiple clients/sites then the
desired query can be subdivided into sub queries. 18
Disadvantage of Distributed Database
1. Horizontal Fragmentation
2. Vertical Fragmentation
3. Mixed Fragmentation
20
Horizontal Fragmentation
In Horizontal fragmentation records of a relation are divided into number of
subsets.
24
Vertical Fragmentation
Pack2 = Π date, cartoon, desp (packing)
Table :Pack2
Date Cartoon Desp
No.
18/04/2014 123 T
18/04/2014 124 F
18/04/2014 125 F
18/04/2014 126 T
18/04/2014 127 T
18/04/2014 128 F
26
Schedules
We know that transactions are set of instructions and these instructions
perform operations on database. When multiple transactions are
running concurrently then there needs to be a sequence in which the
operations are performed because at a time only one operation can be
performed on the database. This sequence of operations is known
as Schedule. Banking transaction system is the best example of
scheduling. The various type of Schedules are:
1. Serial Schedules
2. Non Serial Schedules
3. Conflict Schedules
4. View Schedules
27
Serial Schedules
Two schedules A and B are called serial schedule if the operations of each
transaction are executed consecutively , without any interleaved operation from
the other transaction.
Schedule A Schedule B
T1: T2: T1: T2:
read_item(X); read_item(X);
X:= X - N; X:= X + M;
write_item(X); write_item(X);
read_item(Y); read_item(X);
Y:=Y + N; X:= X - N;
write_item(Y); write_item(X);
read_item(X); read_item(Y);
X:= X + M; Y:=Y + N;
write_item(X); write_item(Y); 28
Non-Serial Schedules
Two schedules C and D are called non-serial schedule if the operations of each
transaction are executed non- consecutively with interleaved operation from the
other transaction.
Schedule C Schedule D
T1: T2: T1: T2:
read_item(X); read_item(X);
X:= X - N; X:= X - N;
read_item(X); write_item(X);
X:= X + M; read_item(X);
write_item(X); X:= X + M;
read_item(Y); write_item(X);
write_item(X); read_item(Y);
Y:=Y + N; Y:=Y + N;
write_item(Y); write_item(Y);
29
Conflict Schedules
Consider a schedule S in which there are two consecutive instructions I i and Ij
of the transactions Ti and Tj respectively .
Now we identified three rules that show that if two operations in a schedule
satisfy all these three condition then operations are said to conflict.
Conflicting Operations : The two operations become conflicting if all conditions satisfy:
• Both belong to separate transactions.
• They have the same data item.
• They contain at least one write operation
31
Here, S1 = S2. That means it is non-conflict.
Conflict Serializable Schedule
32
Conflict Equivalent
In the conflict equivalent, one can be transformed to another by swapping non-conflicting
operations. In the given example, S2 is conflict equivalent to S1 (S1 can be converted to S2 by
swapping non-conflicting operations).
Example:
Schedule S2 is a serial schedule because, in this, all operations of T1 are performed before starting
any operation of T2. Schedule S1 can be transformed into a serial schedule by swapping non-
conflicting operations of S1. 33
Conflict Equivalent
After swapping of non-conflict operations, the schedule S1 becomes:
T1 T2
Read(A)
Write(A)
Read(B)
Write(B)
Read(A)
Write(A)
Read(B)
Write(B)
34
Testing of Serializability
If a schedule is view equivalent to its serial schedule then the given schedule is
said to be View Serializable. Lets take an example.
37
View Schedules
Lets check the three conditions of view serializability:
Initial Read
In schedule S1, transaction T1 first reads the data item X. In S2 also transaction T1 first reads the data item X.
Lets check for Y. In schedule S1, transaction T1 first reads the data item Y. In S2 also the first read operation on
Y is performed by T1.
We checked for both data items X & Y and the initial read condition is satisfied in S1 & S2.
Final Write
In schedule S1, the final write operation on X is done by transaction T2. In S2 also transaction T2 performs the
final write on X.
Lets check for Y. In schedule S1, the final write operation on Y is done by transaction T2. In schedule S2, final
write on Y is done by T2.
We checked for both data items X & Y and the final write condition is satisfied in S1 & S2.
Update Read
In S1, transaction T2 reads the value of X, written by T1. In S2, the same transaction T2 reads the X after it is
written by T1.
In S1, transaction T2 reads the value of Y, written by T1. In S2, the same transaction T2 reads the value of Y
after it is updated by T1.
The update read condition is also satisfied for both the schedules.
Result: Since all the three conditions that checks whether the two schedules are view equivalent are satisfied in
this example, which means S1 and S2 are view equivalent. Also, as we know that the schedule S2 is the serial
schedule of S1, thus we can say that the schedule S1 is view serializable schedule. 38