coding for concurrency

20
CODING FOR CONCURRENCY 1063035 – 1063103 - 1603154

Upload: tung-ha-son

Post on 22-Jan-2015

71 views

Category:

Education


2 download

DESCRIPTION

Seminar

TRANSCRIPT

  • 1. CODING FOR CONCURRENCY 1063035 1063103 - 1603154

2. database At the same time at the same data 3. Problem?!Problems Lost updates Dirty read Unrepeatble read Phantom reads 4. Lost updates time transaction 10 9 8 7 6 5 4 3 2 1 Commit tran Write(A) Read(A) Begin tran lost data Read(A) Begin tran Write(A) Commit tran 5. Dirty read time 10 9 8 7 6 5 4 3 2 1 Begin tran Write(A) If(error) Rollback tran Commit tran Begin tran Read(A) Commit tran Data has been changed transaction 6. Unrepeatable read time 10 9 8 7 6 5 4 3 2 1 transaction Begin tran Read(A) Read(A) Commit tran Begin tran Commit tran Write(A) Data A (changed) Data A (original) 7. Phantom reads time 10 9 8 7 6 5 4 3 2 1 transaction Write(B) Begin tran Commit tran Begin tran Commit tran Read(A) Read(A,B) Data range (changed) Data range (original) 8. Control concurrency 9. LOCKING use locking to ensure transactional integrity and database consistency 10. Lock mode SHARED UPDATE EXCLUSIVE INTENT SCHEMA BULK UPDATE Read-only operations (select statement)Used on resources that can be updatedUsed for data-modification operationsUsed to establish a lock hierarchyUsed when an operation dependent on the schema of a table is executingUsed when bulk-copying data into a table and the TABLOCK hint is specified 11. Shared locks (S) Data rowSHARED modification 12. Update locks (U) deadlock UPDATE prevent 13. Exclusive locks (S) Data rowSHARED Modify or Read 14. Intent locks (S) Intent shared (IS) Intent exclusive (IX) Shared with intent exclusive (SIX) 15. Schema locks (S) Schema modification locks (Sch-M) Schema stability locks (Sch-M) used when a table data definition language (DDL) operation is being performed. used when compiling queries 16. Bulk Update locks (S) data copying 17. ISOLATION When locking is used as the concurrency control mechanism, it solves concurrency problems. This allows all transactions to run in complete isolation of one another, although there can be more than one transaction running at any time. 18. Isolation level concurrency Data correction higher lower 19. Isolation level concurrency Data correction higher lower 20. Isolation level Dirty read Nonrepeatable read Phantom Read uncommitted (lowest) Yes Yes Yes Read committed No Yes Yes Repeatable read No No Yes Serializable (highest) No No No