Docsity

Concurrency Control - E-Commerce - Lecture Slides, Slides of Fundamentals of E-Commerce

Partial preview of the text

Download Concurrency Control - E-Commerce - Lecture Slides and more Slides Fundamentals of E-Commerce in PDF only on Docsity!

3. Concurrency Control

for Transactions

Part One

Transaction Processing

Outline

  1. A Simple System Model2. Serializability Theory3. Synchronization Requirements

for Recoverability

  1. Two-Phase Locking5. Preserving Transaction Handshakes6. Implementing Two-Phase Locking7. Deadlocks

Assumption - Atomic Operations

•^

We will synchronize Reads and Writes.

-^

We must therefore assume they’re atomic^ –

else we’d have to synchronize the finer-grainedoperations that implement Read and Write

-^

Read(x) - returns the current value of x in the DB

-^

Write(x, val) overwrites

all

of x (the

whole

page)

•^

This assumption of atomic operations is whatallows us to abstract executions as sequences ofreads and writes (without loss of information).^ –

Otherwise, what would w

[x] rk

[x] mean?i

•^

Also, commit (c

) and abort (ai

) are atomici

System Model

Transaction 1

Transaction N

Start, Commit, AbortRead(x), Write(x)

Data Manager Database

Transaction 2

Equivalence of Histories

•^

Two operations conflict if their execution orderaffects their return values or the DB state.^ –

a read and write on the same data item conflict

two writes on the same data item conflict - two reads (on the same data item) do

not

conflict

•^

Two histories are

equivalent

if they have the

same operations and conflicting operations arein the same order in both histories^ –

because only the relative order of conflictingoperations can affect the result of the histories

Examples of Equivalence

•^

The following histories are equivalentH

1

= r

[x] r 1

[x] w 2

[x] c 1

1

w

[y] c 2

2

H

2

= r

[x] r 2

[x] w 1

[x] c 1

1

w

[y] c 2

2

H

3

= r

[x] r 2

[x] w 1

[y] c 2

2

w

[x] c 1

1

H

4

= r

[x] w 2

[y] c 2

2

r^1

[x] w

[x] c 1

1

•^

But none of them are equivalent toH

5

= r

[x] w 1

[x] r 1

[x] c 2

1

w

[y] c 2

2

because r

[x] and w 2

[x] conflict and 1

r^2

[x] precedes w

[x] in H 1

1

- H

, but 4

r^2

[x] follows w

[x] in H 1

Another Example

•^

H

6 = r

[x] r 1

[x] w 2

[x] r 1

[x] w 3

[y] w 2

[x] c 3

3

w

[y] c 1

1

c^2

is equivalent to a serial execution of T

2

T

1

T^3

H

7

= r

[x] w 2

[y] c 2

2

r^1

[x] w

[x] w 1

[y] c 1

1

r^3

[x] w

[x] c 3

3

•^

Each conflict implies a constraint on any equivalentserial history:H

6 = r

[x] r 1

[x] w 2

[x] r 1

[x] w 3

[y] w 2

[x] c 3

3

w

[y] c 1

1

c^2

T

→ 2

T

1

T

→ 1

T

3

T

→ 2

T

1

T

→ 2

T

3

Serialization Graphs

•^

A serialization graph, SG(H), for history H tells theeffective execution order of transactions in H.

-^

Given history H, SG(H) is a directed graph whosenodes are the committed transactions and whoseedges are all T

→i

T

k^

such that at least one of T

’si

operations precedes and conflicts with at least oneof T

’s operationsk

H

6 = r

[x] r 1

[x] w 2

[x] r 1

[x] w 3

[y] w 2

[x] c 3

3

w

[y] c 1

1

c^2

SG(H

) = 6

T

→ 2

T

→ 1

T

3

Docsity.com