Presentation is loading. Please wait.

Presentation is loading. Please wait.

Databases & Consistency

Similar presentations


Presentation on theme: "Databases & Consistency"— 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 Matt 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

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

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 Set Jingyi friend to none + Matt

15 Even Worse Zadie transfers $200 from checking to savings

16 Even Worse Zadie transfers $200 from checking to savings
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 Pedro withdraws $100
Begin transaction Change Zadie checking from $600 to $400 Change Pedro checking from $150 to $350 End transaction Pedro withdraws $100 Change Pedro checking from $150 to $50 Spit out money

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

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

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

28 OK smart guy… Zadie sends $200 to Pedro Pedro withdraws $100
Begin transaction Change Zadie checking from $600 to $400 Change Pedro checking from $150 to $350 End transaction Pedro withdraws $100 Change Pedro checking from $150 to $50 Spit out money $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 Want to transfer money from Marie to Pedro

31 Deadlock Two Programs both trying to transfer money
Process A locks Marie Process B Pedro

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

33 Deadlock Busting Database can resolve: Roll back one transaction
Give up its locks Make it restart AFTER other is complete

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

35 Prepare Then Commit Trick
Master DB initiates transaction

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

37 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

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

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

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


Download ppt "Databases & Consistency"

Similar presentations


Ads by Google