Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 ICS 214B: Transaction Processing and Distributed Data Management Replication Techniques.

Similar presentations


Presentation on theme: "1 ICS 214B: Transaction Processing and Distributed Data Management Replication Techniques."— Presentation transcript:

1 1 ICS 214B: Transaction Processing and Distributed Data Management Replication Techniques

2 ICS214BNotes 142 Data Replication Databasenode 1node 2node 3 item fragment

3 ICS214BNotes 143 Goals for Data replication –Higher throughput –Better response time –Higher availability Assumption: Reliable network, fail- stop nodes

4 ICS214BNotes 144 Basic Solution (for Concurrency Control) Treat each copy as an independent data item X1X2X3 Lock mgr X3 Lock mgr X2 Lock mgr X1 Tx i Tx j Tx k Object X has copies X1, X2, X3

5 ICS214BNotes 145 Read(X): –get shared X1 lock –get shared X2 lock –get shared X3 lock –read one of X1, X2, X3 –at end of transaction, release X1, X2, X3 locks X1 lock mgr X3 lock mgr X2 lock mgr read

6 ICS214BNotes 146 Write(X): –get exclusive X1 lock –get exclusive X2 lock –get exclusive X3 lock –write new value into X1, X2, X3 –at end of transaction, release X1, X2, X3 locks X1 X3 X2 lock write

7 ICS214BNotes 147 RAWA (read lock all, write lock all) Correctness OK –2PL  serializability Problem: Low availability X1 X3 X2 down!  cannot access X!

8 ICS214BNotes 148 Readers lock and access a single copy Writers lock all copies and update all copies Basic Solution — Improvement X1X2X3 reader has lock writer will conflict!

9 ICS214BNotes 149 ROWA Good availability for reads Poor availability for writes

10 ICS214BNotes 1410 Reminder With basic solution –use standard 2PL –use standard commit protocols (e.g., 2PC)

11 ICS214BNotes 1411 Another approach: Primary copy Select primary site All read/write locks requested at the primary site All data read at primary Updates are propagated to backups (using sequence numbers) Probability a transaction blocks = prob. that primary is down Availability is the same as the primary node X1 *X2X3 reader write lock writer

12 ICS214BNotes 1412 Update Propagate Options Immediate Write –Write all copies at the same time Deferred Write –Wait until commit

13 ICS214BNotes 1413 Electing a new primary Elect New Primary P new Make sure P new has committed T 0,…,T k and has locks for T k+1,…,T m Therefore, before each transaction Ti commits, we should ensure backups (potential future primaries) have Ti’s updates PRIMARY Backup 1 Backup n Committed: T1, T2, …, Tk Pending: T k+1, …, T m

14 ICS214BNotes 1414 Distributed Commit X1*X2X3 prepare to write new value lock, compute new value writer ok commit (write)

15 ICS214BNotes 1415 Example X1: 0 Y1: 0 Z1: 0 * X2: 0 Y2: 0 Z2: 0 T1: X  1; Y  1; T2: Y  2; T3: Z  3;

16 ICS214BNotes 1416 Local Commit X1 *X2X3 propagate update lock, write, commit writer Write(X): Get exclusive X1* lock Write new value into X1* Commit at primary; get sequence number Perform X2, X3 updates in sequence-number order...

17 ICS214BNotes 1417 Example t = 0 X1: 0 Y1: 0 Z1: 0 * X2: 0 Y2: 0 Z2: 0 T1: X  1; Y  1; T2: Y  2; T3: Z  3;

18 ICS214BNotes 1418 Example t = 1 X1: 1 Y1: 1 Z1: 3 * X2: 0 Y2: 0 Z2: 0 T1: X  1; Y  1; T2: Y  2; T3: Z  3; active at node 1 waiting for lock at node 1 active at node 1

19 ICS214BNotes 1419 Example t = 2 X1: 1 Y1: 2 Z1: 3 * X2: 0 Y2: 0 Z2: 0 T1: X  1; Y  1; T2: Y  2; T3: Z  3; committed active at 1 committed #2: X  1; Y  1 #1: Z  3

20 ICS214BNotes 1420 Example t = 3 X1: 1 Y1: 2 Z1: 3 * X2: 1 Y2: 2 Z2: 3 T1: X  1; Y  1; T2: Y  2; T3: Z  3; committed #1: Z  3 #2: X  1; Y  1 #3: Y  2

21 ICS214BNotes 1421 What good is RPWP-LC? primary backup updates can’t read! Answer: Can read “out-of-date” backup copy (also useful with 1-safe backups... later)

22 ICS214BNotes 1422 Basic Solution Read lock all; write lock all: RAWA Read lock one; write lock all: ROWA Read and write lock primary: RPWP –local commit: LC –distributed commit: DC

23 ICS214BNotes 1423 Comparison N = number of nodes with copies P = probability that a node is operational *: assuming the read/write waits until all sites are active **: assuming we don’t care if other backups are active

24 ICS214BNotes 1424 Failures in Primary Copy model Backup fails –Asks primary for “lost” updates Primary fails –Data unavailable

25 ICS214BNotes 1425 Mobile Primary (1) Elect new primary (2) Ensure new primary has seen all previously committed transactions (3) Resolve pending transactions (4) Resume processing primary backup

26 ICS214BNotes 1426 (1) Elections Similar to 3PC termination protocol –Nodes have IDs –Largest (or smallest) ID wins

27 ICS214BNotes 1427 (2) Ensure new primary has previously committed transactions primary new primarybackup committed: T1, T2 need to get and apply: T1, T2  cannot use local commit

28 ICS214BNotes 1428 Failed Nodes: Example now: primarybackupbackup - down--down- later: -down--down--down- later primarybackup still: P1P2P3 P1P2P3 P1P2P3 -down- commits T 1 commit T 2 (unaware of T1!)

29 ICS214BNotes 1429 (3) Resolve pending transactions primary new primarybackup T3? T3 in “W” state  should not use blocking commit T3 in “W” state

30 ICS214BNotes 1430 3PC takes care of this problem! Option A –Failed node waits for:  commit info from active node, or  all nodes are up and recovering Option B –Majority voting

31 ICS214BNotes 1431 Node Recovery All transactions have commit sequence number Active nodes save update values “as long as necessary” Recovering node asks active primary for missed updates; applies in order

32 ICS214BNotes 1432 Example: Majority Commit C1 C2C3 CT1,T2,T3T1,T2T1,T3 PT3T2 WT4T4T4 state:

33 ICS214BNotes 1433 Example: Majority Commit t1: C1 fails t2: C2 new primary t3: C2 commits T1, T2, T3; aborts T4 t4: C2 resumes processing t5: C2 commits T5, T6 t6: C1 recovers; asks C2 for latest state t7: C2 sends committed and pending transactions; C2 involves C1 in any future transactions

34 ICS214BNotes 1434 2-safe vs. 1-safe Backups Distributed commit results in 2-safe backups primarybackup 1backup 2 (1) T end work (2) send data (3) get acks (4) commit time

35 ICS214BNotes 1435 Guarantee After transaction T commits at primary, any future primary will “see” T primarybackup 1backup 2 primary next primary backup 2 now: T1, T2, T3 later:

36 ICS214BNotes 1436 Performance Hit 3PC is very expensive –many messages –locks held longer (less concurrency) [Note: group commit may help] Can use 2PC –may have blocking –2PC still expensive [up to 1 second reported]

37 ICS214BNotes 1437 Alternative: 1-safe Commit transactions unilaterally at primary Send updates to backups as soon as possible primarybackup 1backup 2 (1) T end work (2) T commit (3) send data (4) purge data time

38 ICS214BNotes 1438 Problem: Lost Transactions primarybackup 1backup 2 primary next primary backup 2 now: T1, T2, T3 T1, T4, T5 later: T1 T1, T4

39 ICS214BNotes 1439 Claim Lost transaction problem tolerable –failures rare –only a “few” transactions lost

40 ICS214BNotes 1440 Primary Recovery with 1-safe When failed primary recovers, need to “compensate” for missed transactions primarybackup 2 backup 3 next primary backup 2 now: T1, T2, T3 T1, T4, T5 later: T1, T4, T5 T1, T4 T1, T4, T5 next primary T1, T2, T3, T3 -1, T2 -1, T4, T5 compensation

41 ICS214BNotes 1441 Log Shipping “Log shipping:” propagate updates to backup Backup replays log How to replay log efficiently? –e.g., elevator disk sweeps –e.g., avoid overwrites primarybackup log

42 ICS214BNotes 1442 So Far in Data Replication RAWA ROWA Primary copy –static  local commit  distributed commit –mobile primary  2-safe (blocking or non-blocking)  1-safe

43 ICS214BNotes 1443 Correctness with replicated data S 1 : r 1 [X 1 ]  r 2 [X 2 ]  w 1 [X 1 ]  w 2 [X 2 ]  Is this schedule serializable? X1X1 X2X2

44 ICS214BNotes 1444 One copy serializable (1SR) A schedule S on replicated data is 1SR if it is equivalent to a serial history of the same transactions on a one-copy database

45 ICS214BNotes 1445 To check 1SR Take schedule Treat r i [X j ] as r i [X] X j is copy of X w i [X j ] as w i [X] Compute P(S) If P(S) acyclic, S is 1SR

46 ICS214BNotes 1446 S 1 : r 1 [X 1 ]  r 2 [X 2 ]  w 1 [X 1 ]  w 2 [X 2 ] S 1 ’: r 1 [X]  r 2 [X]  w 1 [X]  w 2 [X] S 1 is not 1SR! Example T1T2T1T2 T2T1T2T1

47 ICS214BNotes 1447 Second example S 2 : r 1 [X 1 ]  w 1 [X 1 ]  w 1 [X 2 ] r 2 [X 1 ]  w 2 [X 1 ]  w 2 [X 2 ] S 2 ’: r 1 [X]  w 1 [X]  w 1 [X] r 2 [X]  w 2 [X]  w 2 [X] P(S 2 ):

48 ICS214BNotes 1448 Second example S 2 : r 1 [X 1 ]  w 1 [X 1 ]  w 1 [X 2 ] r 2 [X 1 ]  w 2 [X 1 ]  w 2 [X 2 ] S 2 ’: r 1 [X]  w 1 [X]  w 1 [X] r 2 [X]  w 2 [X]  w 2 [X] Equivalent serial schedule S S :

49 ICS214BNotes 1449 Next lecture Multiple fragments Network partitions


Download ppt "1 ICS 214B: Transaction Processing and Distributed Data Management Replication Techniques."

Similar presentations


Ads by Google