Lecturenotes BCS403 Databasemanagementsystem
Lecturenotes BCS403 Databasemanagementsystem
MoModule -4
BCS403-Database Management System
Transaction Processing
R.THARANI,AP,AIML,SSCE,ANEKAL Page 1
SCHEME - 2022
MoModule -4
BCS403-Database Management System
In a multiuser DBMS, the stored data items are the primary resources that may be
accessed concurrently by interactive users or application programs, which are constantly
retrieving information from and modifying the database.
Transactions, Database Items, Read and Write Operations, and DBMS Buffers
A transaction is an executing program that forms a logical unit of database processing. A
transaction includes one or more database access operations—these can include
insertion, deletion, modification (update), or retrieval operations.
The database operations that form a transaction can either be embedded within an
application program or they can be specified interactively via a high-level query
language such as SQL.
One way of specifying the transaction boundaries is by specifying explicit begin
transaction and end transaction statements in an application program; in this case, all
database access operations between the two are considered as forming one transaction.
If the database operations in a transaction do not update the database but only retrieve
data, the transaction is called a read-only transaction; otherwise it is known as a read-
write transaction.
A database is basically represented as a collection of named data items. The size of a
data item is called its granularity.
A data item can be a database record, but it can also be a larger unit such as a
whole disk block, or even a smaller unit such as an individual field (attribute) value
of some record in the database.
Using this simplified database model, the basic database access operations that a
transaction can include are as follows:
R.THARANI,AP,AIML,SSCE,ANEKAL Page 2
SCHEME - 2022
MoModule -4
BCS403-Database Management System
The DBMS will maintain in the database cache a number of data buffers in main
memory.
A transaction includes read_item and write_item operations to access and update the
database.
The read-set of a transaction is the set of all items that the transaction reads, and the
write-set is the set of all items that the transaction writes.
MoModule -4
BCS403-Database Management System
to execute many different transactions, each with a different flight number, date, and
number of seats to be booked.
Figure 20.2(a) shows a transaction T1 that transfers N reservations from one flight
whose number of reserved seats is stored in the database item named X to another
flight whose number of reserved seats is stored in the database item named Y.
This problem occurs when two transactions that access the same database items have
their operations interleaved in a way that makes the value of some database items
incorrect.
This problem occurs when one transaction updates a database item and then the
transaction fails for some reason.
Another problem that may occur is called unrepeatable read, where a transaction T
reads the same item twice and the item is changed by another transaction T′ between
the two reads.
MoModule -4
BCS403-Database Management System
Types of Failures
Failures are generally classified as transaction, system, and media failures.
There are several possible reasons for a transaction to fail in the middle of execution:
Disk failure
Some disk blocks may lose their data because of a read or write malfunction or
because of a disk read/write head crash. This may happen during a read or a write
operation of the transaction.
R.THARANI,AP,AIML,SSCE,ANEKAL Page 5
SCHEME - 2022
MoModule -4
BCS403-Database Management System
A transaction is an atomic unit of work that should either be completed in its
entirety or not done at all. For recovery purposes, the system needs to keep track of
when each transaction starts, terminates, and commits, or aborts.
Therefore, the recovery manager of the DBMS needs to keep track of the following
operations:
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.
COMMIT_TRANSACTION
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.
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.
Figure 20.4 shows a state transition diagram that illustrates how a transaction moves
through its execution states.
R.THARANI,AP,AIML,SSCE,ANEKAL Page 6
SCHEME - 2022
MoModule -4
BCS403-Database Management System
A transaction goes into an active state immediately after it starts execution, where it can
execute its READ and WRITE operations. When the transaction ends, it moves to the
partially committed state.
When a transaction is committed, it has concluded its execution successfully and all its
changes must be recorded permanently in the database, even if a system failure occurs.
Protocols for recovery that avoid cascading rollbacks which include nearly all practical
protocols—do not require that READ operations are written to the system log.
R.THARANI,AP,AIML,SSCE,ANEKAL Page 7
SCHEME - 2022
MoModule -4
BCS403-Database Management System
Beyond the commit point, the transaction is said to be committed, and its effect must be
permanently recorded in the database.
Transactions that have written their commit record in the log must also have recorded
all their WRITE operations in the log, so their effect on the database can be redone from
the log records.
At the time of a system crash, only the log entries that have been written back to disk
are considered in the recovery process if the contents of main memory are lost.
Hence, before a transaction reaches its commit point, any portion of the log that has not
been written to the disk yet must now be written to the disk.
This process is called force-writing the log buffer to disk before committing a
transaction.
In a DBMS, various types of disk pages exist: index pages, data file pages, log file
pages, and so on. In this method, the DBMS cache is divided into separate domains
(sets of buffers).
Each domain handles one type of disk pages, and page replacements within each
domain are handled via the basic LRU (least recently used) page replacement.
The hot set method determines for each database processing algorithm the set of
disk pages that will be accessed repeatedly, and it does not replace them until their
processing is completed.
This page replacement algorithm is useful in queries that have to scan a set of
pages repeatedly, such as when a join operation is performed using the nested-loop
method.
R.THARANI,AP,AIML,SSCE,ANEKAL Page 8
SCHEME - 2022
MoModule -4
BCS403-Database Management System
This page replacement policy uses a model known as QLSM (query locality set
model), which predetermines the pattern of page references for each algorithm for a
particular type of database operation.
The DBMIN page replacement policy will calculate a locality set using QLSM for
each file instance involved in the query.
The concept of locality set is analogous to the concept of working set, which is
used in page replacement policies for processes by the operating system but there
are multiple locality sets, one for each file instance in the query.
Levels of Isolation.
R.THARANI,AP,AIML,SSCE,ANEKAL Page 9
SCHEME - 2022
MoModule -4
BCS403-Database Management System
Two operations in a schedule are said to conflict if they satisfy all three of the
following conditions: (1) they belong to different transactions; (2) they access the
same item X; and (3) at least one of the operations is a write_item(X).
For example, in schedule Sa, the operations r1(X) and w2(X) conflict, as do the
operations r2(X) and w1(X), and the operations w1(X) and w2(X).
Intuitively, two operations are conflicting if changing their order can result in a
different outcome.
For example, if we change the order of the two operations r1(X); w2(X) to w2(X);
r1(X), then the value of X that is read by transaction T1 changes, because in the
second ordering the value of X is read by r1(X) after it is changed by w2(X), whereas
in the first ordering the value is read before it is changed.
This is called a read-write conflict. The other type is called a write-write conflict and
is illustrated by the case where we change the order of two operations such as
w1(X); w2(X) to w2(X); w1(X).
R.THARANI,AP,AIML,SSCE,ANEKAL Page 10
SCHEME - 2022
MoModule -4
BCS403-Database Management System
For the schedule to be recoverable, the c2 operation in Sc must be postponed until after
T1 commits, as shown in Sd.
If T1 aborts instead of committing, then T2 should also abort as shown in Se, because
the value of X it read is no longer valid. In Se, aborting T2 is acceptable since it has not
committed yet, which is not the case for the nonrecoverable schedule Sc.
R.THARANI,AP,AIML,SSCE,ANEKAL Page 11
SCHEME - 2022
MoModule -4
BCS403-Database Management System
These two schedules—called serial schedules—are shown in Figures 20.5(a) and (b),
respectively. If interleaving of operations is allowed, there will be many possible orders
in which the system can execute the individual operations of the transactions.
Two possible schedules are shown in Figure 20.5(c). The concept of serializability of
schedules is used to identify which schedules are correct when transaction executions
have interleaving of their operations in the schedules.
R.THARANI,AP,AIML,SSCE,ANEKAL Page 12
SCHEME - 2022
MoModule -4
BCS403-Database Management System
Two schedules are said to be conflict equivalent if the relative order of any two conflicting
operations is the same in both schedules.
R.THARANI,AP,AIML,SSCE,ANEKAL Page 13
SCHEME - 2022
MoModule -4
BCS403-Database Management System
Serializable Schedules
R.THARANI,AP,AIML,SSCE,ANEKAL Page 14
SCHEME - 2022
MoModule -4
BCS403-Database Management System
MoModule -4
BCS403-Database Management System
A blind write is a write operation in a transaction T on an item X that is not dependent
on the old value of X, so it is not preceded by a read of X in the transaction T.
The definition of view serializability is less restrictive than that of conflict serializability
under the unconstrained write assumption, where the value written by an operation
wi(X) in Ti can be independent of its old value.
MoModule -4
BCS403-Database Management System
The access mode can be specified as READ ONLY or READ WRITE. The default is READ
WRITE, unless the isolation level of READ UNCOMMITTED is specified (see below), in
which case READ ONLY is assumed.
A mode of READ WRITE allows select, update, insert, delete, and create commands to be
executed. A mode of READ ONLY, as the name implies, is simply for data retrieval.
If a transaction executes at a lower isolation level than SERIALIZABLE, then one or more
of the following three violations may occur:
3. Phantoms. A transaction T1 may read a set of rows from a table, perhaps based on
some condition specified in the SQL WHERE-clause.
phantom record because it was not there when T1 starts but is there when T1 ends.
R.THARANI,AP,AIML,SSCE,ANEKAL Page 17
SCHEME - 2022
MoModule -4
BCS403-Database Management System
Snapshot Isolation
Another isolation level, known as snapshot isolation, is used in some commercial
DBMSs, and some concurrency control protocols exist that are based on this concept.
The basic definition of snapshot isolation is that a transaction sees the data items that it
reads based on the committed values of the items in the database snapshot (or
database state) when the transaction starts.
Snapshot isolation will ensure that the phantom record problem does not occur, since
the database transaction, or in some cases the database statement, will only see the
records that were committed in the database at the time the transaction starts.
Any insertions, deletions, or updates that occur after the transaction starts will not be
seen by the transaction.
R.THARANI,AP,AIML,SSCE,ANEKAL Page 18