When two or more transactions execute concurrently, their database operations are
executed in an interleaved fashion in order to make efficient use of the CPU. The
operations from one transaction may execute in between two operations from another
transaction. This interleaving may cause incorrect results leading to
an inconsistent database.
Simultaneous execution of transactions over a shared database can create several data
integrity and consistency problems when the transactions operate on the same
attributes. Some of the problems are :
1. Lost updates
2. Uncommitted Data
3. Inconsistent Retrievals
Lost Updates
This problem may occur when two concurrent transactions are updating the same data
values and one transaction overwrites the update made by the other transaction.
For Example:
Uncommitted Data
The Uncommitted Data problem may occur when two transaction T1 and T2 are
executed concurrently and the first transaction is rolled back after the second
transaction has already accessed the uncommitted data - thus violating the isolation
property of the transaction.
Transaction Computation
STORED
TIME TRANSACTION STEP
VALUE
1 T1 Read PROD_QOH 35
2 T1 PROD_QOH = 35 + 100
3 T1 Write PROD_QOH 135
Read PROD_QOH (Read uncommitted
4 T2 135
data)
5 T2 PROD_QOH = 135 - 30
6 T1 ** ROLLBACK ** 35
7 T2 Write PROD_QOH 105
Inconsistent Retrievals
Transaction Results :
BEFORE AFTER
PROD_CODE PROD_QOH PROD_QOH
104XCV 100 100
110YGH 120 120
125TYZ 70 (70 + 30) -> 100
345TYX 35 (35 - 30) -> 5
350TYX 100 100
355TYX 30 30
T1 : SUM 455 455
Inconsistent Retrievals:
The Scheduler
The scheduler establishes the order in which the operations within concurrent
transactions are executed.
The scheduler interleaves the execution of database operations to ensure
serializability.
To determine the appropriate order, the scheduler bases its actions on
concurrency control algorithms, such as locking or time stamping methods.
The scheduler also makes sure that the computer's CPU is used efficiently.
Locking Methods
Lock Granularity
Database Level
Prevents the use of any tables in the database by transaction T2 while
transaction T1 is being executed.
Table Level
Prevents access to any row by transaction T2 while transaction T1 is using the
table.
Page Level
A diskpage or page is the equivalent of a disk block that can be described as a
(referenced) section of a disk. A table can span several pages, and a page can
contain several rows of one or more tables.
Page-level locks are currently the most frequent used multi-user DBMS locking
methods.
Row Level
It is much less restrictive than the locks discussed above.
The DBMS allows concurrent transactions to access different rows of the same
table, even if the rows are located on the same page.
Although the row-level locking approach improves the availability of data, its
management requires high overhead cost.
Field Level
Allows concurrent transactions to access the same row, as long as they require
the use of different fields (attributes) within that row.
Although field-level locking clearly yields the most flexible multi-user data
access, it requires a high level or computer overhead.
Types of Locks
Shared/Exclusive Lock :
TIME T1 T2 Value
1 Request lock on PROD_QOH (granted) -- --
2 Read PROD_QOH (granted) -- 35
3 PROD_QOH = 35 + 100 Request lock on PROD_QOH (wait) 35
4 Write PROD_QOH Request lock on PROD_QOH (wait) 135
5 Release Lock on PROD_QOH Request lock on PROD_QOH (wait) 135
6 -- Lock on PROD_QOH granted 135
7 -- Read PROD_QOH 135
8 -- PROD_QOH = 135 - 30 135
9 -- Write PROD_QOH 105
RECOVERY
The DBMS uses a transaction log to keep track of all transactions that update the
database. The data in the log is used by the Recovery Manager to restore the database
to a consistent state after failure. DBMSs use one of two protocols in relation to when
data are saved to the physical database:
Deferred-write
Transaction operations do not immediately update the database. Instead, all
changes are written to the transaction log. The database is updated only after
the transaction reaches its commit point.
Immediate-write
The database is immediately updated by transaction operations during the
transaction's execution, even before the transaction reaches its commit point.
The transaction log is also updated. If a transaction fails, the database uses the
log information to roll back the database.
Types of Failures
1. Transaction Failures
2. System Failures
3. Media Failures
Transaction Failures
Some unplanned operation in the transaction which may cause it to fail, such
as:
o Illegal operation (e.g. integer overflow, division by zero)
o Interrupt (e.g. unintended keyboard error: user presses an escape
character)
Exception condition detected by the transaction (a planned failure), such as:
o Withdrawal of funds when there are insufficient funds in an account
o Data for transaction not found
System detects deadlock, that is, concurrency control mechanisms aborts one
transaction and reschedules it
The system aborts a failed transaction (that is, not committed) by rolling back or
undoing all the changes made by the aborted transaction.
System Failures
A system failure refers to the loss or corruption of the contents of volatile storage (that
is, main memory). For example:
Network failure
The critical point regarding system failure is that the contents of main memory are
lost.
The precise state of any transaction that was in progress at the time of the failure is
therefore no longer known; such a transaction can therefore never be successfully
completed, and so must be undone (rolled back) when the system restarts (in
immediate-write environment).
It may also be necessary to redo certain transactions at restart time that did
successfully complete prior to the crash but did not manage to get their updates
transferred to the physical database.
Physically writing the contents of the database buffers out to the physical
database, and
Physically writing a special checkpoint record out to the physical log, listing all
transactions that were in progress at the time the checkpoint was taken.
2. Search forward through the log, starting from the checkpoint record.
4. If a COMMIT log entry is found for transaction T, move T from the UNDO list
to the REDO list (T2, T4).
5. When the end of the log is reached, the UNDO and REDO lists identify,,
respectively, transactions of types T3 and T5, transactions of types T2 and T4.
The system now works backwards through the log, undoing the transactions in the
UNDO list writing the 'before' values in the transaction log to the physical database. It
then works forward again, redoing the transaction in the REDO list writing the 'after'
values in the transaction log to the physical database. When all such recovery is
complete, the system is ready to accept new work.
Media Failures
A media failure occurs when any part of the stable storage is destroyed. For instance:
Hardware induces failures, including disk crashes, bad disk sectors, disk full
errors, etc.
It is a major task to recover from these failures, which requires use of backup copy of
database.
One approach for dealing with media failures is archiving. Periodically, the value of
each data item is written or dumped to an archive database. The log contains (at least)
all of the updates applied to the database since the last dump. It is mportant to start a
new transaction log file immediately upon making an archive copy of the database. If
a media failure destroys the contents of the stable database, then we execute a Restart
algorithm using the log and archive database to bring the archive to the committed
state with respect to the log.
Bien plus que des documents.
Découvrez tout ce que Scribd a à offrir, dont les livres et les livres audio des principaux éditeurs.
Annulez à tout moment.