Coarse-Grained Transactions

48
Coarse-Grained Transactions Maurice Herlihy Brown University Joint work with Eric Koskinen and Matthew Parkinson (POPL 10)

description

Coarse-Grained Transactions. Maurice Herlihy Brown University Joint work with Eric Koskinen and Matthew Parkinson   (POPL 10). Skew Heaps. Tree with “heap” property. 0. 1. 2. 3. 4. Concurrent Skew Heap. Insert me!. Insert me!. 6. 0. 2. 1. 3. 4. 5. Concurrent Skew Heap. 2. 6. - PowerPoint PPT Presentation

Transcript of Coarse-Grained Transactions

Page 1: Coarse-Grained Transactions

Coarse-Grained Transactions

Maurice HerlihyBrown University

Joint work with Eric Koskinen and Matthew Parkinson  (POPL 10)

Page 2: Coarse-Grained Transactions

TMW April 2010

Skew Heaps

0

1

Tree with “heap”

property2

43

Page 3: Coarse-Grained Transactions

TMW April 2010

Concurrent Skew Heap

0

1 3

54

2

Insert me!

6

Insert me!

Page 4: Coarse-Grained Transactions

TMW April 2010

Concurrent Skew Heap

0

1 3

54

2 6 Lock parent

Swap R & L

Page 5: Coarse-Grained Transactions

TMW April 2010

Concurrent Skew Heap

0

1 3

54

6

Lock right child

Unlock parent2

Page 6: Coarse-Grained Transactions

TMW April 2010

Concurrent Skew Heap

0

1 3

54

6

2

No global rebalancingNo global rebalancing

Good amortized performanceGood amortized performance

Good concurrencyGood concurrency

Page 7: Coarse-Grained Transactions

TMW April 2010

Transactional Skew Heap

0

1 3

54

2

Insert me!

6

Insert me!

Page 8: Coarse-Grained Transactions

TMW April 2010

Transactional Skew Heap

0

1 3

54

2 6

I wrote

0

Write-write

conflict!

Good concurrency with lockingGood concurrency with locking

Not with transactions …Not with transactions …

Confusion betweenthread-level & transaction-level synchronization

Confusion betweenthread-level & transaction-level synchronization

Page 9: Coarse-Grained Transactions

TMW April 2010

Coarse-Grained Synchronization

Synchronize on high-level operations,Like add(), remove(), etc. …

Not low-level reads and writes

Synchronize on high-level operations,Like add(), remove(), etc. …

Not low-level reads and writesPessimistic: update in place, undo on abortPessimistic: update in place, undo on abort

Optimistic: update private copy, apply changes on commit

Optimistic: update private copy, apply changes on commit

But what is the meaning of conflict?

But what is the meaning of conflict?

Page 10: Coarse-Grained Transactions

TMW April 2010

Pessimistic Boosting

transactions

Abstract locks Black-box linearizable data

object

Undo Logs

Page 11: Coarse-Grained Transactions

TMW April 2010

Pessimistic Boosting

transactions

Abstract locks Black-box linearizable data

object

Undo Logs

add(x)

Page 12: Coarse-Grained Transactions

TMW April 2010

Pessimistic Boosting

transactions

Abstract locks Black-box linearizable data

object

Undo Logs

add(x)

Page 13: Coarse-Grained Transactions

TMW April 2010

Pessimistic Boosting

transactions

Abstract locks Black-box linearizable data

object

Undo Logs

add(x)

Page 14: Coarse-Grained Transactions

TMW April 2010

Pessimistic Boosting

transactions

Abstract locks Black-box linearizable data

object

rem(x)

Undo Logs

add(x)

x

Page 15: Coarse-Grained Transactions

TMW April 2010

Pessimistic Boosting

transactions

Abstract locks Black-box linearizable data

object

rem(x)

Undo Logs

add(x)

x

add(y)

y

Page 16: Coarse-Grained Transactions

TMW April 2010

Pessimistic Boosting

transactions

Abstract locks Black-box linearizable data

object

rem(x)

Undo Logs

add(x)

x

member(x)

Page 17: Coarse-Grained Transactions

TMW April 2010

Pessimistic BoostingThread-safe base objectThread-safe base object

Updated in placeUpdated in placeLog InversesLog InversesConflicting operations blocked by abstract locksConflicting operations blocked by abstract locks

What does it mean for operations to conflict?What does it mean for operations to conflict?

Page 18: Coarse-Grained Transactions

TMW April 2010

Optimistic Boosting

Black-box linearizable data

object

Page 19: Coarse-Grained Transactions

TMW April 2010

Optimistic Boosting

private copies

Black-box linearizable data

object

Page 20: Coarse-Grained Transactions

TMW April 2010

Optimistic Boostingredo logs

private copies

Black-box linearizable data

object

Page 21: Coarse-Grained Transactions

TMW April 2010

Optimistic Boostingredo logs

private copies

Black-box linearizable data

object

add(x)

Page 22: Coarse-Grained Transactions

TMW April 2010

Optimistic Boostingadd(x)

redo logs

private copies

Black-box linearizable data

object

add(x)

x

Page 23: Coarse-Grained Transactions

TMW April 2010

Optimistic Boostingadd(x) add(y)

redo logs

private copies

Black-box linearizable data

object

add(x)

x

add(y)

y

Page 24: Coarse-Grained Transactions

TMW April 2010

On Commitadd(x) add(y)

redo logs

private copies

Black-box linearizable data

object

x y

add(x)

add(x)

Page 25: Coarse-Grained Transactions

TMW April 2010

On Commitadd(x) add(y)

redo logs

private copies

Black-box linearizable data

object

x y

add(x)

add(x)

No conflict, apply

updates to my copy

x

x

Page 26: Coarse-Grained Transactions

TMW April 2010

On Commitadd(x) add(y)

x y

add(x)

add(x)

x

x

Different physical values,Same logical values

Page 27: Coarse-Grained Transactions

TMW April 2010

On Commitadd(x) rem(x)

redo logs

private copies

Black-box linearizable data

object

x

add(x)

add(x)

Conflict! Abort & restore my copy

x

Page 28: Coarse-Grained Transactions

TMW April 2010

Optimistic BoostingThread-local object copiesThread-local object copies

Deferred operatons kept in redo logDeferred operatons kept in redo log

No inversesNo inversesOn commit, broadcast deferred operations

To other transactions, public copy

On commit, broadcast deferred operationsTo other transactions, public copyTransactions snoop on broadcast,

Abort if conflict detected

Transactions snoop on broadcast,Abort if conflict detected

What does it mean for operations to conflict?What does it mean for operations to conflict?

Page 29: Coarse-Grained Transactions

TMW April 2010

Left-Movers

time

legal history

Page 30: Coarse-Grained Transactions

TMW April 2010

Left-Movers

time

If and are adjacent,Ok to move earlier

Page 31: Coarse-Grained Transactions

TMW April 2010

Left-Mover Example: Semaphore

time

inc()dec() dec()

1 0 1 0

Page 32: Coarse-Grained Transactions

TMW April 2010

Inc() is Left-mover WRT Dec()

time

inc() dec() dec()

1 10 01 02 11

Page 33: Coarse-Grained Transactions

TMW April 2010

Same sequence of calls(results unaffected)

Left-Mover Example: Semaphore

time

inc() dec() dec()

1 10 01 02 11

Page 34: Coarse-Grained Transactions

TMW April 2010

Same final state

Left-Mover Example: Semaphore

time

inc() dec() dec()

3 23 23 24 33

Page 35: Coarse-Grained Transactions

TMW April 2010

Left-Mover Counter-example

time

1

dec()

0

inc()

1

dec()

0

Page 36: Coarse-Grained Transactions

TMW April 2010

Dec() not Left-Mover WRT Inc()

time

1

dec()

0

inc()

1

dec()

0-1

Page 37: Coarse-Grained Transactions

TMW April 2010

Right-Movers

time

legal history

Page 38: Coarse-Grained Transactions

TMW April 2010

Right-Movers

time

If and are adjacent,Ok to move later

Page 39: Coarse-Grained Transactions

TMW April 2010

Commutativity

time

If and are adjacent,Ok to swap

Page 40: Coarse-Grained Transactions

What Theory? Sept 2009 40

Pessimistic Semantics(modify shared state in place)

time

Txn B beg

Txn A beg

Pessimistic Commit: Move Left of pendingPessimistic Commit: Move Left of pending

cmt

Page 41: Coarse-Grained Transactions

What Theory? Sept 2009 41

Pessimistic Semantics(modify shared state in place)

time

Txn B beg

Txn A beg abt

Page 42: Coarse-Grained Transactions

What Theory? Sept 2009 42

Pessimistic Semantics(modify shared state in place)

time

3

Txn B beg

Txn A beg 1 2 4

Pessimistic Abort: Move Right of pendingPessimistic Abort: Move Right of pending

24 3 1

Pessimistic Abort: Pending ops move LeftPessimistic Abort: Pending ops move Left

Page 43: Coarse-Grained Transactions

What Theory? Sept 2009 43

Pessimistic Semantics(modify shared state in place)

• Operations must be LEFT moversw.r.t. other pending operations

• On commit, move operations LEFT

• On abort, move operations RIGHT (free)and append inverses

Page 44: Coarse-Grained Transactions

What Theory? Sept 2009 44

Optimistic Semantics(modify local copies; merge)

time

Txn B

Txn A beg

Optimistic Commit: Move Right of committedOptimistic Commit: Move Right of committed

cmt

cmt

Page 45: Coarse-Grained Transactions

What Theory? Sept 2009 45

Optimistic Semantics(modify local copies; merge)

time

Txn B

Txn A beg

Optimistic Abort: Discard OperationsOptimistic Abort: Discard Operations

abt

cmt

Page 46: Coarse-Grained Transactions

What Theory? Sept 2009 46

• Operations must be RIGHT moversw.r.t. concurrently committed operations

• On commit, move operations RIGHT

• Abort if concurrent non-LM op• On abort, discard local changes

Optimistic Semantics(modify local copies; merge)

Page 47: Coarse-Grained Transactions

Pessimistic Optimistic

Two Execution Models

What Theory? Sept 2009 47

Left-Moverness Right-MovernessAlgebraic Abstract

Properties

Page 48: Coarse-Grained Transactions

TMW April 2010

Challenges

• Automation?– Theorem proving– Model checking

• Compiler & Language support?• Implementation …