Advertisement
Advertisement

More Related Content

Advertisement

Transaction.pptx

  1. Submitted By Ujjwal Matoliya Assignment :- concurrency control Protocol Database management 1
  2. 2 Transaction Concurrency control Type of Concurrency control protocol INDEX
  3. It is a set of opration used to perform a logical unit of work A transaction generally represent change in databass Transaction 3
  4. Example of a simple transaction. 4 READ WRITE A=1000 B=2000 Transfer R(A)= 1000 R(B)=2000 A=A-500 B=B+500 W(A)=500 W(B)=2500 commit A=500 B=2500
  5. Commit: After all instructions of a transaction are successfully executed, the changes made by transaction are made permanent in the database. Write (A): Write operation Write(A) or W(A) writes the value back to the database from buffer. Read(A): Read operations Read(A) or R(A) reads the value of A from the database and stores it in a buffer in main memory. 5
  6. The concurrency control is the process to maintain the data where there are multiple resources or users are accessing the data element and performing the database operations. There are several enterprise systems such as banking, ticket booking, and traffic light systems that use a shared database as part of the data store associated with concurrent transactions. 6 Concurrency control
  7. Shard – Exclusive Locking Shared Lock (S): also known as Read-only lock. As the name suggests it can be shared between transactions because while holding this lock the transaction does not have the permission to update data on the data item. S-lock is requested using lock-S instruction. Exclusive Lock (X): Data item can be both read as well as written. This is Exclusive and cannot be held simultaneously on the same data item. X-lock is requested using lock-X instruction. REQUEST-> <-GRANT 7 S E S YES NO E NO NO
  8. Ex = Transaction (T1) Transaction (T2) Shard Locking (s) Exclusive Locking(E) Read (R) Write (W) T1 S(A) R(A) U(A) T1 E(A) R(A)W U(A) T2 E(A) R(A)W U(A) T2 S(A) R(A) U(A) 8
  9. Problem With Shard – Exclusive Locking I. May not sufficient to produce only serializable schedule II. May not free from irrecoverability III. May not free from deadlock IV. May not free from starvation A 9
  10. T1 T2 E(A) R(A)W U(A) S(A) R(A) U(A) E(A) R(A)W U(A) Not serializable T1 T2 E(A) R(A)W U(A) S(A) R(A) COMMIT * irrecoverability Deadlock T1 T2 E(A) E(B) E(B)* E(A)* starvation T1 T2 T3 S(A) E(A)* S(A) U(A) 10
  11. Two Phase Locking Protocol Growing Phase: New locks on data items may be acquired but none can be released. Shrinking Phase: Existing locks may be released but no new locks can be acquired. T1 T2 E(A) R(A)W S(A)* S(B) R(B) U(A) U(B) serializable Growing Shrinking 11
  12. Problem With Two Phase Locking Protocol I. May not free from irrecoverability II. not free from deadlock III. not free from starvation IV. Not free from cascading rollback 12
  13. Irrecoverability T1 T2 E(A) R(A)W U(A) S(A) R(A) . . .commit * Deadlock T1 T2 E(A) E(B) E(B)* E(A)* starvation T1 T2 T3 S(A) E(A)* S(A) U(A) Cascading rollback T1 T2 T3 E(A) R(A)W U(A) S(A) R(A) . . S(A) R(A) . . * 13
  14. Strict 2-PL – This requires that in addition to the lock being 2-Phase all Exclusive(X) locks held by the transaction be released until after the Transaction Commits. Rigorous 2-PL – This requires that in addition to the lock being 2-Phase all Exclusive(X) and Shared(S) locks held by the transaction be released until after the Transaction Commits. Conservative 2-PL – This protocol requires the transaction to lock all the items it access before the Transaction begins execution by predeclaring its read-set and write-set. **free from deadlock 14
  15. Timestamp Ordering Protocol T1 S(A) R(A) T2 S(A) R(A) 10:00 10:10 100 200 15 The main idea for this protocol is to order the transactions based on their Timestamps. A schedule in which the transactions participate is then serializable and the only equivalent serial schedule permitted has the transactions in the order of their Timestamp Values. Or Unique value assign to every transactions.
  16. W_TS(X) is the largest timestamp of any transaction that executed write(X) successfully. R_TS(X) is the largest timestamp of any transaction that executed read(X) successfully. T1 S(A) R(A) T2 S(A) R(A) RTS=200 10:00 10:10 100 200 10:00 10:10 100 200 T1 E(A) W(A) T2 E(A) W(A) WTS=200 16
  17. Transaction Ti issues a W (A) operation, If R_TS(X) > TS(T) , then rollback Ti if W_TS(X) > TS(T), then rollback Ti Otherwise Execute W(A) operation of T and set W_TS(A) = TS(Ti). Transaction Ti issues a R (A) operation 1. )If W_TS(A) > TS(Ti) ,rollback Ti 2.) Otherwise execute the R(A) operation If W_TS(X) <= TS(T),of T and set R_TS(X) to the larger of TS(Ti) and current R_TS(A). 17
  18. T1 R(A) W(A) W(A) T2 W(A) R(A) W(A) T1 W(A) R(A) W(A) T2 R(A) W(A) W(A) 18
  19. 19
Advertisement