U N I T – III
Contents …………………………… Page No.
Introduction to Transaction Processing Concepts and Theory-
1. Introduction to Transaction Processing
a. Transaction Definition 1
b. Why Concurrency needed? 2
c. Why recovery is needed: What causes a Transaction to fail) 4
2. Transaction and System Concept (Transaction states and System Log) 4
3. Desirable Properties of Transactions (ACID Properties) 5
4. Characterizing Schedules Based on Recoverability 6
(schedule? Classification of schedules based on recoverability)
5. Characterizing schedules Based on Serializability 7
Conflict Serializability
View Serializability
Concurrency Control Techniques 8
6. Two-Phase Locking Techniques for Concurrency Control, Concurrency 9
7. Control Based on Timestamp Ordering. 10
Database Recovery Techniques
8. Recovery Concepts 11
9. Recovery Techniques Based on Deferred Update 12
10. Recovery Techniques Based on Immediate Update 13
11. Shadow paging. 14
0
INTRODUCTION TO TRANSACTION PROCESSING CONCEPTS AND THEORY-
1. INTRODUCTION TO TRANSACTION PROCESSING
1
Why Concurrency Control is needed:
The Lost Update Problem
This occurs when two transactions that access the same database items have their
operations interleaved in a way that makes the value of some database item incorrect.
The Temporary Update (or Dirty Read) Problem
This occurs when one transaction updates a database item and then the transaction fails
for some reason.
The updated item is accessed by another transaction before it is changed back to its
original value.
The Incorrect Summary Problem
If one transaction is calculating an aggregate summary function on a number of records
while other transactions are updating some of these records, the aggregate function
may calculate some values before they are updated and others after they are updated.
2
3
Why recovery is needed: (What causes a Transaction to fail)
1. A computer failure (system crash):
A hardware or software error occurs in the computer system during transaction execution. If the hardware
crashes, the contents of the computer’s internal memory may be lost.
2. A transaction or system error:
Some operation in the transaction may cause it to fail, such as integer overflow or division by zero.
Transaction failure may also occur because of erroneous parameter values or because of a logical
programming error. In addition, the user may interrupt the transaction during its execution.
3. Local errors or exception conditions detected by the transaction:
Certain conditions necessitate cancellation of the transaction. For example, data for the transaction may
not be found. A condition, such as insufficient account balance in a banking database, may cause a
transaction, such as a fund withdrawal from that account, to be canceled.
A programmed abort in the transaction causes it to fail.
4. Concurrency control enforcement:
The concurrency control method may decide to abort the transaction, to be restarted later, because it
violates serializability or because several transactions are in a state of deadlock.
5. 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.
6. Physical problems and catastrophes:
This refers to an endless list of problems that includes power or air-conditioning failure, fire, theft,
sabotage, overwriting disks or tapes by mistake, and mounting of a wrong tape by the operator.
2. TRANSACTION AND SYSTEM CONCEPT
A transaction is an atomic unit of work that is either completed in its entirety or not done at all.
o For recovery purposes, the system needs to keep track of when the transaction starts,
terminates, and commits or aborts.
Transaction states:
o Active state
o Partially committed state
o Committed state
o Failed state
o Terminated State
Recovery manager keeps track of the following operations:
o begin_transaction: This marks the beginning of transaction execution.
o read or write: These specify read or write operations on the database items that are executed
as part of a transaction.
4
o end_transaction: This specifies that read and write transaction operations have ended and
marks the end limit of transaction execution.
At this point it may be necessary to check whether the changes introduced by the
transaction can be permanently applied to the database or whether the transaction has
to be aborted because it violates concurrency control or for some other reason.
Recovery manager keeps track of the following operations (cont):
o 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.
o rollback (or abort): 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.
The System Log
Log or Journal: The log keeps track of all transaction operations that affect the values of
database items.
This information may be needed to permit recovery from transaction failures.
The log is kept on disk, so it is not affected by any type of failure except for disk or
catastrophic failure.
In addition, the log is periodically backed up to archival storage (tape) to guard
against such catastrophic failures.
3. DESIRABLE PROPERTIES OF TRANSACTIONS (ACID Properties)
Transactions should posses the following (ACID) properties: Transactions should possess several
properties. These are often called the ACID properties, and they should be enforced by the concurrency
control and recovery methods of the DBMS. The following are the ACID properties:
Atomicity: A transaction is an atomic unit of processing; it is either performed in its entirety or
not performed at all.
Consistency preservation: A correct execution of the transaction must take the database from
one consistent state to another.
5
Isolation: A transaction should not make its updates visible to other transactions until it is
committed; this property, when enforced strictly, solves the temporary update problem and makes
cascading rollbacks of transactions unnecessary (see Chapter 21).
Durability or permanency: Once a transaction changes the database and the changes are
committed, these changes must never be lost because of subsequent failure.
The atomicity property requires that we execute a transaction to completion. It is the responsibility of
the transaction recovery subsystem of a DBMS to ensure atomicity. If a transaction fails to complete for
some reason, such as a system crash in the midst of transaction execution, the recovery technique must
undo any effects of the transaction on the database.
4. CHARACTERIZING SCHEDULES BASED ON RECOVERABILITY
Transaction schedule or history:
When transactions are executing concurrently in an interleaved fashion, the order of
execution of operations from the various transactions forms what is known as a
transaction schedule (or history).
A schedule (or history) S of n transactions T1, T2, …, Tn:
It is an ordering of the operations of the transactions subject to the constraint that, for
each transaction Ti that participates in S, the operations of T1 in S must appear in the
same order in which they occur in T1.
Note, however, that operations from other transactions Tj can be interleaved with the
operations of Ti in S.
Schedules classified on recoverability:
Recoverable schedule:
One where no transaction needs to be rolled back.
A schedule S is recoverable if no transaction T in S commits until all transactions T’ that
have written an item that T reads have committed.
Cascadeless schedule:
One where every transaction reads only the items that are written by committed
transactions.
Schedules requiring cascaded rollback:
A schedule in which uncommitted transactions that read an item from a failed transaction
must be rolled back.
Strict Schedules:
A schedule in which a transaction can neither read or write an item X until the last
transaction that wrote X has committed.
6
5. CHARACTERIZING SCHEDULES BASED ON SERIALIZABILITY
Serial schedule:
A schedule S is serial if, for every transaction T participating in the schedule, all the
operations of T are executed consecutively in the schedule.
Otherwise, the schedule is called nonserial schedule.
Serializable schedule:
A schedule S is serializable if it is equivalent to some serial schedule of the same n
transactions.
Result equivalent:
Two schedules are called result equivalent if they produce the same final state of the
database.
Conflict equivalent:
Two schedules are said to be conflict equivalent if the order of any two conflicting
operations is the same in both schedules.
Conflict serializable:
A schedule S is said to be conflict serializable if it is conflict equivalent to some serial
schedule S’.
Being serializable is not the same as being serial
Being serializable implies that the schedule is a correct schedule.
It will leave the database in a consistent state.
The interleaving is appropriate and will result in a state as if the transactions were serially
executed, yet will achieve efficiency due to concurrent execution.
View equivalence:
A less restrictive definition of equivalence of schedules
View serializability:
Definition of serializability based on view equivalence.
A schedule is view serializable if it is view equivalent to a serial schedule.
Two schedules are said to be view equivalent if the following three conditions hold:
The same set of transactions participates in S and S’, and S and S’ include the same
operations of those transactions.
For any operation Ri(X) of Ti in S, if the value of X read by the operation has been
written by an operation Wj(X) of Tj (or if it is the original value of X before the schedule
started), the same condition must hold for the value of X read by operation Ri(X) of Ti in
S’.
If the operation Wk(Y) of Tk is the last operation to write item Y in S, then Wk(Y) of Tk
must also be the last operation to write item Y in S’.
7
The premise behind view equivalence:
As long as each read operation of a transaction reads the result of the same write
operation in both schedules, the write operations of each transaction must produce the
same results.
“The view”: the read operations are said to see the same view in both schedules.
Relationship between view and conflict equivalence:
The two are same under constrained write assumption which assumes that if T writes X,
it is constrained by the value of X it read; i.e., new X = f(old X)
Conflict serializability is stricter than view serializability. With unconstrained write (or
blind write), a schedule that is view serializable is not necessarily conflict serializable.
Any conflict serializable schedule is also view serializable, but not vice versa.
Testing for conflict serializability: Algorithm 17.1:
Looks at only read_Item (X) and write_Item (X) operations
Constructs a precedence graph (serialization graph) - a graph with directed edges
An edge is created from Ti to Tj if one of the operations in Ti appears before a
conflicting operation in Tj
The schedule is serializable if and only if the precedence graph has no cycles.
CONCURRENCY CONTROL TECHNIQUES
8
6. TWO-PHASE LOCKING TECHNIQUES FOR CONCURRENCY CONTROL
i. Types of Locks and System Lock Tables
9
Serializability by Two Phase Locking
7. CONCURRENCY CONTROL BASED ON TIMESTAMP ORDERING.
10
DATABASE RECOVERY TECHNIQUES
8. RECOVERY CONCEPTS
11
9. RECOVERY TECHNIQUES BASED ON DEFERRED UPDATE
12
10. RECOVERY TECHNIQUES BASED ON IMMEDIATE UPDATE
13
11. SHADOW PAGING.
14
15