Sekolah Tinggi Ilmu Statistik (STIS) 1 Dr. Said Mirza Pahlevi, M.Eng

Embed Size (px)

Citation preview

  • Slide 1
  • Sekolah Tinggi Ilmu Statistik (STIS) 1 Dr. Said Mirza Pahlevi, M.Eng.
  • Slide 2
  • Lecture 3 2 Dr. Said Mirza Pahlevi, M.Eng.
  • Slide 3
  • Sekolah Tinggi Ilmu Statistik (STIS) Todays Lecture Concurrency Control Meaning of serializability Conflict serializability View serializability Locking Methods 3 Dr. Said Mirza Pahlevi, M.Eng. Last time lecture
  • Slide 4
  • Second Subtopic (from previous lecture) 4 Dr. Said Mirza Pahlevi, M.Eng.
  • Slide 5
  • Sekolah Tinggi Ilmu Statistik (STIS) View Serializability Conflict equivalent-----View equivalent Conflict serializable-----View serializable 5 Dr. Said Mirza Pahlevi, M.Eng.
  • Slide 6
  • Sekolah Tinggi Ilmu Statistik (STIS) Motivating example Schedule Q T 1 T 2 T 3 Read(A) Write(A) 6 Dr. Said Mirza Pahlevi, M.Eng. t1:t1: t2:t2: t3:t3: t4:t4:
  • Slide 7
  • Sekolah Tinggi Ilmu Statistik (STIS) Motivating Example Same as Q = r 1 (A) w 2 (A) w 1 (A) w 3 (A) P(Q): T1 T2 T3 Not conflict serializable! 7 Dr. Said Mirza Pahlevi, M.Eng.
  • Slide 8
  • Sekolah Tinggi Ilmu Statistik (STIS) Compare Q to Serial Schedule (S) QT 1 T 2 T 3 Read(A) Write(A) Write(A) Write(A) S T 1 T 2 T 3 Read(A) Write(A) Write(A) Write(A) T 1 reads same thing in Q dan S T 2, T 3 read same thing (nothing?) After Q or S, DB is left in same state So what is wrong with Q? T 1 reads same thing in Q dan S T 2, T 3 read same thing (nothing?) After Q or S, DB is left in same state So what is wrong with Q? 8 Dr. Said Mirza Pahlevi, M.Eng.
  • Slide 9
  • Sekolah Tinggi Ilmu Statistik (STIS) View Equivalent Two schedules S1 and S2 are view equivalent: 1.IF in S1: w j (A) r i (A), THEN in S2: w j (A) r i (A) 2.IF in S1: r i (A) reads initial DB value, THEN in S2: r i (A) also reads initial DB value 3.IF in S1: T i does last write on A, THEN in S2: T i also does last write on A Dr. Said Mirza Pahlevi, M.Eng. 9 means reads value produced by
  • Slide 10
  • Sekolah Tinggi Ilmu Statistik (STIS) View Serializability Schedule is view serializable if it is view equivalent to a serial schedule. Offers less stringent definition of schedule equivalence than conflict serializability. Every conflict serializable schedule is view serializable, although converse is not true. It can be shown that any view serializable schedule that is not conflict serializable contains one or more blind writes. 10 Dr. Said Mirza Pahlevi, M.Eng.
  • Slide 11
  • Sekolah Tinggi Ilmu Statistik (STIS) View Serializable Test Dr. Said Mirza Pahlevi, M.Eng. 11 add 1. Add final transaction T f that reads all DB e.g.: S = ..W 1 (A).. W 2 (A) R f (A) last A write
  • Slide 12
  • Sekolah Tinggi Ilmu Statistik (STIS) add View Serializable Test Dr. Said Mirza Pahlevi, M.Eng. 12 2. Add initial transaction T b that writes all DB e.g.: S = w b (A) ... r 1 (A) w 2 (A)
  • Slide 13
  • Sekolah Tinggi Ilmu Statistik (STIS) View Serializable Test Dr. Said Mirza Pahlevi, M.Eng. 13 0 3. Create labeled precedence (LP) graph of S: (a) If w i (A) r j (A) in S, add T i T j means reads value produced by
  • Slide 14
  • Sekolah Tinggi Ilmu Statistik (STIS) View Serializable Test Dr. Said Mirza Pahlevi, M.Eng. 14 p p 0 0 (b) For each w i (A) r j (A) do consider each w k (A): [T k T b ] (i) IF T i T b T j T f THEN insert T k T i some new p T j T k (ii) IF T i =T b T j T f THEN insert T j T k (iii) IF T i T b T j =T f THEN insert T k T i
  • Slide 15
  • Sekolah Tinggi Ilmu Statistik (STIS) View Serializable Test Dr. Said Mirza Pahlevi, M.Eng. 15 4. Check if LP(S) is acyclic; if so, then S is view serializable - For each pair of p arcs (p 0), choose one
  • Slide 16
  • Sekolah Tinggi Ilmu Statistik (STIS) Example 1: View Serializable (VS) Dr. Said Mirza Pahlevi, M.Eng. 16 Check if Q is view serializable: Q = r 1 (A) w 2 (A) w 1 (A) w 3 (A) Q = w b (A) r 1 (A) w 2 (A) w 1 (A) w 3 (A) r f (A) T3T3 T2T2 T1T1 TfTf TbTb rule 3a 0 0 0 0 rule 3b (ii) 0 0 rule 3b (iii) Acyclic graph!! Q is VS Acyclic graph!! Q is VS
  • Slide 17
  • Sekolah Tinggi Ilmu Statistik (STIS) Z=w b (A) r 1 (A) w 2 (A) r 3 (A) w 1 (A) w 3 (A) r f (A) T3T3 T2T2 T1T1 TfTf TbTb 0 0 0 0 0 Acyclic graph, so Z is VS (equivalent to T b T 1 T 2 T 3 T f ) Acyclic graph, so Z is VS (equivalent to T b T 1 T 2 T 3 T f ) do not pick this one of 1 pair do not pick this one of 1 pair 17 Dr. Said Mirza Pahlevi, M.Eng. 1 1 0 0 Example 2: View Serializable (VS) rule 3b (i) rule 3b (ii) rule 3b (iii) rule 3a
  • Slide 18
  • Sekolah Tinggi Ilmu Statistik (STIS) Recoverability Serializability identifies schedules that maintain database consistency, assuming no transaction fails. Could also examine recoverability of transactions within schedule. If transaction fails, atomicity requires effects of transaction to be undone Durability states that once transaction commits, its changes cannot be undone (without running another, compensating, transaction). 18 Dr. Said Mirza Pahlevi, M.Eng.
  • Slide 19
  • Sekolah Tinggi Ilmu Statistik (STIS) If T9 Rollback Instead of Commit Dr. Said Mirza Pahlevi, M.Eng. 19 We should undo T10 but T10 has committed the transaction (durability does not allow it). This is a non- recoverable schedule
  • Slide 20
  • Sekolah Tinggi Ilmu Statistik (STIS) Recoverable Schedule A schedule where, for each pair of transactions T i and T j, if T j reads a data item previously written by T i, then the commit operation of T i precedes the commit operation of T j. If commit operation of T j precedes the commit operation of T i then it is unrecoverable, because of the durability. 20 Dr. Said Mirza Pahlevi, M.Eng.
  • Slide 21
  • Third Topic Dr. Said Mirza Pahlevi, M.Eng. 21
  • Slide 22
  • Sekolah Tinggi Ilmu Statistik (STIS) Concurrency Control Techniques Two basic concurrency control techniques: Locking, Timestamping. Both are conservative approaches: delay transactions in case they conflict with other transactions. Optimistic methods assume conflict is rare and only check for conflicts at commit. Dr. Said Mirza Pahlevi, M.Eng. 22
  • Slide 23
  • Sekolah Tinggi Ilmu Statistik (STIS) Locking Transaction uses locks to deny access to other transactions and so prevent incorrect updates. Most widely used approach to ensure serializability. Generally, a transaction must claim a shared (read) or exclusive (write) lock on a data item before read or write. Lock prevents another transaction from modifying item or even reading it, in the case of a write lock. Dr. Said Mirza Pahlevi, M.Eng. 23
  • Slide 24
  • Sekolah Tinggi Ilmu Statistik (STIS) Locking - Basic Rules 1. If transaction has shared lock on item, it can read but not update item. 2. If transaction has exclusive lock on item, it can both read and update item. 3. Reads cannot conflict, so more than one transaction can hold shared locks simultaneously on same item. 4. Exclusive lock gives transaction exclusive access to that item. Dr. Said Mirza Pahlevi, M.Eng. 24
  • Slide 25
  • Sekolah Tinggi Ilmu Statistik (STIS) Locking - Basic Rules 5. Some systems allow transaction to upgrade read lock to an exclusive lock, or downgrade exclusive lock to a shared lock. But this basic rules does not guarantee serializability of schedules by themselves Dr. Said Mirza Pahlevi, M.Eng. 25
  • Slide 26
  • Sekolah Tinggi Ilmu Statistik (STIS) Incorrect Locking Schedule Dr. Said Mirza Pahlevi, M.Eng. 26 Valid schedule using basic rules: S = {write_lock(T 9, bal x ), read(T 9, bal x ), write(T 9, bal x ), unlock(T 9, bal x ), write_lock(T 10, bal x ), read(T 10, bal x ), write(T 10, bal x ), unlock(T 10, bal x ), write_lock(T 10, bal y ), read(T 10, bal y ), write(T 10, bal y ), unlock(T 10, bal y ), commit(T 10 ), write_lock(T 9, bal y ), read(T 9, bal y ), write(T 9, bal y ), unlock(T 9, bal y ), commit(T 9 ) }