L J Institute of Computer Applications Database Management Systems – II Semester -2 Weekly Test

Date : March 22, 2010 1. State if True or False a. b. c. d. e. Time : 9:30 – 10:30 (6)

There is a possibility of deadlock in Timestamp ordering protocol - False View serializable schedules are conflict serializable - False Basic two phase locking protocol schedules are non-recoverable - True Reading uncommitted data is also called “dirty read” - True A committed transaction that has performed updates transforms the database to a new consistent state. - True f. The recovery management component of the DBMS ensures the atomicity and the durability property of transactions - True 2. Define the following (attempt any three) (6)

a. Starvation b. Schedule c. Deadlock d. Recoverable Schedule a. Starvation : A process in which a transaction trying to acquire an exclusive lock is made to wait for a long duration of time, while other transactions requesting shared lock on a data item acquire the same , is said to be a state of starvation. e.g. Transaction T1 has acquired a shared lock on data item A. Transaction T2 requests an exclusive lock on A and is made to wait. In the meanwhile other transactions T3, T4 etc. acquire shared locks as they are compatible and T2 keeps waiting and is made a victim and is starved for the lock. b. Schedule A sequence of instructions that specify the chronological order, in which instructions of concurrent transactions are executed is called a schedule. A schedule can be formed by interleaving instructions of the transactions. A schedule must include all the instructions of the transactions that are included in the schedule. It must also preserve the order of the instructions of the transactions

Optimistic and pessimistic concurrency control a. then the commit operation of Ti appears before the commit operation of Tj. 3. Tj can also be rolled back and hence is recoverable. d. if Tj reads a data item previously written by a transaction Ti . Serial and Serializable schedule b. Conflict serializable 2. T1 requires a shared / exclusive lock on Y and is waiting for T2 to release the same.g. then such a condition leads to a deadlock. then for each such pair of transactions Ti and Tj. meanwhile T2 requires a shared / exclusive lock on X and is waiting for T1 to release the same. Recoverable Schedule In any schedule containing Ti and Tj.c. View serializable Serializable schedules are more efficient and make optimum usage of resources (4) Serial schedules are inefficient as they do not make optimum usage of resources . Deadlock is a problem that can happen with two phase locking. operations of different transactions which are part of the schedule can be interleaved A serializable schedule is considered to be correct if it is equivalent to a serial schedule. Here the two transactions have reached a deadlock state. Differentiate between a. e. The only way to come out of a deadlock situation is to abort one of the transactions. In case of a rollback of Ti . Serial Schedule and Serializable Schedule Serial Schedule In a serial schedule containing transaction Ti. Deadlock When two or more transactions are waiting for locks to be released by each other . They could be of the following types : 1. Transaction T1 has acquired an exclusive lock on data item X and transaction T2 has acquired an exclusive lock on Y. all the operations of Ti are executed consecutively and there is no interleaving of operations Serial schedules are correct and do not exhibit concurrency anamolies Serializable Schedule In a serializable schedule.

Dirty Read c. . and stop them by either making the transactions wait or rollback There may be deadlocks This method is preferable when there is a high level of concurrency e. Lost updates b.g. processes and commits.g.g. Explain the problems related to concurrency and why is concurrency control (5) required When concurrent transactions are executed in an uncontrolled manner then there could be several problems. Unrepeatable Read a. T1 Read (X) Read (Y) X= Y+50 Write (X) T2 Read(X) X=X+100 Write (X) Here the value of X written by T1 is lost. Dirty Read A dirty read problem occurs when one transaction reads an uncommitted value written by another transaction. There is no possibility of deadlocks. whereas the original transaction fails. e. Lost Update : Lost Update occurs when the two transactions attempt to update the same data item without committing and the updates of one of them is lost. Two phase locking.b) Optimistic and pessimistic concurrency control Optimistic Concurrency Control Optimistic concurrency control assumes that conflicts of database operations are rare and hence that there is no need to do checking during transaction execution. e. b. Validation based protocol` Pessimistic Concurrency Control Pessimistic concurrency control do not allow conflicts to happen. If there is a high level of concurrency then this method is not good and can result in large amount of rollbacks e. 4. The following three are the main problems : a.g. Time stamp ordering.

T1 Read (X) T2 Read(X) X= X+100 Write (X) Read(X) In the above example T1 will read two different values of X within the same transaction and this causes an inconsistency in the database. As concurrent execution of transactions is required to achieve increased throughput and better resource utilization and to protect the atomicity and consistency properties of the transaction the DBMS needs to implement concurrency control and this can be done by way of locking and time stamps. processes and commits. .T1 Read (X) X= X+50 Write(X) T2 Read(X) X= X+100 Write (X) Commit Fail In the above situation T2 uses the value of X written by T1. Dirty Read and Unrepeatable read. e. the DBMS needs a concurrency control mechanism. making the value of X used by T2 as inconsistent. The problem has happened here as T1 was not committed and T2 read the uncommitted value written by T1. c.g. Unrepeatable Read: An unrepeatable read occurs when one transaction reads a value of a data item and sees different values at both the times as there is another transaction that has updated this value. To prevent the concurrency anomalies like Lost Update. whereas T1 later fails.

which could be using the system clock or a logical counter based on the time the transaction started. 3. e. if transaction Ti was reading Q. as W-timestamp(X)=2 and is more than TS(T1).g T1 1. This protocol ensures that the read and write operations are executed in the timestamp order. then the write would be successful if TS(Ti) > W-Timestamp(Q) and TS(Ti) > R-timestamp(Q). In the Timestamp Ordering Protocol. the R-timestamp. On successful write. hence the read will not be successful and T1 will rollback. else the read operation would be rejected and the transaction would be rolled back. Transaction Ti that needs to read a dataitem will be allowed to read only if the timestamp Ti is greater than the W-timestamp value of the dataitem. Each data item is also assigned two timestamps each. which contains the value of the timestamp of the largest transaction that completed the read successfully and the W-timestamps. i. Similarly if the transaction Ti needs to write a dataitem. In this method each transaction is given a timestamp.e. 4. Read(X) 2.Explain the Timestamp Ordering Protocol with examples. Read(X) T2 Read(X) Write (X) Here lets say T1 has timestamp value 1 and T2 has timestamp value 2 The initial timestamp value for X will be W-timestamp(X)=0 and R-timestamp(X)=0 On instruction 1 W-timestamp(X)=0 and R-timestamp(X)=1 On instruction 2 W-timestamp(X)=0 and R-timestamp(X)=2 On instruction 3 W-timestamp(X)=2 and R-timestamp(X)=2 On instruction 4. the concurrency control is achieved by way of giving timestamps rather than locks. then the read would be successful if TS(Ti) > WTimestamp(Q) and on successful read R-timestamp(Q) will be set to the timestamp value of Ti. .e if transaction Ti was writing the value of dataitem Q. the W-timestamp(Q) will be set to the timestamp value of Ti. i. which contains the value of the timestamp of the transaction that last wrote that value successfully. then it will be allowed to write the value only if the R-timestamp and the W-timestamp value of the dataitem is less than that of the Transaction Ti. This method is free from deadlocks.

Lock_X(B) 4. Read (B) 2. If B=0 then A:=A+1 4. Lock_S(A) 2. Unlock (A) 8. Write(B) 7. Read(B) 5. 13. 16. so that they observe two phase locking protocol. 12. Consider the following two transactions T1 : 1. 15. If A=0 then B:=B+1 4. 11. Read(A) 3. Read(B) 3. Write(A) (4) Prepare a schedule by adding lock and unlock instructions to the transactions T1 and T2. Read(A) 2. Read(A) 3. Unlock(B) 9.5. Write(B) T2 : 1. T1 1. If A=0 then B=B+1 6. T2 Lock_S(B) Read (B) Lock_X(A) Read (A) If B=0 then A=A+1 Write(A) Unlock(A) Unlock(B) . 10. 14.

Sign up to vote on this title
UsefulNot useful