Presentation is loading. Please wait.

Presentation is loading. Please wait.

Databases & Consistency. Database Relational databases : dominant information storage/retrieval system.

Similar presentations


Presentation on theme: "Databases & Consistency. Database Relational databases : dominant information storage/retrieval system."— Presentation transcript:

1 Databases & Consistency

2 Database Relational databases : dominant information storage/retrieval system

3 Database Data stored in tables – Each row is a record – Columns define attributes

4 Consistency Consistent : no contradictions

5 Consistency Inconsistent : contradictions

6 How Do we Become Inconsistent? Only one row can be saved at a time…

7 How Do we Become Inconsistent? Only one row can be saved at a time…

8 How Do we Become Inconsistent? Only one row can be saved at a time… CRASH!!!!

9 How Do we Become Inconsistent? Two programs interact – Program 1: Make Rosina & Jingyi friends – Program 2: Make Matt & Jingi friends

10 How Do we Become Inconsistent? Two programs interact – Program 1: Make Rosina & Jingyi friends Make Rosina friend Jingyi – Program 2: Make Matt & Jingi friends

11 How Do we Become Inconsistent? Two programs interact – Program 1: Make Rosina & Jingyi friends Make Rosina friend Jingyi – Program 2: Make Matt & Jingi friends Make Rosina friend Jingyi

12 How Do we Become Inconsistent? Two programs interact – Program 1: Make Rosina & Jingyi friends Make Rosina friend Jingyi Check who Jingyi is friends with none – Program 2: Make Matt & Jingi friends Make Rosina friend Jingyi Check who Jingyi is friends with none

13 How Do we Become Inconsistent? Two programs interact – Program 1: Make Rosina & Jingyi friends Make Rosina friend Jingyi Check who Jingyi is friends with none Set Jingyi friend to none + Rosina – Program 2: Make Matt & Jingi friends Make Rosina friend Jingyi Check who Jingyi is friends with none

14 How Do we Become Inconsistent? Two programs interact – Program 1: Make Rosina & Jingyi friends Make Rosina friend Jingyi Check who Jingyi is friends with none Set Jingyi friend to none + Rosina – Program 2: Make Matt & Jingi friends Make Rosina friend Jingyi Check who Jingyi is friends with none Set Jingyi friend to none + Matt

15 Even Worse Zadie transfers $200 from savings to checking

16 Even Worse Zadie transfers $200 from savings to checking – Look at checking… decide it should be $600 – Look at savings… decide it should be $500 – Write change to checking – BOOM

17 To Do List Trick Make a list of what you intend to do and save it:

18 To Do List Trick Make a list of what you intend to do and save it:

19 To Do List Trick Make a list of what you intend to do and save it:

20 To Do List Trick Delete list when you are done:

21 To Do List Trick A crash…

22 Idempotent Idempotent action : same effect no matter how many times you execute it – "Change checking balance to $600" Non-idempotent – "Subtract $200 from checking"

23 To Do List If every instruction is: – Idempotent – Reversible : Know how to restore original state Can resume or reverse any partial transaction

24 OK smart guy… Zadie sends $200 to Pedro – Begin transaction – Change Zadie checking from $600 to $400 – Change Pedro checking from $150 to $350 – End transaction Pedro withdraws $100 – Begin transaction – Change Pedro checking from $150 to $50 – Spit out money – End transaction

25 OK smart guy… Zadie sends $200 to Pedro – Begin transaction – Change Zadie checking from $600 to $400 – Change Pedro checking from $150 to $350 – End transaction Pedro withdraws $100 – Begin transaction – Change Pedro checking from $150 to $50 – Spit out money – End transaction $400 $350

26 OK smart guy… Zadie sends $200 to Pedro – Begin transaction – Change Zadie checking from $600 to $400 – Change Pedro checking from $150 to $350 – End transaction Pedro withdraws $100 – Begin transaction – Change Pedro checking from $150 to $50 – Spit out money – End transaction $400 $50 Pedro got cheated!!!

27 OK smart guy… Zadie sends $200 to Pedro – Begin transaction – Change Zadie checking from $600 to $400 – Change Pedro checking from $150 to $350 – End transaction Pedro withdraws $100 – Begin transaction – Change Pedro checking from $150 to $50 – Spit out money – End transaction $50

28 OK smart guy… Zadie sends $200 to Pedro – Begin transaction – Change Zadie checking from $600 to $400 – Change Pedro checking from $150 to $350 – End transaction Pedro withdraws $100 – Begin transaction – Change Pedro checking from $150 to $50 – Spit out money – End transaction $400 $350 Pedro got $100 free!!!

29 Atomicity Atomic operation : indivisible / one unit – Never see results of half done transaction

30 Atomicity Transaction must LOCK all rows it will modify before starting

31 Atomicity Process A locks Marie Process B Pedro

32 Atomicity Process A locks Marie… now needs Pedro Process B Pedro… now needs Marie

33 Deadlock Busting Deadlock requires: – Mutual Exclusion, Hold & Wait, No Preemption

34 Deadlock Busting Deadlock requires: – Mutual Exclusion, Hold & Wait, No Preemption Database can preempt: – Roll back one transaction – Give up its locks – Make it restart AFTER other is complete

35 Replication Databases must be replicated – Redundancy – Speed Copies must remain consistent on the fly

36 Prepare Then Commit Trick Master DB initiates transaction

37 Prepare Then Commit Trick Master DB initiates transaction Asks each other DB to do same… waits for OK Prepare

38 Prepare Then Commit Trick Master DB initiates transaction Asks each other DB to do same… waits for OK Prepare Once everyone complete, sends signal to end transaction Commit

39 Prepare Then Commit Trick Master DB initiates transaction Asks each other DB to do same… waits for OK ERROR

40 Prepare Then Commit Trick Master DB initiates transaction Asks each other DB to do same… waits for OK ERROR Rollback instead of committing

41 Transactional Memory Current research area : Design regular software with transactional memory interactions


Download ppt "Databases & Consistency. Database Relational databases : dominant information storage/retrieval system."

Similar presentations


Ads by Google