100 likes | 326 Views
CS3223 Tutorial 10. Fan Qi fan.qi@nus.edu.sg Database Lab 1, com1 #01-08. Transaction Management. ACID Atomicity : Commit or Abort Consistency: DB initial-end state is consistent Isolation: one Xact is unaware of other Xacts Durability: Once commit, forever commit
E N D
CS3223 Tutorial 10 Fan Qi fan.qi@nus.edu.sg Database Lab 1, com1 #01-08
Transaction Management • ACID • Atomicity : Commit or Abort • Consistency: DB initial-end state is consistent • Isolation: one Xact is unaware of other Xacts • Durability: Once commit, forever commit • Recoverable Schedule • If reads from , then should commit after • Ensures cascade aborting can be performed
Transaction Management • Cascadeless Schedule • Every read is from a committed value or from DB • Strict Schedule • If one object is written by a transaction, it is not concurrently read/write by other transactions • Recovery can be efficiently done by before-image
Protocol Implementation • 2PL & Strict 2PL • Gain all the locks before release • Hold all locks before commit/abort • Multi-granular Locking • Four locks available, IS, IX, S, X • To obtain S or IS lock on a node, must already hold IS or IX lock on parentnode • To obtain X or IX lock on a node, must already hold IX lock on parent node
Question 1 • R1(X), R2(X), W1(X), W2(X) • W1(X), R2(Y), R1(Y), R2(X) • R1(X), R2(Y), W3(X), R2(X), R1(Y) • R1(X), R1(Y), W1(X), R2(Y), W3(Y), W1(X), R2(Y) • R1(X), W2(X), W1(X), Abort2, Commit1 • R1(X), W2(X), W1(X), Commit2, Commit1 • W1(X), R2(X), W1(X), Abort2, Commit1 • W1(X), R2(X), W1(X), Commit2, Commit1 • W1(X), R2(X), W1(X), Commit2, Abort1 • R2(X), W3(X), Commit3, W1(Y), Commit1, R2(Y), W2(Z), Commit2 • R1(X), W2(X), Commit2, W1(X), Commit1, R3(X), Commit3 • R1(X), W2(X), W1(X), R3(X), Commit1, Commit2, Commit3
Question 2 • R1(X), R2(X), W1(X), W2(X) • W1(X), R2(Y), R1(Y), R2(X) • R1(X), R2(Y), W3(X), R2(X), R1(Y) • R1(X), R1(Y), W1(X), R2(Y), W3(Y), W1(X), R2(Y) • R1(X), W2(X), W1(X), Abort2, Commit1 • R1(X), W2(X), W1(X), Commit2, Commit1 • W1(X), R2(X), W1(X), Abort2, Commit1 • W1(X), R2(X), W1(X), Commit2, Commit1 • W1(X), R2(X), W1(X), Commit2, Abort1 • R2(X), W3(X), Commit3, W1(Y), Commit1, R2(Y), W2(Z), Commit2 • R1(X), W2(X), Commit2, W1(X), Commit1, R3(X), Commit3 • R1(X), W2(X), W1(X), R3(X), Commit1, Commit2, Commit3
Question 2 (Examples) • failed 2PL! • 2PL! • Not 2SPL, why? • failed 2PL! • ), failed 2PL!
Question 3 Database | File | Page | Record • Read record P1200:5. • Read records P1200: 98 through P1205:2. • Read all (records on all) pages in file F1. • Read pages P500 through P520. • Read pages P10 through P980. • Read all pages in F1 and (based on the values read) modify 10 pages. • Delete record P1200:98. (This is a blind write.) • Delete the first record from each page. (Again, these are blind writes.) • Delete all records.
Question 3 (Examples) Database • Read records P1200: 98 through P1205:2 • D IS • IS • P1200 IS, P1205 IS, P1201-P1204 S • P1200:98-100 S, P1205:1-2 S • Delete record P1200:98 • D IX • IX • P1200 X • Delete the first record from each page • D IX • IX, IX • P1 X, P2 X 1,1000 1001,2000 File 1 File 2
Thank you! All the best for your exams!