Dbms. 4

You might also like

Download as pdf
Download as pdf
You are on page 1of 40
UNIT TRANSACTION MANAGEMENT, aS CONCURRENCY CONTROL = Caoup PART-A SHORT QUESTIONS WITH SOLUTIONS Q1. Explain the ACID Properties of transaction with example Answer + ay-19(R16), 10) ACID Properties ‘These are the properties that a transaction should posses in order to avoid failures during concurrent access of a database. ACID isan acronym which stands for Atomicity, Consistency, Isolation and Durability. 1. Atomic ‘Atomicity ensures that the transaction is either executed completely or not executed at all. Incomplete transaction consequences are not valid. Consider the example of a transaction involving crediting and debiting the account. ‘Suppose Pavani had & 500/- in her account and Vasavi has & 200/- in her account. Now Pavani transfers a amount of & S0V- to Vasavi. A’transaction debits the amount from Pavani’s account, but before it could be credited to Vasavi, if there is a fail- ture then transaction would result in loss of & S0/-. Because, the amount is deducted from Pavani’s account but itis not added to ‘Vasavi's account. This leaves the data in an inconsistent state. If there is a failure during transaction execution, then measures are taken to get back the data in a form which was in, before transaction. This is taken care by transaction management component. 2. Consistency The data inthe database must always be in a consistent state, A transaction that is carried on a consistent data should bring the data to another consistent state after execution. However, transaction need not maintain consistency at intermediate stages. For example, consider a transaction that involves transfer of amount. If amount is debited from account-‘A’ and credited ‘to account-"B’ after the transaction then the sum A +B should be same as it was before transaction. However, at an intermediate stage, where the amount is deducted from 4 but not yet credited to B, the sum A + B would not be same and it need not be. The result is an inconsistent transaction. Its the responsibility of application program to ensure consistency. Isolation All transactions must run in isolation from one another that is every transaction should be kept unaware of other transactions and execute independently. The intermediate results generated by the transactions should not be available to other transactions, 4. Durability ‘This property ensures that data remains in a consistent state even after the failure. This is ensured by loading modified data into disk. This task is handled by recovery-management component of DBMS. It ensures that cither the complete modified data is loaded into disk or the information that would be sufficient to get the modified data is loaded in disk. This enables a system to recover after a system crash, SPECTROM ALL-IN-ONE JOURNAL FOR ENGINEERING STUDENTS SIA GROUP WS ENT SYSTEMS [JNTU-HYOERABAD} a2 DATABASE MANAGEM >_> ——_———— Q2. Whats a transaction failure? Answer : Model Paper, Q1(a) ‘Atransaction may filo execute is intended operation when either logic ertrs or system erToF ‘encountered. Logic errors occur duc to the following reasons Incorrect input ii) Absence of data that is to be searched (iii). Dota stored exceed the capacity of storage limit On the other hand, system errors occur when deadlock occurs. Whenever, syste undesirable state from which itis not possible for a transaction to perform normal execution. Q3. What is seriatizability? Answer : / Sevialiabiity isa sandard that ensures the consistency ofa schedule. A schedule i consistent ifand only it A schedule is serializable if the interleaved transactions produce the result, which is equivalent the result produced by executing individual transaction separately (i... a scliedule is serialidable, it produces the same result a that ‘of a serial schedule). Q4. What is write-write conflicts? Give an example. Answer : Write-write Confliets This conflict arises when a transaction overwrites an object which is modified by another transaction, still under processing. ‘This is called blind writing Example Consider there are two employees Pavani and Vasavi. They are in same post and so must recive ‘T1 assign a salary of € $00/- and transaction T2 assigns a salary of € 1000 1m errot occurs. the systera enters into an (Mode! Papers, 1) | April-18(R16), Q1(0)) is serializable. same salary, Transaction Table “Hence, Pavani will have 10001- and Vasavi will have & S00. This situation i calied lot update 5, When do we say that transaction T, precedes transaction T,? Answer + schedule 5, consists of set of transactions (7, Ty. TZ. T,) then 7, precedes 7, if and only if Transaction T, acquires a lock on data itm xin exclusive mode and transaction T, acquires a lock on sin shared mode Compatibility ofexelusive and shared mode isnot equal o true, which is possible when there exist conflicting instructions. 17, is exceuted before T, then precedence signifies that in a conflict equivalent serial schedule, 7, must appear before T, @ Gi) Q6. What are two schedules conflict equivalent? What is conflict serializable schedule? Answer « . Conitict Equivalent “The order of the instructions /, and /, can be swapped when, May-17(R15), a1(m) © 1, and J, belong to two different transactions, & — L,and/, ae not conflicting instructions. “The execution order ofthe instruction in schedule S, are swapped, s0 as to generate a new schedule S.‘ Which is equivalent to schedule S, $s said to be equivalent to S,” because the order of executing the instruction in 5," is siiar to the execution “order in S, except for instructions [, and /, (i.e. the order of J, and /, is not considered) Look for the St GROUP LOGO {Y of''the TITLE COVER before you thy UNIT-4 Transaction Management, Concurrency Control 4.3 Confiict Seriolizable ‘Consider a schedule 5, consisting of two successive instructions J, andl /, belonging to transactions 7, and 7’, respectively. WEL, and I, refer to different data item then itis very easy to swap these instructions. The result of swapping these instructions, doesn’t have any impact on the remaining instructions in the schedule, On the other hand, if /, and /, refer to same data item then the following four cases must be considered (since only read and write operations ate performed), (i) 1, Radin) J, = Readts) Gi) 1, = Readte), f= Writetx) it) 1, = Write(2), J, = Read(e) Kiv) 1, > Writet), 1, = Write(x) QT. What Is locking protocol? - Answer: (lay-190848), O16) | May-171R15), 149) A Protocol which blocks or stops the access of same data transaction during the life ofa transaction using a lock is called “Locking Protoco?” ‘The three different types of locking protocots are as follows, (@) Simple locking Gi) 2-phase locking (ii). Graph-based locks. : Model Papers, 1h) Lock-based Concurrency Control : ~ [Ont Concurrency Contra In this approach, the order of the conflicting Vi, Tn this approach, aimistamp ordering is imposed onthe | actions tht arises between different ransactons transactions and the validation phase checks that all afe'in accordance with the order in which the conflicting actions oecurred in the same order | Jocks are obtained. Itis a pessimistic approach to control concurrency. | 2. Hete the locking protocols ensure setiaizability by | 3. extending the order of the actions to the transactions, Jt is an optimistic approach for concurrency control ‘The serializability order can be ensured by using the value of the validation timestamp, Explain dead lock prevention policies employed in databases. Answer t ‘As the saying goes, prevention is better than cure, itis always belter to prevent a deadlock rather than waiting for it to ‘occur and then taking measures to avoid deadlock. It can be prevented by prioritizing the transactions Priorities can be assigned by giving a timestamp to each transaction on its startup ie. the lower the time stamp, the higher the priority of transaction, Ifa transaction T- j requests a lock which held by some other transactiori T-j, then the lock manager can use one of these Policies. Q10. What are the different ways for ensuring recoverability and cascadelessness of a schedule? Answer : Model Papers, ath) ‘The different ways for ensuring recoverability and cascadelessness are as follows. (Executing All the Write Instructions Togethe t the End of the Transaction In this method, while a transaction 7, executes the write instruction, no other transaction is allowed to access the data items written by 7,. (i) Employing Limited Number of Locks In this miethod, uncommitted read are not executed until the transaction that executes the write instruction commits, successfully. (ii) Monitoring the Uncommitted Writes In this method, the transaction T, will not exeeue the read operation on the data item writen by another transaction ntl ransaction T, commits successfully. SPECTRUM ALLANONE JOURNAL FOR ENGINEERING STUDKiTS ——— —sin GRow gh DATABASE MANAGEMEN! of ote. 440 ATABASE Ne 11. What do you mean by 2PL?, as Nov Dec.48(R16), a1) ey ‘Two-Phase Locking (2PL) protocol isa concurrency control protocol that guarantees seializability between the schedules, ‘transaction obeys two-phase locking protocol when read as well as write operations are executed before the execution of frst unlock instruction. In 2PL, the transactions can be divided into two phases. (Growing (lock acquisition) phase (i) Shrinking lock releasing) phase, (i) Growing (Lock Acquisition) Phase In this phase, transaction acquires new locks, but cannot releases them (li) Shrinking (Lock Releasing) Phase 7 In this pis {ransaction releases the existing locks, but cannot acquires any new locks. Q12. What Is the difference between Thomas-write rule and timestamp-based rule? Answer t i _ ae that makes Thomas-write rule different from Timestamp based rule is 7,(7,) < WTS(X). IF this condition sip in timestamp based rule, then the transaction cannot execute the write operation as it may lead (9 inconsistent ie x hereas in Thomas-write rule, the transaction ignores the write operation as it is trying to write an obsolete value on i rane ifthe condition T,(7,) = RTS(X) is encountered in Thomas-write rule as well as in Timestamp based rule, then bse write i ignored in both of these rus, Timestmp tae le il generate serializable schedule. Therefore: ‘modifications are performed on the rule by deleting the obsolete write operation from the transactions that have ised the wri ‘Tequest. This modification performed on timestamp-ordering protocol is referred as Thomas-write tule, where it is possible to generate serializable schedule. Q13. What methods are used to assign timestamps to transactions? Answer : May 1813), O1(6) The methods that are used to assign timestamps to translations are, 1. System Clock: When a transaction enters the system, itis assigned with a timestamp which is equal to the time in the system clock. 2. Logical Counter: When a transaction enters the system, its assigned with timestamp which is equal tothe counter valle that is incremented each time for a newly entered transaction. 14. What is dirty page table? Answer: Dirty Page Table (DPT) table stores the information regarding the pages that are modified in the database buffer. Every ity page is assigned a unique pageLSN and RecLSN, which helps in identifying log records that have already been reflected onto the disk. Whenever, a page is stored in DPT then ‘the value of RecLSN is set to the current log end, but when the page is moved to the disk, then it is deleted from the dirty page table. In addition to DPT and active transactions, checkpoint logrecord also record the information about the last log record in LastLSN field. = —— Q15. Define multiple granularity. Answer: Multiple Granlarity scheme is mechanism tat llows the system te define man levels of granularity, It allows data items of dffecat ses to define granularity hierarchy in which smaller data granuartis les within larger granularity Tis granularity hierarchy can be graphically represented in the form of a tree. Every non leaf node in the tree signifies the data that is associated with its child nodes. Q16. What are checkpoints? Answer : Now/Dec.-18(R16), 21/9) {All the log records that are present inside the main memory must be given to the stable storage. All the modified buffer blocks must be given tothe disk. ‘A record ofthe form must be given to the stable storage. Here fhe TITLE COVER before you buy “1? refers to a set of al! active transaction R18. Or) schedules, OM Of frst ition, sistent ue on then fore, le to 216) ue UNIT-4 Transaction Management, Concurrency Control as PART-B ESSAY QUESTIONS WITH SOLUTIONS 4:1 TRANSACTION CONCEPT, TRANSACTION STATE 17. What Is transaction? Explain the properties of transaction. Apn1a(R16),a8(0) or \What is ransaction? Explain the ACID Propertin of transactions, say) on Wat is a transaction? Explain ACID properties, : ‘ (Model Papert, Q8(a) | April/May-12, Set-4, 054a)) Tranacton ‘transaction ran exciton oer rogram, DBMS considers transaction alist faction that ed, write and wpe database objects, rogram. transact list of actions that read ind igh-level data manipulation language or programming language. is resulted from the execution ofa program written in a hi ‘and ‘ended transaction’. A transaction isa unit of ‘A transaction is started and ended between the statements “begin transect program execution which access and possibly updates various data items Ina transaction, database is accessed by two operations, (reads) Gi) writers), ‘The frst one performs the readi ‘operation of data item x to the database. Consider a transaction 7, which transfers $100 from * ‘transaction will be as follows, ing operation of data item x from the database, whereas the second one performs the writing ‘A° account to “B" account, This T= read(ay; AL@A~ 100; write(A); read(B); B:=B+100; write(B); ACID Properties of Transaction These are the properties that a transaction should posses in order to avoid failures during concurrent access of a database ACID is an acronym which stands for Atomicity, Consistency, Isolation and Durability. 1. Atomicity Atomicity ensures that the transaction is either executed completely or not executed at all. Incomplete transaction ‘consequences are not valid. Consider the example ofa transaction involving crediting and debiting the account. ‘Suppose Pavani had & 500/- in hes account and Vasavi has & 200/- in her account, Now Pavani transfers a amount of @ '50/ to Vasavi. A transaction debits the amount from Pavani’s account, but before it could be credited to Vasav, if there i a fail ure then transaction would result in loss of @ 50/-, Because, the amount is deducted from Pavani’s account but itis not added to ‘Vasavi’s account. This leaves the data in an inconsistent state. If there is a faire during transaction execution, then measures are taken to get back the data in a form which was in, before transaction. This is taken care by transaction management component. 2 Consistency ‘The data in the database must always be in a consistent state. A transaction that is carried on a consistent data should bring the data to another consistent state after execution. However, transaction need not maintain consistency at intermediate stages For example, consider a transaction that involves transfer of amount: If amount is debijed from account-"A’ and credited to account-‘B" afler the transaction then the sum A + B should be same as it was before transaction. However, at an intermediate stage, where the amount is deducted from 4 but not yet credited to B, the sum A + B would not be same and it need not be. The result is an inconsistent transaction. Its the responsibility of application program to ensure consistency. SPECTRUM ALL-IN-ONE JOURNAL FOR ENGINEERING STUDENTS ‘Sl GROUP 4 3. Isolation All ti seedy tn a Demet os ‘(wansactions, Ot be available to other 4 Durabitity This property ensures that ds sate ven ae the fal. Thisis ens 8 ose data into disk. This ask is handed by Tecover-managenet omponent of DBMS. ensures that ether he commie ren fied data is loaded into disk or the information men Sufficient to get the modified data is loaded in, ‘APriMMay-12, Sot, a5(0) ‘Transaction Creation Transactic 2 Teecton cam be created by sing certain SOL siate- (Select Gil). Update i Once a transaction is created, it continues the execu- tion of successive transactions until it finds a COMMIT and ROLLBACK statement, ‘Two additional statements are provided to handle long- (@) ‘Save point (b) Chained transaction, (@) Save Points ROLLBACK undoes all the operation previously per- formed, but in Jong-running applications, it is always desired to roll back only tll certain extent and save the other operations. This facility is provided by ‘SAVEPOINT”. This statement is ‘generally used for decision making. ‘Any number of savepoints can be defined in a long-run application. The syntax for savepoint is given by, ‘SAVEPOINT ‘There are two types of savepoints, @ Statement (ii) Named. ‘The savepoints have two advantages, © Initiating several transaction can be done easily @ ~— We-can roll back to several savepoints. Look for the SIA GROUP LOGO Create. DATABASE MANAGEMENT SYSTEMS (INTU'HYDERARap, (b) Chained Transaction ‘These statements make oll back and commit opera, even more simpler. Consider the following query SBLECT* PROM student s WHERE s.category = “Sports” Suppose there are two transactions. (i) Executes the above query. (ii) The other transaction adds grace marks to students wh are in sports category with greater than 60% of marks, tis a difficult choice to choose what should be locked, ‘We can either lock the table for first transaction and provide an exclusive lock for second transaction. Though it provides seralizbilty,it provide poor concurrency. better choice isto lock smaller objects. Instead of lock- ing the complete table, it would be better to provide a shared lock only on the rows which satisfies the condition, “s.category” = “Sports”. The other rows which do not have category as sports can run TI and T2 concurrently Its a complicated task to select the object that should be locked. DBMS obtains locks at various ‘granularity’. Some transaction serve better ifthe shared lock is provided at row level and some few transactions serve better if lock is provided to complete table At times, the decision made for the previous ‘students’ example may also fil. Consider a third transaction T3, which adds anew row to students table with category as ‘Sports. Since T1 is provided a shared lock, it does not stop T2 from adding a ‘new row and providing it an exclusive row. However, the results generated by TI will depend on when T2 willbe executed. That is itmay generate two different answers upon executing twice. ‘This effect is called ‘PHANTOM" problem, ‘Transaction Characteristics in SQL ‘The three characteristics of a transaction in SQL are, (', Access mode (i) Diagnostics size : (i) Isolation evel (Access Mode This specifies the access a user can have on the data. If the access mode is READ ONLY, then it allows the user only to read the data. He cannot perform any data manipulation opera- tions like insert, delete, update, create etc. If the access mode is READ WRITE, then the user can read and perform various data manipulation operatins. I access mode is READ ONLY, then exclusive locks are not required and hence increases concurrency. (i) Diagnostics Size __Itis the total numberof errors. on the TITLE COVER before you buy o) - Answer: ‘Transaction States UNIT-4 Transaction Management, Concurrency Contro! (it) Isolation Level ‘Transaction isolation level (a) Read Uncommitted (©) Read Committed (©) Repeatable Read (6) Serializable, (@) Read Uncommitted ‘A transaction can read the modifications made by an uncommitted transaction, Thus, it becomes vulnerable to phantom problem. ‘An uncommitted transaction never obtains a shared lock before reading and it needs to have READ-ONLY access mode. As it cannot write, it does not need exclusive lock as well (©) Read Committed ‘A transaction reads the values only from a committed transaction. It also does not allow other transactions to modify a value written by T. Howeyer, the value T reads may be modified by some other transaction, hence prone to phantom problem. Unlike READ UNCOMMITTED, a transaction obtains an exclusive locks before writing and a shared lock before reading objects. (©) Repeatable Read ‘A transaction *Y’, reads only from a committed transac- tion. No other transaction is allowed to change a value, read or written by the transaction *Y”. It sets locks same asa SERIALIZABLE transaction except index locking, (@) Serializable : {A serializable transaction enjoys the highest degree of isolation. serializable transaction, “T'reads only froma ‘committed transaction and a value read or written by “T” is not changed by other transactions until a T commits T totally avoid phantom phenomenon. Iti the safest of all isolations. Q19. Explain transaction states and properties. ‘May-15(R13), 8(2) OR Explain different states of transactions. (Refer Only Topic: Transaction States) + ‘The different states of transactions are as follows, 1. Active state Partially committed state Fail state 2 sta its 3 4 @ sen 4.7 ‘Active State ‘A transaction is said to be in active state if itis in ‘execution. It is therefore considered asthe initial state. Partially Committed State ‘A transaction is in partially committed state if its last stementis been executed. Though the transaction had finished execution in this state, there is a possibility that it might get aborted either due to hardware or software failure. In order to avoid the data loss, the data is stored temporarily in the main ‘memory. This help inreereatin the updates done by the aborted ‘transactions in case of system failure. Fail State ‘A transaction is jn failed state, if the execution of the transaction cannot be processed, and the system performs the roll back operation Abort State ‘The roll back transaction enters the abort state when the system performs any one of the following operation, i) Restart If the transaction was aborted due to hardware or software failure, then the transaction can be restarted, such transaction is considered as a new transaction. (i) Kill Ifthe transaction was aborted due to some internal logical error of due to bad input then the system can kill the transaction. Figure: State Diagram of Transaction States 5, Full Committed State If every statement of the transaction is successfully completed, then itis said to bein full committed state Properties of Transaction For answer refer Unit-IV, QI7, Topic: ACID Properties of Transaction. Abort state 8 ent a ——— ener [SPECTRUM ALLARFORE JOURNAL FOR ENGINEERING STUDENTS ~~ — 48 ©20. During its execution, » transaction passes ‘through several states, until it finally commits or aborts, List all possible sequences of states through which a transaction may pase. Explain why each state transition may oceur Coen ‘Apt, Sat 2,04 The possible sequence of states through whven a transaction may pass ae. |. Active partallycommited_ sorted 2 Active failed aborted 4. _Active_partallycommitted commited 1, Active partiltycommitted_aborted During execution, several state transitions may oeeur, which are illustrated as follows, 2 Initially when the execution i started, the transaction ie said to fe in the inital state Le, the “active” sate hen all ansactions have been executed the transaction may pass through the ‘partially commited state. But if ome hardware or software failure occurs then the data ey los and the information cannot be writen into the dis Due to this. the system need to be restarted, which undo the changes made to the database and ths the transection uses through the aborted? sate 2 Active failed_aborted When the execution of transaction is started, it is said to be the ‘active’ state, When the transaction does not perform its normal execution ic. if any update made to the database inaccordance t the integrity constraint is Violated then the transaction passes through the “failed” state. Here the system performs aol back operation and hence the ransaetion is said tobe in jhe ‘aborted state. 3. Active_partillycommitted_committed When the execution is started, the transaction passes through the ‘active’ state. When all transactions are executed, the system is said to be in the ‘partially committed’ state. And, when every statement of the transaction is successfully completed, then it is said to bein the fully committed’ state. 4.2 IMPLEMENTATION OF ATOMICITY AND DURABILITY Q21. Explain shadow-copy technique for atomicity and durability. Answer : Shadow-copy Technique ‘There are mariy techniques that are employed by recovery ‘management component for ensuring atomicity and durability. ‘One such technique is“shadow-copy” technique wherein many duplicate copies of database called shadow copies are created. This technique assumes that, (i) There is only one active transaction at any time ii) Database is nothing, but a file which is written on the disk. This database consist of database pointer (dbptr) that points tothe new database capy. Api, Set 3.08 LObkK for the SIA GROUP LOGO DATABASE MANAGEMENT SY! /STEMS [JNTU-HYDERABAD, ee yaaer opr Tie renin yf man an ei cn eae redatabase but not tothe original database 7 the shadow-copy). These updates docen a the na vu flea transaction failure, then the system fils to find the Successfully commits, then it enters the committed state inthe eae nae of ei a din ety ee mere Pa th oe a eed = = = cS Figur: Before Update Figure: After Update Shadow-copy technique has the ability of handling two ‘major issues, () Transaction failure issue (ii) System faiture issue. @ ‘Transaction Failure Issue ‘The original copy of database remains unaffected if! the transaction failure occur before updating dbptr. In such situation, the transaction can be aborted by’ simply deleting the new database copy. On the other hand, ifthe transaction successfully committed, then all the updates are carried-out in the current database copy (ie. the database pointed by updated dbptr). Once all the updates are done, the original copy of the database is deleted from the disk. Thus, dbptr is updated only if all the updates are done (ie. either ll updates are done or none). (i) System Failure Issue The original copy of database remains unaffected ifthe system fails before writin the updated dbptr onto the disk. In such situation, when a system is restarted, the dbptr points to the original database but not the current copy of database in which the updates were performed, Nov, ifsystem failure occurred after writing the updated

7, as shown in table (2). a Read(Sam) Sam Sum (Sam * 20100) Wrae(Sam) | Reads) Joan Joan + (Sam * 20/00) | Wrietfoan) | ReadSem) Sam Sam 200, Wieie(Sam) ReadJoan) Joan Joan +200 | Wien) Table (2: Sorially Executed Transaction (T, —>,) .¢., processor anid disk are never idle). SPECTRUM ALLIN-ONE JOURNAL FOR ENGINEERING STUDENTS SIA GROUP {5 ‘The final amount in Sam account is 1900. After the execution, sum of bath accounts are preserved since they generate consistent result Suppose, thatthe transactions are exeouted concurrently as shown in table (3) [ t | | ReadSam) | | Sam= Samm. 200 | | Wrtersam) | | Reaatsany Sam~ Sam- (Same? | | 109 | Wereesam | | Read aan) | { Joan Sean + 200, | | | Weeetiou) | ‘Table (3k: Concurrent Execution of Transactions Then the final amount in Sam's account is 640 and in Joan's account is 1860 which is equivalent of executing the transactions in the order T, -> 7.. Aflcr the execution the total amount is stored as the exccution result in consistent sta 23. What Is a schedule? Explain about serial and non-serial schedules. Answer : Schedule Schedule is a series of actions that represent sequence of execution. Therefore, a schedule for any set of transaction ‘comprises of instructions that aré executed by those transaction, ‘The execution order of the instructions within a transaction is determined by a schedule (i.e. it specifies whether write instruction should appear before or after the read instruction). Serial Schedule Serial schedule is a schedule wherein the transactions are exceuted one after the another sequentially. All the instructions belonging to a transaction appear together in serial schedule. The number of serial schedules generated fora given Schedule depends on the number of transaction (ie. ifthere are ‘transaction. then k! serial schedules are generated), ENT SYSTEMS [0 BAD] 10 DATABASE MANAGEM! nee account is 600 and in Joan | Non- i uted cOnCUTENIy, thy i ions are exe a vn the schedule 1s not & tially executes few instructions of fig, the operating sys CPU. performs comtext switching ang transaction and of second transaction Lat itsviche executes the mei onan executes the Femaining instruction, back st ceveral transaction afe executed concur, and 30.0 Ha is shared synchronously between all thy then transactions In cone transactions may be interleaved, rent execution, this, there is a possibility that more than one execution Se seis However. it isnot possible t0 know the sea testo that renee na ansaction bef ‘number of ins tion. CPU switches to another transa ; It is not always true that concurrent execution leads to | consistent state ie., they may be schedules that may lead to incorrect result. Example of one such schedule is given below, | i 5 th | Read Sam) | Sam= Sam 200 i | Reaarsam) 20 | ‘Sam:= Sam (suon 2 | Write(Sam) write(Sam) Read(Joan) | | Resdidoen} Joan Joan + 200 | | | Writeoun) A Jo | Write(foan) a) ‘able (2 Schedule S, Since, the execution of above schedule results in incorrect, state, Therefore, the sum of both accounts are not stored. | Q24. What is a cascadeless schedule? ‘Why Is cascadelessness of schedules desirable? Are there any circumstances under which it would be desirable to allow non-cascadel schedules? Explain your answer. Answer : Cascadeless schedules are the schedules in which cascading rollbacks does not occur. Cascading rollbacks is a situation in which series of interdependent transaction rollbacks | even ifa single transaction fails. Generally, cascading rollback is undesirable as it may result in undoing huge amount of work. Therefore, to avoid this undesirable situation, Cascadeless Schedules are pre.erred. Cascadeless schedules can more formally be defined as a schedule in which a transaction performs'a eommit operation Prior to read operation being performed-(on the data ites writen Py Committed transaction) by another transaction, For Look for the SIA GROUP Loco Gi on’the TITLE ci aa OVER balore youtuy UNIT-4 Transaction Management, Concurrency Control 9 a instance, consider 7, and T, as pair of transaction. 7, pert ct rand Ty {performs the write operation én data item ‘x" and then commits, later 7, performs the read operation on the data item written by T,. The important property of cascadeless scheses ts that the vchedule are recoverable Read (x) Write (4) 1 Commit : Cascadeless Schedule Caseadcless schedules are desirable because i schedules fate oa single asain does nat have ay ‘impact on the remaining transactions ic, even ifone transaction fails, then it does not result in aborting the other transactions However, the drawback of cascadeless schedules is that these schedules provides less concurrency. Therefore. if there are certain situations in which cascading aborts results in high concurrency then in such situation, non-cascadeless schedules are desirable rather than cascadeless schedules. 25. Define dynamic database. Explain phantom problem by considering suitable example. Answer : Dynamic Databases Dynamic databases are the databases th ““value-based” relationships. In these database, the information about the relationship and the location where the records are stored are specified at the execution time (.c., retrieval time). Phantom Problem Ifa transaction is executed twice without undergoing modifications on any of the tuples and if different result is ‘generated at each execution, then such an execution leads to the occurrence of phantom problem. Example Consider a transaction 7, that scans “STUDENT” relation in order to find the student who secured highest marks sn subject! and subject2. Before initiating the search progess, the transaction finds all the pages associated with “STUDEN[” relation and then acquire locks on each of the page consisting of student with subject! After acquiring the lock, the transaction searches the locked pages to find the page consisting ofa student with highest marks which is, for instance 92. In the meantime, another transaction 7, performs an insertion operation by inserting new student record with subject! and marks 95 onto a page that does not contain other student with subject. r ’ consists of t. of transactions 7, and T,. Eventhough, both the employ strict 2PL, they fail to ensure seralizability: This is because the implicit assumption made by transaction I, which assumes that it has locked all pages consisting of student with subject! But, the assumption fils when by transaction 7, on different page. Thus, when execution of 411 8, Aer finding the desired record, the transaction 7, deletes this student record. Once the record is deleted, the transaction 7, commits and releases all the acquired locks. Finally, transaction T, sdentifies and locks all the pages consisting of student with tbject2. Then the transaction finds the record ofa student who cured the highest marks (ie. *7) The result generated ater the execution of transaction 7, and 87, However. ithe order of executions 7, > Try then he es generated willbe 92 ane 93 and ifthe order is, > then te result generated will bs 95 and 87. Therefore, ean be said that the result generated after the interleaved execution after the serial execution transactions is different from the result generat new record is inserted same transaction, generates different result at each execution, then phantom problem is encountered ‘The phantom problem can he prevented by allowing the DBMS to lock all the rows that consists of subject! on behalf of transaction T,, This can be done by locking the entire “STUDENT” table, However, such locking does not guarantee high level of eancurreney. = Q26. Explain B’-treé locking used for concurrency control with suitable example. Concurrency Control Using R-tree Concurrency control using B”-tree can be achieved by. ()__ Ignoring the structure of the index. (it) Considering every individual page as date object (iii) Applying some version of 2PL. ‘The result of employing B°-tree concurrency control approach is that a high lock contention exist in the higher level nodes of the tree. This is because the search provess initiates from the root node and continues to the leaf node by following ‘ particular path, In addition to this locking protocol, there ‘exists many efficient locking protocols that empioy hierarchical tree index structure. These protocols ate capable of achieving, serializability and recoverability when locking overhead is being reduced. Following two observations must be considered while using any of the locking protocols, Searching is directed by the higher level nodes and the Since, the new student record is inserted on a different page, | (jy ‘acquiring an exclusive lock on this page does not conflict with actual data is present in the leaf node. any of the locks acquired by the first transaction ie. 7,.Now. | | - : sa scton 7, vans stent elton and findsall the pages | (i) Wille ineting a data vale, ts neceaary to acquire consisting of student with subject2. After identifying the pages, aan exclusive lock on a node, if there is a possibility fora split to propagate back from the modified node to reach ese pages and then finds the student sin subject2, which is, forinstance transaction 7, logks all th who secured the highest marks SPECTRUM Ajj -ONE JOURNAL FOR ENGINEERING STUDENTS the root node. SiA Group DATABASE MANAGEMENT SYSTEMS [JNTU-HYDERABaq, yhich Pa ing the search process, every tree node ic, from root node to the desired tat nde = a day, ‘auc i present) must acquire a separate shared lock. However, tis necessary 1 ensue that, when a ere bo the lock acquired by its parent lock is released. The Purpose of releasing the lock as soon as child node #eq} cause the seach press cannot propagate in backward direction (ie, the node visited wil not be revisited) which an “X'lock is acquited by every noge While inserting a dat value, a conserys ti - being traversed from root node to the oa oe nee ioe pecans in the backward direction ic, frp, odie eto heron, Thelok acquired the pare rode isnot released if there is possibility thatthe split may propagy to the parent node. In other words it can be Said, the lock is teleased only if the child node has space for inserting new data Value Te ces of asquiring the lock om chill nde andthe releasing the lock aequired by parent node is called Inck coupling op crabbing Example Consider the following B'-tree. Tr WL \ ae etl Ee rin last ts da aby a Bah . Figure: B- tree Locking Ifthe data value 80° is tobe searched, then the transaction T, reads the values present in node ‘A, after acquiring a shared lock (S) om it If the node contains the desired value then the search operation terminates, However, iit docs not cern the required data valu, then the transaction proceeds to node ‘Nand acquires an ‘Sloe on it Once the transaction acquires lock 00 the lock on node “Mis released. The transaction proceeds to node ‘O" as ‘N” doesnot have the resuired data value, The Process of acquiring and releasing the lock continues until the node ‘P” containing the data value $0* is reached. The purpose of ‘acquiring lock on each node which i being searched iso allow newer transactions to wait until the. currently executing transaction completes. For example, ifa transaction 7, wants to delete the data value 50*, then it has to wait until T, completes, but if another ‘ransaction T- have already aequited lock on node “O" before 7, then T, has to wait fo the transaction 7. o complet. Inorder to insert 46°, a transaction 7, must intially acquire a‘S"lock on node ‘M, then on node ‘N”. Once node ‘'W acquire fe lock, the lock on node “AF must be released. The transaction proceeds and acquires a'S lock onthe next node ie, node -o* Before releasing the ‘S Tock on node ‘N’, the transaction acquires an‘X" lock onthe successive node of node ‘OP ie, node P Once the lock has been acquited the locks are released in the order node ‘O” and then node "N’. The data value 46+ i inserted in the node “P’ as it has space for new data entry. A However, ifa data valu isto be inserted within a node “U" that is already ful then the node “U” must be splitted. Spliting means that the parept of node ‘U? ie. node ‘7 must undergo modifications. But, this parent node "is locked using the shared lock, therefore, node “7, must send a request for upgrading its ‘S'lock to an “X* lock. The request is granted only if no other transaction holds an ‘Jock on node “T when the leaf node °U” is being split, the new node must be added tothe left of U. But, if the new node Is added as the right child of node U, then it is necessary to change the sibling pointer of successive node ie. ode ‘R’ which has different parent node. This concurrency approach is better than 2PL, but the disadvantage ofthis approach is that performance is degraded as many ‘X locks are unnecessarily acquired eventhough they are released quickly. This problem can be solved by acquiring only “S*lock on all nodes except in the leaf node that acquired an “X" lock. In this approach, spitting isnot required in many situations ‘When the leaf node does not have space for inserting a new data value, then itis necessary to upgrade the shared locks to exclusive locks which are acquired by every node to which the split propagates. Look for the SUA GROUP LOGO { on the TITLE COVER before you buy fr ; UNIT-4 Transaction Management, Concurrency Control —_—___——nnmrrsorment Concurrency Control 4.4 SERIALIZABILITY, RECOVERABILITY Q27. What is serializability? Explain. May-19(R16), 0940) oR Define serializability. Explain conflict erlalizability and view serializabllity in detall. Answer : June-144R09), 8 Serializability Senializability isa standard that ensures the consistencs ofa schedule A schedule is consistent if and only itt serializable. A schedule is serializable if the interleaved transactions produce the result, which is equivalent tothe result, Produced by executing individual transaction separately (i.e. 4 schedule is serializable, ifit produces the same result as that ofa serial schedule), Example ses i fi l eeoid] ‘Table (1): Serial Schedule n n Reach) | | = | Resa | i sent vn Aaa we ‘Table (2) Schedule for the Two Transactions When Interleaved ‘The above two schedules produce the same result hence they are serializable. The transaction may be interleaved in any ‘order and DBMS doesn’t provide any guarantee about the order, in which they are executed. The two different types of serializability are, 1. Conflict serializability 2. View serializability. 1. Conflict Serializabitity Consider a schedule S,, consisting of two successive instructions J, and /, belonging to transactions 7, and 7, respectively. If /, and /, refer to different data item then i i very easy to swap these instructions. The result of swapping these instructions, doesn’t have any impact on the remaining instructions in the schedule. On the other hand, if /, and J, refer to same data item then the following four cases. must be considered (since only read and write operations are performed), SPECTROM ALLN-ONE JOURNAL FOR ENGINEERING STUDENTS (i) 1,= Read(s), 1, = Reads) (i) 1, = Read(e), J, ~ Write(s) (Gli) 1, Writetx), 1, = Read(x) iv) 1, = Write(a), J, = Write(2) Case () Here, both J, and J, are read instructions, In this case, the «execution order ofthe insinctions isnot considered Since the same data item xis read by both the transactions , and 7, (ie, ether 7, can read the instruction 1, before T, reads fo vice versa). Case (ty Here 1, and [reread and write instructions respectively. Ifthe execution ordet of instruction is /,-» then transaction 7, canmot read the value written by transaction in instruction 1, On the other hand, if the execution order is /, -/, then 7, can read the value written by transaction 7,. Therefore in this case, the execution order of instruction is important. Case it) Here, 1, and , are write and read instruction respectively. Ifthe execution order of instruction is /,—» I, then transaction 7, can read the value written by 7, but if the order is /, -¥ J, then T, cannot read the value written by transaction T,, Therefore in this case, the execution order of instructions is important. Case (iv) Here, both 1, and J, are write instructions. n tis case. the order of instruction doesn’t matter. If a read operation is performed before the write operation, then the vata item which ‘was already stored in the database is read. Now, if write(x) ‘operation is performed on the database, then already stored data item is overwritten by new data item x. Then a read(x) operation is performed, such thatthe data item x is read but not the earlier stored value. This is because, database stores only the current result. If there is no next wrte(x) instruction after the two write instructions in S,, then the execution order of the instruction have «impact on the resultant value of x, stored in the database ‘Two instructions J, and J, are said to be conflicting if and only if, 1. They representthe operations performed by two different transactions on the same data item. At least one among J), and J, is a write operation, Consider the following schedule S,, 7 1 | Read(x) | ‘Write(x) Reads) | wee Ready) | ‘Write(y) el Write(y) Table (3): Schedule S, { | | | 4.14 the write(x) operation of 7, conflicts with read(x) operation of 7, But the wrte(x) operation of 7, doesn’t contlict with read) operation of 7, since these instructions perform their operations on two different data items Conflict Equivalent ‘The order ofthe instructions /, and J, can be swapped ° ° 4, and 1, belong to two diferent transactions 1, and J, are not conflicting instructions, The exceution order ofthe instuction in schedule 5, Ae swapped, so as to generate a new schedule S° which i eauivalent to schedule S,.5, is said to be equivalent to $. because the order of executing the instucton in Sis similar tothe execution order in S except forinstuction and, ('e the order of J, and /, is not considered). aie Inthe above schedule 5, wrte(x) instruction of 7,can be swapped with ready) instruction of 7, (since both instructions are non-conflicting). This schedule S, can be transferred into ‘Sy by swapping the instruction of 7, and 7, in the following ‘manner, ()__Read() instruction of 7, doesn’t conflict with read(x) instruction of 7,, Therefore, these instructions ean be ‘swapped so as to generate new schedule S," (ii) Write(») instruction of 7, can be swapped with wrte(x) instruction of T,. Since, these are nonconflicting instructions. (iii) Write(») instruction of 7, can further be swapped with read) instruction of 7, ‘After performing the swapping, a new schedule S,"is produced which is a serial schedule. Tt Reads) Write(x) Ready) Write(y) Table (4: Schedule S; Since, S, is equivalent to 5S,’ therefore S, and'S,” are said to be conflict equivalent. In general, two schedules S, and 5," are said to be conflict equivalent when itis possible to generate 1 schedule $,” from S, by performing a series of swapping ‘operations on nonconflicting pair of instructions. The conflict equivalence lead to another notion called conflict serialisability. A schedule say 5, is conflict serializable only if it is conflict equivalent with the serial schedule. DATABASE MANAGEMENT SYSTEMS [INTU-HYDERABAp, Tn the above example, schedule S, is conflict serializabe as itis conflict equivalent witha serial schedule S Consider a schedule S, which is not conflict serializabje [1 tr | Reads) — | | Write) | ‘Write(x) | al (5 Sehodle 8, ‘The above schedule 5, is not conflict serializable since itis not equivalent to either of the serial schedules «7,, T,> or . Two different schedules can generate identical result ‘even though they are not conflict equivalent 2. View Serializability Two schedules 5, and §,’ consisting of same set of transactions are said to be view equivalent, if the following conditions are satisfied (Ifa transaction 7, in schedule S, performs the read operation on the inital vah same transaction in schedule 5,” must also perform the of data item x, then the ‘ead operation on the initial value of x. (ii) Mfatransaction 7, in schedule S, reads the value x, which ‘was written by transaction 7, then 7, in schedule 5," ‘must also read the value x writen by transaction 7, (ii) fa transaction , in schedule S, performs the final write ‘operation on data item x, then the same transaction in schedule on, ‘must also perform the final write operation Consider the following schedules that are view equivalent. 4 Look for the SIA GROUP LOGO {J on the TITLE COVER before you buy

You might also like