You are on page 1of 7

HW4

PART-A

Question 1: What variations are possible on two-phase locking protocol?


Ans::
There are three variations of two phase locking protocol. These are as follows:

• Strict Two phase locking protocol: This variation of two phase protocol is used to avoid
cascading rollbacks. In addition to two-phase locking, it requires that all the exclusive
mode locks acquired by a transaction must be held until that transaction commits.

• Rigorous two phase locking protocol: this protocol is further modification of strict two
phase locking. In addition to two phase locking, it requires that all the locks acquired by a
transaction must be held until that transaction commits.

• Two phase locking with lock conversion: this protocol adds the ability of lock
conversion to the basic two phase locking. It means that we can convert a shared lock to
an exclusive lock(called as upgrading) and an exclusive lock to a shared lock(called as
downgrading). The upgrade instruction is used to convert a shared lock to an exclusive
lock. The downgrade instruction is used to convert an exclusive lock to shared loc.
Upgrading is done in the growing phase whereas downgrading is done only in the
shrinking phase.

Question 2: “Thomas write rule modifies the time-stamp ordering protocol”.


Do you agree? Justify your answer.
Ans::
Thomas write rule modifies the time-stamp ordering protocol. Yes, we agree and it operates as
follows:
Suppose that transaction T issues read(Q) operation then,
• If TS(T)<W-Timestamp(Q) then, T is trying to read a value of Q that was already
overwritten, hence abort read operation and T is rolled back.

• If TS(T)>=W-Timestamp(Q) then, execute read operation and set

R-Timestamp (Q)=Max(R-Timestamp(Q),TS(T)).
Suppose that transaction T issues write(Q) operation the,
• If TS(T)<R-Timestamp(Q) then, abort write operation and rollback T.

• If TS(T)<W-Timestamp(Q) then, ignore write operation.


• Otherwise, execute write operation and set W-Timestamp(Q)=TS(T).

Question 3:”In databases is there a possibility of deadlocks”. If yes why? In


how a many ways, deadlocks can be handled?
Ans::
Deadlock between two transactions occurs when eac transaction is waiting for a lock to be
released by each other.
For example: consider two transactions T1 and T2. T1 holds a lock on data item X and T2 holds on
data item Y. At the same time, T1 is requesting for a lock on data item Y and T2 is requesting for
a lock on data item X. But none of the transaction will release the lock and keep on waiting for a
new lock. Thus, these two transactions can’t proceed and said to be deadlocked.
Deadlock can also occur between more than two transactions. There are three methods of
handling deadlock:
• Deadlock prevention

• Time-out based scheme

• Deadlock detection and deadlock recovery

PART-B

Question 4: Compare deferred and immediate database modifications with


help of an example.

Ans::

Deferred Database Modification

What?

- Ensures transaction atomicity by recording all database

modification in the log, but deferring the execution of all write

operations of a transaction until the transaction partially commits.

- Not use undo :


If system crashes or the transaction aborts, then the information

on the log is simply ignored.

- Operation :

<Ti , start> : Before starts its execution, log record is written to the log.

<Ti , Xj , V2> : The write operation by Ti results in the writing of new record

to the log.

<Ti , commit> : When Ti partially commis, this record is written to the log.

Example

- Let T1 be a transaction that transfers 100 won from account A

to account B. This transaction may be defined as :

T1 : Read(A, a)

a = a - 100

Write(A, a)

Read(B, b)

b = b + 100

Write(B, b)

Let T2 be a transaction that withdraws 200 won from account C.

This transaction can be defined as :

T2 : Read(C, c)

c = c - 200

Write(C, c)

State of log and database


- A result of the execution T1 and T2, Note that the value of A is

changed in database only after the record <T1, A, 900> :

• Redo(Ti)

which sets the value of all data items updated by transaction Ti

to the new values in the order of log records.

• Determine which transactions need to redo

(1) redo :

The log contains both the record <T1, start > and the record

< T1, commit >.

This transaction may be or may not be stored disk physically.

Immediate Database Modification

What?

- Uncommitted modifications : Allows database modifications to

be output to database while the transaction is still in the


active state.

- Use undo :

If system crashes or the transaction aborts, then the old-value

field of log record is used to restore.

• Log Record Format :

<Ti , Xj , Vold ,Vnew>

• Undo(Ti)

which restores the value of all data items updated by transaction

Ti to the old values.

Example

State of log and database

- A result of the execution T1 and T2, Note that the value of A is

changed in database before partially committed :


• Two Recovery Schemes :

(1) Undo(Ti) :

If the log contains the record <Ti, start > but does not contain

the record < Ti, commit >.

 This transaction is crashed during execution. Thus transaction Ti

needs to be undone.

(2) Redo(Ti) :

If the log contains both the record <Ti, start > and the record

< Ti, commit >.

 This transaction is crashed just after partially committed.

Thus transaction Ti needs to be undone.

Question 5: Assume that the Railway reservation system is implemented using


an RDBMS. What are the concurrency control measures one has to take, in
order to avoid concurrency related problems in the above system? How can
the deadlock be avoided in this system?
Ans::
Concurrency control deals with preventing concurrently running processes from improperly
inserting, deleting, or updating the same data. Concurrency control is maintained through two
mechanisms: Transactions and Locks.
Transactions are a mandatory facility for maintaining the integrity of a database while running
multiple concurrent operations. A transaction is a logical unit of work. It is both the unit of work
and the unit of recovery. The s tatements nested within a transaction must either all happen or
none happen. Transactions are atomic: there is no such thing as a partial transaction. A set of
transactions is said to be serializable if and only if it produces the same result as some arbi trary
serial execution of those same transactions for arbitrary input. A set of transactions can be correct
only if it is serializable.
A lock is a means of claiming usage rights on some resource. There can be several different types
of resources that can be locked and several different ways of locking those resources. Most locks
used on Teradata resources are locked automatically by default. The Teradata lock manager
implicitly locks the following objects: Database, Table, View and Row hash. User can apply four
different levels of locking on Teradata resources: Exclusive, Write, Read and Access. The
Teradata R DBMS applies most of its locks automatically.

Question 6: “Shadow paging uses the concept of paging scheme (in operating
system)”. Do you agree? Justify your answer.
Ans::
Shadow paging uses the concept of paging scheme. As we know that paging scheme is used in
operating system for virtual memory management
Paging scheme divides the physical memory into a number of fixed-size blocks called as frames
and it divides the logical memory into a number of fixed-size blocks called as pages. The frame
size is same as that of page size. The logical pages are mapped with the help of page table.
Shadow paging divides database into a number of fixed-size blocks called as pages and it also
treats the physical memory to be composed of a number of fixed-size blocks called as frames.
The database pages are mapped into physical frames with the help of two page tables and they
are:
• Current page table

• Shadow page table

You might also like