Coarse-Grained Transactions Maurice Herlihy Brown University Joint work with Eric Koskinen and...

Post on 18-Dec-2015

222 views 5 download

Tags:

Transcript of Coarse-Grained Transactions Maurice Herlihy Brown University Joint work with Eric Koskinen and...

Coarse-Grained Transactions

Maurice HerlihyBrown University

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

TMW April 2010

Skew Heaps

0

1

Tree with “heap”

property2

43

TMW April 2010

Concurrent Skew Heap

0

1 3

54

2

Insert me!

6

Insert me!

TMW April 2010

Concurrent Skew Heap

0

1 3

54

2 6 Lock parent

Swap R & L

TMW April 2010

Concurrent Skew Heap

0

1 3

54

6

Lock right child

Unlock parent2

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

TMW April 2010

Transactional Skew Heap

0

1 3

54

2

Insert me!

6

Insert me!

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

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?

TMW April 2010

Pessimistic Boosting

transactions

Abstract locks Black-box linearizable data

object

Undo Logs

TMW April 2010

Pessimistic Boosting

transactions

Abstract locks Black-box linearizable data

object

Undo Logs

add(x)

TMW April 2010

Pessimistic Boosting

transactions

Abstract locks Black-box linearizable data

object

Undo Logs

add(x)

TMW April 2010

Pessimistic Boosting

transactions

Abstract locks Black-box linearizable data

object

Undo Logs

add(x)

TMW April 2010

Pessimistic Boosting

transactions

Abstract locks Black-box linearizable data

object

rem(x)

Undo Logs

add(x)

x

TMW April 2010

Pessimistic Boosting

transactions

Abstract locks Black-box linearizable data

object

rem(x)

Undo Logs

add(x)

x

add(y)

y

TMW April 2010

Pessimistic Boosting

transactions

Abstract locks Black-box linearizable data

object

rem(x)

Undo Logs

add(x)

x

member(x)

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?

TMW April 2010

Optimistic Boosting

Black-box linearizable data

object

TMW April 2010

Optimistic Boosting

private copies

Black-box linearizable data

object

TMW April 2010

Optimistic Boostingredo logs

private copies

Black-box linearizable data

object

TMW April 2010

Optimistic Boostingredo logs

private copies

Black-box linearizable data

object

add(x)

TMW April 2010

Optimistic Boostingadd(x)

redo logs

private copies

Black-box linearizable data

object

add(x)

x

TMW April 2010

Optimistic Boostingadd(x) add(y)

redo logs

private copies

Black-box linearizable data

object

add(x)

x

add(y)

y

TMW April 2010

On Commitadd(x) add(y)

redo logs

private copies

Black-box linearizable data

object

x y

add(x)

add(x)

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

TMW April 2010

On Commitadd(x) add(y)

x y

add(x)

add(x)

x

x

Different physical values,Same logical values

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

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?

TMW April 2010

Left-Movers

time

legal history

TMW April 2010

Left-Movers

time

If and are adjacent,Ok to move earlier

TMW April 2010

Left-Mover Example: Semaphore

time

inc()dec() dec()

1 0 1 0

TMW April 2010

Inc() is Left-mover WRT Dec()

time

inc() dec() dec()

1 10 01 02 11

TMW April 2010

Same sequence of calls(results unaffected)

Left-Mover Example: Semaphore

time

inc() dec() dec()

1 10 01 02 11

TMW April 2010

Same final state

Left-Mover Example: Semaphore

time

inc() dec() dec()

3 23 23 24 33

TMW April 2010

Left-Mover Counter-example

time

1

dec()

0

inc()

1

dec()

0

TMW April 2010

Dec() not Left-Mover WRT Inc()

time

1

dec()

0

inc()

1

dec()

0-1

TMW April 2010

Right-Movers

time

legal history

TMW April 2010

Right-Movers

time

If and are adjacent,Ok to move later

TMW April 2010

Commutativity

time

If and are adjacent,Ok to swap

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

What Theory? Sept 2009 41

Pessimistic Semantics(modify shared state in place)

time

Txn B beg

Txn A beg abt

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

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

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

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

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)

Pessimistic Optimistic

Two Execution Models

What Theory? Sept 2009 47

Left-Moverness Right-MovernessAlgebraic Abstract

Properties

TMW April 2010

Challenges

• Automation?– Theorem proving– Model checking

• Compiler & Language support?• Implementation …