Dhanalakshmi College of Engineering, Chennai
Dhanalakshmi College of Engineering, Chennai
2. List out the SQL statements used for transaction control. (N/D – 11)
The SQL standard specifies that a transaction begin implicitly. Transactions are ended by
one of these SQL statements:
a. Commit work commits the current transaction and begins a new one
b. Rollback work causes the current transaction to abort
7. Write the two commonly used concurrency control techniques. (N/D – 11)
Commonly used concurrency control techniques are:
a. Two-Phase locking
b. Concurrency control based on Timestamp ordering
c. Multi-version Concurrency Control techniques
d. Lock Compatibility Matrix
e. Lock Granularity
13. What are the advantages of two phase locking protocol? (M/J–12)
The advantages of two phase locking protocol are:
produces only cascade less schedules
Recovery is very easy
14. What are the phases of two Phase locking protocol?
The phases of two phase locking protocol are,
Growing phase: A transaction may obtain locks but not release any lock and
Shrinking phase: A transaction may release locks but may not obtain any new locks
1. How can you implement atomicity in transactions? Explain. (A/M – 10) (8 Marks)
2. Describe the concept of serilalizability with suitable example. (A/M – 10, M/J – 11) (8
Marks)
The concept of serilalizability:
1. Each transaction preserves database consistency.
2. Thus serial execution of a set of transactions preserves database consistency
3.A (possibly concurrent) schedule is serializable if it is equivalent to a serial schedule.
Different forms of schedule equivalence give rise to the notions of:
1. Conflict Serializability
2.View Serializability
3. How concurrency is performed? Explain the protocol that is used to maintain the
concurrency concept. (A/M – 10) (16 Marks)
They are multiple transactions that are allowed to run currently in the system
Advantages of concurrent executions
1.Increased processor and disk utilization, leading to better transaction
throughput: one transaction can be using the CPU while another is reading from or
writing to the disk.
2.Reduced average response time for transactions: short transactions need not
wait behind long ones.
Schedules
Schedules are sequences that indicate the chronological order in which
instructions of concurrent transactions are executed.
1.A schedule for a set of transactions must consist of all instructions of those
Transactions
2.Must preserve the order in which the instructions appear in each individual
transaction.
Example Schedules
Let T1 transfer $50 from A to B, and T2 transfer 10% of the Balance from A to B. The
following is a Serial Schedule in which T1 is followed by T2.
Let T1 and T2 be the transactions defined previously. The schedule 2 is not a serial
schedule,but it is equivalent to Schedule 1.In both Schedules 1 and 3, the sum A+ B is
preserved.
The Schedule in Fig-3 does not preserve the value of the sum A+ B.
Recoverability
Recoverable schedule — if a transaction Tj reads a data items previously written
by a transaction Ti, the commit operation of Ti appears before the commit operation
of Tj.
Cascading rollback:
Definition: If a single transaction failure leads to a series of transaction rollbacks, It is called as
cascaded rollback.
Consider the following schedule where none of the transactions has yet committed
1. If T10 fails, T11 and T12 must also be rolled back.
2. Can lead to the undoing of a significant amount of work
Cascade less schedules:
The cascading rollbacks cannot occur; for each pair of transactions Ti and Tj such that
Tj reads a data item previously written by Ti, the commit operation of Ti appears before
the read operation of Tj.
1. Every cascade less schedule is also recoverable
2. It is desirable to restrict the schedules to those that are cascade less.
Introduction
This is a protocol, which ensures conflict-serializable schedules.
Lock points: It is the point where a transaction acquired its final lock.
– Two-phase locking does not ensure freedom from deadlocks
– Cascading rollback is possible under two-phase locking.
– There can be conflict serializable schedules that cannot be obtained if
two-phase locking is used.
Given a transaction Ti that does not follow two-phase locking, we can find a
transaction Tj that uses two-phase locking, and a schedule for Ti and Tj that is not
conflict serializable.
Lock Conversions
Two-phase locking with lock conversions:
First Phase:
_ can acquire a lock-S on item
_ can acquire a lock-X on item
_ can convert a lock-S to a lock-X (upgrade)
Second Phase:
This protocol assures serializability. But still relies on the programmer to insert
the various locking instructions.
5. Briefly explain transaction recovery with primitive operations. (N/D – 10) (6 Marks)
Recoverability
Recoverable schedule — if a transaction Tj reads a data items previously written
by a transaction Ti, the commit operation of Ti appears before the commit operation
of Tj.
Cascading rollback:
Definition: If a single transaction failure leads to a series of transaction rollbacks, It is
called as cascaded rollback.
Consider the following schedule where none of the transactions has yet committed
1.If T10 fails, T11 and T12 must also be rolled back.
2. Can lead to the undoing of a significant amount of
work
Cascade less schedules:
The cascading rollbacks cannot occur; for each pair of transactions Ti and Tj such that
Tj reads a data item previously written by Ti, the commit operation of Ti appears before
the read operation of Tj.
1.Every cascade less schedule is also recoverable
2.It is desirable to restrict the schedules to those that are cascade less.
Isolation. Although multiple transactions may execute concurrently, each transaction must be
unaware of other concurrently executing transactions. Intermediate transaction results must be
hidden from other concurrently executed transactions. That is, for every pair of transactions Ti
and Tj, it appears to Ti that either Tj finished execution before Ti started, or Tj started execution
after Ti finished.
Durability. After a transaction completes successfully, the changes it has made to the database
persist, even if there are system failures.
Atomicity requirement — if the transaction fails after step 3 and before step 6, the system
should ensure that its updates are not reflected in the database, else an inconsistency will result.
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
persist despite failures.
Isolation requirement — if between steps 3 and 6, another transaction is allowed to access the
partially updated database, it will see an inconsistent database (the sum A+ B will be less than it
should be).
ACID properties
1.Atomicity - ‘all or nothing’, transaction is an indivisible unit that is either performed in its
entirety or not at all
2. Consistency - a transaction must transform the database from one consistent state to another.
3. Isolation - transactions execute independently of one another. partial effects of incomplete
transactions should not be visible to other transactions
4. Durability - effects of a successfully completed (committed) transaction are stored in DB and
not lost because of failure.
7. Discuss in detail about transaction recovery, system recovery and media recovery.
(M/J – 12) (16 Marks)
Instance Recovery
1.Oracle physically updates data using LRU algorithm
2. State of database at failure time is complex.
3. Results of committed tx. stored on disc
4. Results of committed tx. stored in memory buffers
5. Results of UNcommitted tx. stored on disc
6. Results of UNcommitted tx. stored in memory buffers
System Recovery
Consequently:
1.SHUTDOWN trashes the memory buffers - recovery used disk data and:
2. ROLLS FORWARD: re-apply committed tx. on log which holds before/after images of
updated rec.
3. ROLLBACK uncommitted tx. already written to database using rollback segments.
Media Recovery
1. Disk failure - recover from backup tape using Oracle EXPORT/IMPORT
2. Necessary to also backup log files and control files to tape
3. DBA decide to keep complete log archives which are costly in terms of:
1.Time
2. Space
3. Administrative overheads
OR
1. Cost of manual re-entry
2. Log archiving provides the power to do on-line backups without shutting down
the system, and full automatic recovery. It is obviously a necessary option for
operationally critical database applications.
Deferred Update
1. No physical updates to db until after a transaction commits.
2. During the commit, log records are made then changes are made permanent on
disk.
3. What if a Transaction fails?
4.No UNDO required
5.REDO may be necessary if the changes have not yet been made permanent
before the failure.
Immediate Update
1.Physical updates to db may happen before a transaction commits.
2. All changes are written to the permanent log (on disk) before changes are made
to the DB.
3. What if a Transaction fails?
4.After changes are made but before commit – need to UNDO the changes
5.REDO may be necessary if the changes have not yet been made permanent
before the failure.