UNIT-4-Database Management System-BCA-22-403
UNIT-4-Database Management System-BCA-22-403
UNIT-IV
Transaction Processing
A DBMS is called multi-user if many user many user use the system
and, hence access database concurrently. On the other hand in
single-user if at most one user can use a system at a time. The
model of a database is used to explain a transaction-processing
concept is much simplified. A database is basically represented as a
collection of named data items. The size of the data is called
granularity, and it can be field of some record in the database, or it
may be large unit such as record or even whole disk. One
T1 T2
read_item(X)
X:= X-N; read_item (X);
X:=X+M;
write_item(X);
read_item(Y);
write_item(X);
Time
Item X has an incorrect value because its
Y=Y+N; update by T1 is “lost” (overwritten)
write_item(Y);
T1 T2
read_item(X)
X:= X-N;
read_item (X);
X:=X+M;
write_item(X);
Time
read_item(Y);
T1 T2
sum:=0;
read_item(X)
read_item (X);
X:=X-M;
write_item(X);
read_item (Y);
X:=X-M;
write_item(Y);
The Above Figure shows an example where T1 updates item X and
then fails before competition, so the system must change X back to
its original value. Before it can do so, however, transaction T2 reads
the “temporary” value of X, which will not be recorded permanently
in the database because it has been created by a transaction that has
not been done yet; this problem is known as dirty read problem.
Active: The initial state; the transaction stays in this state while it is
executing.
Partially committed: After the final statement has been executed.
Committed: After successful completion of transaction itself. We
can say that a transaction has committed only if it has entered the
committed only if it has entered into committed state.
Failed: After the discovery that normal execution has been rolled
back and the database have been restored to its state prior to start
of the transaction.
Partially Committed
Committed
Active
Failed Aborted
System Failure
The transaction is said to have been committed at the point where
the updated db pointer is written to disk. If the transaction fails at
any time before db-pointer is updated, the old content of the
database re not affected. We can abort the transaction by just
deleting the new copy of database. Once the transaction has been
committed, all the updates that it performed are in the database
pointed to by db pointer. Thus, either all updates of the transaction
are reflected, or none of the effects are reflected regardless of
transaction failure.
Review Questions
1. What is mean by the concurrent execution of database
transaction in multi-user system?
2. Draw a state diagram, and discus the typical state transaction
goes through during execution.
3. Define the term system failure and recoverability.
Database Recovery
1. Transaction Failure
Logical Error
Transaction can no longer continue with its normal executing
due to some internal condition such as bad input, data not
found, overflow or recourse limit exceeded.
Physical Error
The system has entered an undesirable state such as deadlock.
2. System Crash
There is a hardware manufacture problem or a bug in the database
software or operating system that causes the loss of the content of
volatile storage and brings the transaction processing to a halt. The
content of the non-volatile storage remains intact and is not
corrupted.
3. Disk Failure
A disk block loses its content as a result of either a head crash or
failure during a data transfer operation.
Recovery Techniques: Conceptually, there are two main
techniques for recovery from non-catastrophic transaction failures:
Immediate Update
The database may be updated by some operations of a transaction
before the transaction reaches its commit point. However, these
operations are transaction before the transaction typically recorded
in the log on disk by force writing before they are applied to the
database, making recovery still possible. If a transaction fails after
recording some changes in the database but before reaching its
commit point, the effect of its operation on the database must be
undone. That is the transaction must be rolled back. However, these
operations are typically recorded in the log file.
Shadow Paging
The recovery system does not require the use of a log in single user
environment. In a multi user environment, a log may be needed for
the concurrency control method. Shadow paging considers the
database is stored in number of fixed size pages or disk blocks for
recovery purpose.
This recovery scheme does not require the use of a log in a single-
user environment. In a multi-user environment, a log may be needed
for the concurrency control method. A directory with n entries is
constructed, where the ith entry point to ith database page on disk.
The directory is kept in main memory if it is not too large, and all
references, reads or writes to database pages on disk go through it.
The shadow directory is then saved on disk while the current
directory is used by transaction.
Transaction Rollback
A Transaction may have updated a data item more than once.
< Ti, A, 10, 20>
<Ti, A, 20, 30>
The scanning of the log terminates when the log records <Ti, start>
is found
The value 10 will be restored in the rollback.
Check Points
Use checkpoints to reduce the number of log records that are
scanned when the system recovers from a crash. Consider the
situation when transaction can execute concurrently. Several
transactions may have been active time of most recent checkpoint.
These checkpoints may be in form of <Checkpoint L>, where L is the
list of transaction active at the time of checkpoint.
Restart Recovery
Generally, system recovers from crash that constructs two lists undo
list and redo list. Initially these both list are empty. We can scan
backward, examining each record until the first <checkpoint>
record is found.
(i) For each record found of the form <Ti commit>, we add Ti
to redo-list.
(ii) For each record found of the form < Ti, start>, if Ti is not in
redo-list, then we add Ti to undo-list.
We can check the list L in the check point record. For each
transaction Ti in L, if Ti is not in redo-list then we add Ti to undo-list.
Buffer Management
Every log record is output to stable storage at the time it is created.
Typically output to stable storage is in units of blocks. The cost of
performing the output of a block to stable storage is sufficiently high
that is desirable to output multiple records at once. To do so, we
write log records to a log buffer in main memory, where they stay
temporarily until they are output to stable storage. Multiple log
records can be gathered in the log buffer and output to stable
storage in a single output operation.
Database Buffering
It is necessary to overwrite a block B1 in main memory when
another block B2 needs to be brought into memory. If B1 has been
modified, B1 must be output prior to the input of B2. If B1 has been
modified, B1 must be output prior to the input of B2.
Review Questions