Concurrency Control Theory Lecture # 16 Database Systems Andy - - PowerPoint PPT Presentation

concurrency control theory
SMART_READER_LITE
LIVE PREVIEW

Concurrency Control Theory Lecture # 16 Database Systems Andy - - PowerPoint PPT Presentation

Concurrency Control Theory Lecture # 16 Database Systems Andy Pavlo AP AP Computer Science 15-445/15-645 Carnegie Mellon Univ. Fall 2018 2 SEM ESTER STATUS A DBMS's concurrency Query Planning control and recovery components permeate


slide-1
SLIDE 1

Database Systems 15-445/15-645 Fall 2018 Andy Pavlo Computer Science Carnegie Mellon Univ.

AP AP

Lecture # 16

Concurrency Control Theory

slide-2
SLIDE 2

CMU 15-445/645 (Fall 2018)

SEM ESTER STATUS

A DBMS's concurrency control and recovery components permeate throughout the design of its entire architecture.

2

Query Planning Operator Execution Access Methods Buffer Pool Manager Disk Manager Concurrency Control Recovery

slide-3
SLIDE 3

CMU 15-445/645 (Fall 2018)

M OTIVATIO N

We both change the same record in a table at the same time. How to avoid race condition? You transfer $100 between bank accounts but there is a power failure. What is the correct database state?

3

Lost Updates

Concurrency Control

Durability

Recovery

slide-4
SLIDE 4

CMU 15-445/645 (Fall 2018)

CO N CURREN CY CO N TRO L & RECOVERY

Valuable properties of DBMSs. Based on concept of transactions with ACID properties. Let’s talk about transactions…

4

slide-5
SLIDE 5

CMU 15-445/645 (Fall 2018)

TRAN SACTIO NS

A transaction is the execution of a sequence of

  • ne or more operations (e.g., SQL queries) on a

shared database to perform some higher-level function. It is the basic unit of change in a DBMS:

→ Partial transactions are not allowed!

5

slide-6
SLIDE 6

CMU 15-445/645 (Fall 2018)

TRAN SACTIO N EXAM PLE

Move $100 from Andy’ bank account to his bookie’s account. Transaction:

→ Check whether Andy has $100. → Deduct $100 from his account. → Add $100 to his bookie’s account.

6

slide-7
SLIDE 7

CMU 15-445/645 (Fall 2018)

STRAWM AN SYSTEM

Execute each txn one-by-one (i.e., serial order) as they arrive at the DBMS.

→ One and only one txn can be running at the same time in the DBMS.

Before a txn starts, copy the entire database to a new file and make all changes to that file.

→ If the txn completes successfully, overwrite the original file with the new one. → If the txn fails, just remove the dirty copy.

7

slide-8
SLIDE 8

CMU 15-445/645 (Fall 2018)

PRO BLEM STATEM EN T

A (potentially) better approach is to allow concurrent execution of independent transactions. Why do we want that?

→ Utilization/throughput → Increased response times to users.

But we also would like:

→ Correctness → Fairness

8

slide-9
SLIDE 9

CMU 15-445/645 (Fall 2018)

TRAN SACTIO NS

Hard to ensure correctness…

→ What happens if Andy only has $100 and tries to pay off two bookies at the same time?

Hard to execute quickly…

→ What happens if Andy needs to pay off his gambling debts very quickly all at once?

9

slide-10
SLIDE 10

CMU 15-445/645 (Fall 2018)

PRO BLEM STATEM EN T

Arbitrary interleaving can lead to

→ Temporary inconsistency (ok, unavoidable) → Permanent inconsistency (bad!)

Need formal correctness criteria.

10

slide-11
SLIDE 11

CMU 15-445/645 (Fall 2018)

DEFIN ITIO N S

A txn may carry out many operations on the data retrieved from the database However, the DBMS is only concerned about what data is read/written from/to the database.

→ Changes to the "outside world" are beyond the scope of the DBMS.

11

slide-12
SLIDE 12

CMU 15-445/645 (Fall 2018)

FO RM AL DEFIN ITIO N S

Database: A fixed set of named data objects (e.g., A, B, C, …).

→ We do not need to define what these objects are now.

Transaction: A sequence of read and write

  • perations ( R(A), W(B), …)

→ DBMS’s abstract view of a user program

12

slide-13
SLIDE 13

CMU 15-445/645 (Fall 2018)

TRAN SACTIO NS IN SQ L

A new txn starts with the BEGIN command. The txn stops with either COMMIT or ABORT:

→ If commit, all changes are saved. → If abort, all changes are undone so that it’s like as if the txn never executed at all. → Abort can be either self-inflicted or caused by the DBMS.

13

slide-14
SLIDE 14

CMU 15-445/645 (Fall 2018)

CO RRECTN ESS CRITERIA: ACID

Atomicity: All actions in the txn happen, or none happen. Consistency: If each txn is consistent and the DB starts consistent, then it ends up consistent. Isolation: Execution of one txn is isolated from that of other txns. Durability: If a txn commits, its effects persist.

14

slide-15
SLIDE 15

CMU 15-445/645 (Fall 2018)

CO RRECTN ESS CRITERIA: ACID

Atomicity: “all or nothing” Consistency: “it looks correct to me” Isolation: “as if alone” Durability: “survive failures”

15

slide-16
SLIDE 16

CMU 15-445/645 (Fall 2018)

TO DAY'S AGEN DA

Atomicity Consistency Isolation Durability

16

slide-17
SLIDE 17

CMU 15-445/645 (Fall 2018)

ATO M ICITY O F TRAN SACTIO N S

Two possible outcomes of executing a txn:

→ Commit after completing all its actions. → Abort (or be aborted by the DBMS) after executing some actions.

DBMS guarantees that txns are atomic.

→ From user’s point of view: txn always either executes all its actions, or executes no actions at all.

17

A

slide-18
SLIDE 18

CMU 15-445/645 (Fall 2018)

ATO M ICITY O F TRAN SACTIO N S

We take $100 out of Andy’s account but then there is a power failure before we transfer it to his bookie. When the database comes back on-line, what should be the correct state of Andy’s account?

18

A

slide-19
SLIDE 19

CMU 15-445/645 (Fall 2018)

M ECH AN ISM S FO R EN SURIN G ATO M ICITY

Approach #1: Logging

→ DBMS logs all actions so that it can undo the actions of aborted transactions. → Think of this like the black box in airplanes…

Logging used by all modern systems.

→ Audit Trail & Efficiency Reasons

19

A

slide-20
SLIDE 20

CMU 15-445/645 (Fall 2018)

M ECH AN ISM S FO R EN SURIN G ATO M ICITY

Approach #2: Shadow Paging

→ DBMS makes copies of pages and txns make changes to those copies. Only when the txn commits is the page made visible to others. → Originally from System R.

Few systems do this:

→ CouchDB → LMDB (OpenLDAP)

20

A

slide-21
SLIDE 21

CMU 15-445/645 (Fall 2018)

M ECH AN ISM S FO R EN SURIN G ATO M ICITY

Approach #2: Shadow Paging

→ DBMS makes copies of pages and txns make changes to those copies. Only when the txn commits is the page made visible to others. → Originally from System R.

Few systems do this:

→ CouchDB → LMDB (OpenLDAP)

20

A

slide-22
SLIDE 22

CMU 15-445/645 (Fall 2018)

CO N SISTEN CY

The "world" represented by the database is logically correct. All questions asked about the data are given logically correct answers. Database Consistency Transaction Consistency

21

C

slide-23
SLIDE 23

CMU 15-445/645 (Fall 2018)

DATABASE CO N SISTEN CY

The database accurately models the real world and follows integrity constraints. Transactions in the future see the effects of transactions committed in the past inside of the database.

22

C

slide-24
SLIDE 24

CMU 15-445/645 (Fall 2018)

TRAN SACTIO N CO N SISTEN CY

If the database is consistent before the transaction starts (running alone), it will also be consistent after. Transaction consistency is the application’s responsibility.

→ We won’t discuss this further…

23

C

slide-25
SLIDE 25

CMU 15-445/645 (Fall 2018)

ISO LATIO N O F TRAN SACTIO NS

Users submit txns, and each txn executes as if it was running by itself. Concurrency is achieved by DBMS, which interleaves actions (reads/writes of DB objects) of various transactions. How do we achieve this?

24

I

slide-26
SLIDE 26

CMU 15-445/645 (Fall 2018)

M ECH AN ISM S FO R EN SURIN G ISO LATIO N

A concurrency control protocol is how the DBMS decides the proper interleaving of

  • perations from multiple transactions.

Two categories of protocols:

→ Pessimistic: Don’t let problems arise in the first place. → Optimistic: Assume conflicts are rare, deal with them after they happen.

25

I

slide-27
SLIDE 27

CMU 15-445/645 (Fall 2018)

EXAM PLE

Assume at first A and B each have $1000. T1 transfers $100 from A’s account to B’s T2 credits both accounts with 6% interest.

26

BEGIN A=A-100 B=B+100 COMMIT

T1

BEGIN A=A*1.06 B=B*1.06 COMMIT

T2

I

slide-28
SLIDE 28

CMU 15-445/645 (Fall 2018)

EXAM PLE

Assume at first A and B each have $1000. What are the possible outcomes of running T1 and T2?

27

BEGIN A=A-100 B=B+100 COMMIT BEGIN A=A*1.06 B=B*1.06 COMMIT

T1 T2

I

slide-29
SLIDE 29

CMU 15-445/645 (Fall 2018)

EXAM PLE

Assume at first A and B each have $1000. What are the possible outcomes of running T1 and T2? Many! But A+B should be:

→ $2000*1.06=$2120

There is no guarantee that T1 will execute before T2 or vice-versa, if both are submitted together. But, the net effect must be equivalent to these two transactions running serially in some order.

28

I

slide-30
SLIDE 30

CMU 15-445/645 (Fall 2018)

EXAM PLE

Legal outcomes:

→ A=954, B=1166 → A=960, B=1160

The outcome depends on whether T1 executes before T2 or vice versa.

29

A+B=$2120 A+B=$2120

I

slide-31
SLIDE 31

CMU 15-445/645 (Fall 2018)

SERIAL EXECUTIO N EXAM PLE

30

A=954, B=1166 A=960, B=1160

TIM E

BEGIN A=A-100 B=B+100 COMMIT

T1 T2

BEGIN A=A*1.06 B=B*1.06 COMMIT BEGIN A=A-100 B=B+100 COMMIT

T1 T2

BEGIN A=A*1.06 B=B*1.06 COMMIT

Schedule Schedule

I

A+B=$2120

slide-32
SLIDE 32

CMU 15-445/645 (Fall 2018)

IN TERLEAVING TRAN SACTIO N S

We interleave txns to maximize concurrency.

→ Slow disk/network I/O. → Multi-core CPUs.

When one txn stalls because of a resource (e.g., page fault), another txn can continue executing and make forward progress.

31

I

slide-33
SLIDE 33

CMU 15-445/645 (Fall 2018)

IN TERLEAVING EXAM PLE (GO O D)

32

BEGIN A=A-100 B=B+100 COMMIT

T1 T2

BEGIN A=A*1.06 B=B*1.06 COMMIT

TIM E

Schedule

A=954, B=1166

BEGIN A=A-100 B=B+100 COMMIT

T1 T2

BEGIN A=A*1.06 B=B*1.06 COMMIT

Schedule

A=960, B=1160

I

slide-34
SLIDE 34

CMU 15-445/645 (Fall 2018)

IN TERLEAVING EXAM PLE (GO O D)

32

BEGIN A=A-100 B=B+100 COMMIT

T1 T2

BEGIN A=A*1.06 B=B*1.06 COMMIT

TIM E

Schedule

A=954, B=1166

BEGIN A=A-100 B=B+100 COMMIT

T1 T2

BEGIN A=A*1.06 B=B*1.06 COMMIT

Schedule

A=960, B=1160

I

A+B=$2120

slide-35
SLIDE 35

CMU 15-445/645 (Fall 2018)

IN TERLEAVING EXAM PLE (BAD)

33

A=954, B=1166

  • r

A=960, B=1160

BEGIN A=A-100 B=B+100 COMMIT BEGIN A=A*1.06 B=B*1.06 COMMIT

The bank is missing $106!

TIM E

Schedule

T1 T2

A=954, B=1060

I

A+B=$2014

slide-36
SLIDE 36

CMU 15-445/645 (Fall 2018)

IN TERLEAVING EXAM PLE (BAD)

34

BEGIN R(A) W(A) R(B) W(B) COMMIT BEGIN R(A) W(A) R(B) W(B) COMMIT BEGIN A=A-100 B=B+100 COMMIT BEGIN A=A*1.06 B=B*1.06 COMMIT

TIM E

Schedule DBMS View

T1 T2 T1 T2

A=954, B=1060

I

A+B=$2014

slide-37
SLIDE 37

CMU 15-445/645 (Fall 2018)

IN TERLEAVING EXAM PLE (BAD)

34

BEGIN R(A) W(A) R(B) W(B) COMMIT BEGIN R(A) W(A) R(B) W(B) COMMIT BEGIN A=A-100 B=B+100 COMMIT BEGIN A=A*1.06 B=B*1.06 COMMIT

TIM E

Schedule DBMS View

T1 T2 T1 T2

A=954, B=1060

I

A+B=$2014

slide-38
SLIDE 38

CMU 15-445/645 (Fall 2018)

CO RRECTN ESS

How do we judge whether a schedule is correct? If the schedule is equivalent to some serial execution.

35

I

slide-39
SLIDE 39

CMU 15-445/645 (Fall 2018)

FO RM AL PRO PERTIES O F SCH EDULES

Serial Schedule

→ A schedule that does not interleave the actions of different transactions.

Equivalent Schedules

→ For any database state, the effect of executing the first schedule is identical to the effect of executing the second schedule. → Doesn't matter what the arithmetic operations are!

36

I

slide-40
SLIDE 40

CMU 15-445/645 (Fall 2018)

FO RM AL PRO PERTIES O F SCH EDULES

Serializable Schedule

→ A schedule that is equivalent to some serial execution of the transactions.

If each transaction preserves consistency, every serializable schedule preserves consistency.

37

I

slide-41
SLIDE 41

CMU 15-445/645 (Fall 2018)

FO RM AL PRO PERTIES O F SCH EDULES

Serializability is a less intuitive notion of correctness compared to txn initiation time or commit order, but it provides the DBMS with additional flexibility in scheduling operations. More flexibility means better parallelism.

38

I

slide-42
SLIDE 42

CMU 15-445/645 (Fall 2018)

CO N FLICTIN G O PERATIO N S

We need a formal notion of equivalence that can be implemented efficiently based on the notion of "conflicting" operations Two operations conflict if:

→ They are by different transactions, → They are on the same object and at least one of them is a write.

39

I

slide-43
SLIDE 43

CMU 15-445/645 (Fall 2018)

IN TERLEAVED EXECUTIO N AN O M ALIES

Read-Write Conflicts (R-W) Write-Read Conflicts (W-R) Write-Write Conflicts (W-W)

40

I

slide-44
SLIDE 44

CMU 15-445/645 (Fall 2018)

READ- WRITE CO N FLICTS

Unrepeatable Reads

41

BEGIN R(A) R(A) COMMIT BEGIN R(A) W(A) COMMIT

$10 $10 $19 $19

T1 T2

I

slide-45
SLIDE 45

CMU 15-445/645 (Fall 2018)

WRITE- READ CO N FLICTS

Reading Uncommitted Data ("Dirty Reads")

42

BEGIN R(A) W(A) ABORT

T1 T2

BEGIN R(A) W(A) COMMIT

$10 $12 $12 $14

I

slide-46
SLIDE 46

CMU 15-445/645 (Fall 2018)

WRITE- WRITE CO N FLICTS

Overwriting Uncommitted Data

43

BEGIN W(A) W(B) COMMIT BEGIN W(A) W(B) COMMIT

Andy $19

T1 T2

$10 Bieber

I

slide-47
SLIDE 47

CMU 15-445/645 (Fall 2018)

FO RM AL PRO PERTIES O F SCH EDULES

Given these conflicts, we now can understand what it means for a schedule to be serializable.

→ This is to check whether schedules are correct. → This is not how to generate a correct schedule.

There are different levels of serializability:

→ Conflict Serializability → View Serializability

44

I

slide-48
SLIDE 48

CMU 15-445/645 (Fall 2018)

FO RM AL PRO PERTIES O F SCH EDULES

Given these conflicts, we now can understand what it means for a schedule to be serializable.

→ This is to check whether schedules are correct. → This is not how to generate a correct schedule.

There are different levels of serializability:

→ Conflict Serializability → View Serializability

44

Most DBMSs try to support this. No DBMS can do this.

I

slide-49
SLIDE 49

CMU 15-445/645 (Fall 2018)

CO N FLICT SERIALIZABLE SCH EDULES

Two schedules are conflict equivalent iff:

→ They involve the same actions of the same transactions, and → Every pair of conflicting actions is ordered the same way.

Schedule S is conflict serializable if:

→ S is conflict equivalent to some serial schedule.

45

I

slide-50
SLIDE 50

CMU 15-445/645 (Fall 2018)

CO N FLICT SERIALIZABILITY IN TUITIO N

Schedule S is conflict serializable if you are able to transform S into a serial schedule by swapping consecutive non-conflicting operations of different transactions.

46

I

slide-51
SLIDE 51

CMU 15-445/645 (Fall 2018)

CO N FLICT SERIALIZABILITY IN TUITIO N

47

BEGIN R(A) W(A) COMMIT BEGIN R(B) W(B) COMMIT R(B) R(A) W(A) W(B)

TIM E

Schedule

T1 T2

I

slide-52
SLIDE 52

CMU 15-445/645 (Fall 2018)

CO N FLICT SERIALIZABILITY IN TUITIO N

47

BEGIN R(A) W(A) COMMIT BEGIN R(B) W(B) COMMIT W(A) R(A) R(B) W(B)

TIM E

Schedule

T1 T2

I

slide-53
SLIDE 53

CMU 15-445/645 (Fall 2018)

CO N FLICT SERIALIZABILITY IN TUITIO N

47

BEGIN R(A) W(A) COMMIT BEGIN R(B) W(B) COMMIT W(A) R(A) R(B) W(B)

TIM E

Schedule

T1 T2

I

slide-54
SLIDE 54

CMU 15-445/645 (Fall 2018)

CO N FLICT SERIALIZABILITY IN TUITIO N

47

BEGIN R(A) W(A) COMMIT BEGIN R(B) W(B) COMMIT W(A) R(A) R(B) W(B)

TIM E

Schedule

T1 T2

I

slide-55
SLIDE 55

CMU 15-445/645 (Fall 2018)

CO N FLICT SERIALIZABILITY IN TUITIO N

47

BEGIN R(A) W(A) COMMIT BEGIN R(B) W(B) COMMIT W(A) R(A) R(B) W(B)

TIM E

Schedule

T1 T2

I

slide-56
SLIDE 56

CMU 15-445/645 (Fall 2018)

CO N FLICT SERIALIZABILITY IN TUITIO N

47

BEGIN R(A) W(A) COMMIT BEGIN R(B) W(B) COMMIT R(A) R(B) W(B) W(A)

TIM E

Schedule

T1 T2

I

slide-57
SLIDE 57

CMU 15-445/645 (Fall 2018)

CO N FLICT SERIALIZABILITY IN TUITIO N

47

BEGIN R(A) W(A) COMMIT BEGIN R(B) W(B) COMMIT R(A) R(B) W(B) W(A)

TIM E

Schedule

T1 T2

I

slide-58
SLIDE 58

CMU 15-445/645 (Fall 2018)

CO N FLICT SERIALIZABILITY IN TUITIO N

47

BEGIN R(A) W(A) COMMIT BEGIN R(B) W(B) COMMIT BEGIN R(A) W(A) R(B) W(B) COMMIT BEGIN R(A) W(A) R(B) W(B) COMMIT R(B) W(A) R(A) W(B)

TIM E

Schedule

T1 T2

Serial Schedule

T1 T2

I

slide-59
SLIDE 59

CMU 15-445/645 (Fall 2018)

Schedule

T1 T2

Serial Schedule

T1 T2

CO N FLICT SERIALIZABILITY IN TUITIO N

48

BEGIN R(A) W(A) COMMIT BEGIN R(A) W(A) COMMIT BEGIN R(A) W(A) COMMIT BEGIN R(A) W(A) COMMIT

TIM E

I

slide-60
SLIDE 60

CMU 15-445/645 (Fall 2018)

SERIALIZABILITY

Swapping operations is easy when there are only two txns in the schedule. It's cumbersome when there are many txns. Are there any faster algorithms to figure this out

  • ther than transposing operations?

49

I

slide-61
SLIDE 61

CMU 15-445/645 (Fall 2018)

DEPEN DEN CY GRAPH S

One node per txn. Edge from Ti to Tj if:

→ An operation Oi of Ti conflicts with an

  • peration Oj of Tj and

→ Oi appears earlier in the schedule than Oj.

Also known as a precedence graph. A schedule is conflict serializable iff its dependency graph is acyclic.

50

Ti Tj

Dependency Graph

I

slide-62
SLIDE 62

CMU 15-445/645 (Fall 2018)

EXAM PLE # 1

51

BEGIN R(A) W(A) R(B) W(B) COMMIT BEGIN R(A) W(A) R(B) W(B) COMMIT

T1 T2

A

Schedule

T1 T2

TIM E

Dependency Graph

I

slide-63
SLIDE 63

CMU 15-445/645 (Fall 2018)

EXAM PLE # 1

51

BEGIN R(A) W(A) R(B) W(B) COMMIT BEGIN R(A) W(A) R(B) W(B) COMMIT

T1 T2

A B

The cycle in the graph reveals the problem. The output of T1 depends

  • n T2, and vice-versa.

Schedule

T1 T2

TIM E

Dependency Graph

I

slide-64
SLIDE 64

CMU 15-445/645 (Fall 2018)

Dependency Graph

EXAM PLE # 2 TH REESO M E

53

BEGIN R(A) W(A) R(B) W(B) COMMIT BEGIN R(B) W(B) COMMIT

T1 T2

BEGIN R(A) W(A) COMMIT

T3

TIM E

Schedule

T1 T2 T3

I

slide-65
SLIDE 65

CMU 15-445/645 (Fall 2018)

Dependency Graph

EXAM PLE # 2 TH REESO M E

53

BEGIN R(A) W(A) R(B) W(B) COMMIT BEGIN R(B) W(B) COMMIT

T1 T2

BEGIN R(A) W(A) COMMIT

T3

B

TIM E

Schedule

T1 T2 T3

I

slide-66
SLIDE 66

CMU 15-445/645 (Fall 2018)

Dependency Graph

EXAM PLE # 2 TH REESO M E

53

Is this equivalent to a serial execution?

BEGIN R(A) W(A) R(B) W(B) COMMIT BEGIN R(B) W(B) COMMIT

T1 T2

BEGIN R(A) W(A) COMMIT

T3

B A

TIM E

Schedule

T1 T2 T3

I

Yes (T2, T1, T3)

→ Notice that T3 should go after T2, although it starts before it!

slide-67
SLIDE 67

CMU 15-445/645 (Fall 2018)

EXAM PLE # 3 IN CO N SISTEN T AN ALYSIS

54

BEGIN R(A) A = A-10 W(A) R(B) B = B+10 W(B) COMMIT BEGIN R(A) sum = A R(B) sum += B ECHO sum COMMIT

T1 T2

TIM E

Schedule

T1 T2

Dependency Graph

A

I

slide-68
SLIDE 68

CMU 15-445/645 (Fall 2018)

EXAM PLE # 3 IN CO N SISTEN T AN ALYSIS

54

BEGIN R(A) A = A-10 W(A) R(B) B = B+10 W(B) COMMIT BEGIN R(A) sum = A R(B) sum += B ECHO sum COMMIT

T1 T2

TIM E

Schedule

T1 T2

Dependency Graph

A B

I

slide-69
SLIDE 69

CMU 15-445/645 (Fall 2018)

EXAM PLE # 3 IN CO N SISTEN T AN ALYSIS

54

BEGIN R(A) A = A-10 W(A) R(B) B = B+10 W(B) COMMIT BEGIN R(A) sum = A R(B) sum += B ECHO sum COMMIT

T1 T2

Is it possible to modify only the application logic so that schedule produces a "correct" result but is still not conflict serializable?

TIM E

Schedule

T1 T2

Dependency Graph

A B

I

slide-70
SLIDE 70

CMU 15-445/645 (Fall 2018)

EXAM PLE # 3 IN CO N SISTEN T AN ALYSIS

54

BEGIN R(A) A = A-10 W(A) R(B) B = B+10 W(B) COMMIT BEGIN R(A) sum = A R(B) sum += B ECHO sum COMMIT

T1 T2

Is it possible to modify only the application logic so that schedule produces a "correct" result but is still not conflict serializable?

TIM E

Schedule

T1 T2

Dependency Graph

A B

if(A≥0): cnt++ if(B≥0): cnt++ ECHO cnt

I

slide-71
SLIDE 71

CMU 15-445/645 (Fall 2018)

VIEW SERIALIZABILITY

Alternative (weaker) notion of serializability. Schedules S1 and S2 are view equivalent if:

→ If T1 reads initial value of A in S1, then T1 also reads initial value of A in S2. → If T1 reads value of A written by T2 in S1, then T1 also reads value of A written by T2 in S2. → If T1 writes final value of A in S1, then T1 also writes final value of A in S2.

55

I

slide-72
SLIDE 72

CMU 15-445/645 (Fall 2018)

Dependency Graph

VIEW SERIALIZABILITY

56

BEGIN R(A) W(A) COMMIT BEGIN W(A) COMMIT BEGIN W(A) COMMIT

A

T1 T2 T3

TIM E

Schedule

T1 T2 T3

I

slide-73
SLIDE 73

CMU 15-445/645 (Fall 2018)

Dependency Graph

VIEW SERIALIZABILITY

56

BEGIN R(A) W(A) COMMIT BEGIN W(A) COMMIT BEGIN W(A) COMMIT

A A

T1 T2 T3

TIM E

Schedule

T1 T2 T3

I

slide-74
SLIDE 74

CMU 15-445/645 (Fall 2018)

Dependency Graph

VIEW SERIALIZABILITY

56

BEGIN R(A) W(A) COMMIT BEGIN W(A) COMMIT BEGIN W(A) COMMIT

A A A

T1 T2 T3

TIM E

Schedule

T1 T2 T3

I

slide-75
SLIDE 75

CMU 15-445/645 (Fall 2018)

Dependency Graph

VIEW SERIALIZABILITY

56

BEGIN R(A) W(A) COMMIT BEGIN W(A) COMMIT BEGIN W(A) COMMIT

A A A A

T1 T2 T3

TIM E

Schedule

T1 T2 T3

I

slide-76
SLIDE 76

CMU 15-445/645 (Fall 2018)

Dependency Graph

VIEW SERIALIZABILITY

56

BEGIN R(A) W(A) COMMIT BEGIN W(A) COMMIT BEGIN W(A) COMMIT

A A A A A

T1 T2 T3

TIM E

Schedule

T1 T2 T3

I

slide-77
SLIDE 77

CMU 15-445/645 (Fall 2018)

VIEW SERIALIZABILITY

57

BEGIN R(A) W(A) COMMIT BEGIN W(A) COMMIT BEGIN W(A) COMMIT BEGIN R(A) W(A) COMMIT BEGIN W(A) COMMIT BEGIN W(A) COMMIT

VIEW

TIM E

Schedule

T1 T2 T3

Allows all conflict serializable schedules + "blind writes"

Schedule

T1 T2 T3

I

slide-78
SLIDE 78

CMU 15-445/645 (Fall 2018)

SERIALIZABILITY

View Serializability allows for (slightly) more schedules than Conflict Serializability does.

→ But is difficult to enforce efficiently.

Neither definition allows all schedules that you would consider "serializable".

→ This is because they don’t understand the meanings of the

  • perations or the data (recall example #3)

58

I

slide-79
SLIDE 79

CMU 15-445/645 (Fall 2018)

SERIALIZABILITY

In practice, Conflict Serializability is what systems support because it can be enforced efficiently. To allow more concurrency, some special cases get handled separately at the application level.

59

I

slide-80
SLIDE 80

CMU 15-445/645 (Fall 2018)

All Schedules

UN IVERSE O F SCH EDULES

60

View Serializable Conflict Serializable Serial

I

slide-81
SLIDE 81

CMU 15-445/645 (Fall 2018)

TRAN SACTIO N DURABILITY

All of the changes of committed transactions should be persistent.

→ No torn updates. → No changes from failed transactions.

The DBMS can use either logging or shadow paging to ensure that all changes are durable.

61

D

slide-82
SLIDE 82

CMU 15-445/645 (Fall 2018)

ACID PRO PERTIES

Atomicity: All actions in the txn happen, or none happen. Consistency: If each txn is consistent and the DB starts consistent, then it ends up consistent. Isolation: Execution of one txn is isolated from that of other txns. Durability: If a txn commits, its effects persist.

62

slide-83
SLIDE 83

CMU 15-445/645 (Fall 2018)

CO N CLUSIO N

Concurrency control and recovery are among the most important functions provided by a DBMS. Concurrency control is automatic

→ System automatically inserts lock/unlock requests and schedules actions of different txns. → Ensures that resulting execution is equivalent to executing the txns one after the other in some order.

63

slide-84
SLIDE 84

CMU 15-445/645 (Fall 2018)

N EXT CLASS

Two-Phase Locking Isolation Levels

64