Serializable Snapshot Isolation in PostgreSQL Dan Ports Kevin - - PowerPoint PPT Presentation

serializable snapshot isolation in postgresql
SMART_READER_LITE
LIVE PREVIEW

Serializable Snapshot Isolation in PostgreSQL Dan Ports Kevin - - PowerPoint PPT Presentation

Serializable Snapshot Isolation in PostgreSQL Dan Ports Kevin Grittner University of Washington Wisconsin Supreme Court MIT Tuesday, August 28, 2012 For years, PostgreSQLs SERIALIZABLE mode did not provide true serializability


slide-1
SLIDE 1

Serializable Snapshot Isolation in PostgreSQL

Dan Ports University of Washington MIT Kevin Grittner Wisconsin Supreme Court

Tuesday, August 28, 2012

slide-2
SLIDE 2

For years, PostgreSQL’s “SERIALIZABLE” mode did not provide true serializability

  • instead: snapshot isolation – allows anomalies

PostgreSQL 9.1: Serializable Snapshot Isolation

  • based on recent research [Cahill, SIGMOD ’08]
  • first implementation in a production DB release

& first in a purely-snapshot DB

Tuesday, August 28, 2012

slide-3
SLIDE 3

This talk....

  • Motivation: Why serializability?

Why did we choose SSI?

  • Review of snapshot isolation and SSI
  • Implementation challenges & optimizations
  • Performance

Tuesday, August 28, 2012

slide-4
SLIDE 4

Serializability vs. Performance

Two perspectives:

  • Serializability is important for correctness
  • simplifies development;

don’t need to worry about race conditions

  • Serializability is too expensive to use
  • locking restricts concurrency;

use weaker isolation levels instead

Tuesday, August 28, 2012

slide-5
SLIDE 5

Serializability vs. Performance

(in PostgreSQL)

PostgreSQL offered snapshot isolation instead

  • better performance than 2-phase locking

“readers don’t block writers, writers don’t block readers”

  • but doesn’t guarantee serializability!

Snapshot isolation isn’t enough for some users

  • complex databases with strict integrity requirements,

e.g. Wisconsin Court System

Tuesday, August 28, 2012

slide-6
SLIDE 6

Serializability vs. Performance

(in PostgreSQL)

PostgreSQL offered snapshot isolation instead

  • better performance than 2-phase locking

“readers don’t block writers, writers don’t block readers”

  • but doesn’t guarantee serializability!

Snapshot isolation isn’t enough for some users

  • complex databases with strict integrity requirements,

e.g. Wisconsin Court System

Serializable Snapshot Isolation

  • ffered true serializability with

performance benefits of snapshot isolation!

Tuesday, August 28, 2012

slide-7
SLIDE 7

Serializable Snapshot Isolation

SSI approach:

  • run transactions using snapshot isolation
  • detect conflicts between transactions at runtime;

abort transactions to prevent anomalies

Appealing for performance reasons

  • aborts less common than blocking under 2PL
  • readers still don’t block writers!

[Cahill et al. Serializable Isolation for Snapshot Databases, SIGMOD ’08]

Tuesday, August 28, 2012

slide-8
SLIDE 8

SSI in PostgreSQL

Available in PostgreSQL 9.1; first production implementation Contributions: new implementation techniques

  • Detecting conflicts in a purely-snapshot DB
  • Limiting memory usage
  • Read-only transaction optimizations
  • Integration with other PostgreSQL features

Tuesday, August 28, 2012

slide-9
SLIDE 9

Outline

  • Motivation
  • Review of snapshot isolation and SSI
  • Implementation challenges & optimizations
  • Performance
  • Conclusions

Tuesday, August 28, 2012

slide-10
SLIDE 10

Goal: ensure at least one guard always on-duty

guard

  • n-duty?

uty? Alice y Bob y

Tuesday, August 28, 2012

slide-11
SLIDE 11

BEGIN SELECT count(*) FROM guards WHERE on-duty = y if > 1 { UPDATE guards SET on-duty = n WHERE guard = x } COMMIT

Goal: ensure at least one guard always on-duty

guard

  • n-duty?

uty? Alice y Bob y

Tuesday, August 28, 2012

slide-12
SLIDE 12

guard

  • n-duty?

uty? Alice y Bob y

Tuesday, August 28, 2012

slide-13
SLIDE 13

guard

  • n-duty?

uty? Alice y Bob y

BEGIN SELECT count(*) FROM guards WHERE on-duty = y [result = 2]

Tuesday, August 28, 2012

slide-14
SLIDE 14

guard

  • n-duty?

uty? Alice y Bob y

BEGIN SELECT count(*) FROM guard WHERE on-duty = y [result = 2] BEGIN SELECT count(*) FROM guards WHERE on-duty = y [result = 2]

Tuesday, August 28, 2012

slide-15
SLIDE 15

guard

  • n-duty?

uty? Alice y Bob y

BEGIN SELECT count(*) FROM guard WHERE on-duty = y [result = 2] BEGIN SELECT count(*) FROM guards WHERE on-duty = y [result = 2] if > 1 { UPDATE guards SET on-duty = n WHERE guard = ‘Alice’ } COMMIT

Tuesday, August 28, 2012

slide-16
SLIDE 16

guard

  • n-duty?

uty? Alice y Bob y

BEGIN SELECT count(*) FROM guard WHERE on-duty = y [result = 2] BEGIN SELECT count(*) FROM guards WHERE on-duty = y [result = 2] if > 1 { UPDATE guards SET on-duty = n WHERE guard = ‘Alice’ } COMMIT

n

Tuesday, August 28, 2012

slide-17
SLIDE 17

guard

  • n-duty?

uty? Alice y Bob y

BEGIN SELECT count(*) FROM guard WHERE on-duty = y [result = 2] if > 1 { UPDATE guards SET on-duty = n WHERE guards = ‘Bob’ } COMMIT BEGIN SELECT count(*) FROM guards WHERE on-duty = y [result = 2] if > 1 { UPDATE guards SET on-duty = n WHERE guard = ‘Alice’ } COMMIT

n

Tuesday, August 28, 2012

slide-18
SLIDE 18

guard

  • n-duty?

uty? Alice y Bob y

BEGIN SELECT count(*) FROM guard WHERE on-duty = y [result = 2] if > 1 { UPDATE guards SET on-duty = n WHERE guards = ‘Bob’ } COMMIT BEGIN SELECT count(*) FROM guards WHERE on-duty = y [result = 2] if > 1 { UPDATE guards SET on-duty = n WHERE guard = ‘Alice’ } COMMIT

n n

Tuesday, August 28, 2012

slide-19
SLIDE 19

guard

  • n-duty?

uty? Alice y Bob y

BEGIN SELECT count(*) FROM guard WHERE on-duty = y [result = 2] if > 1 { UPDATE guards SET on-duty = n WHERE guards = ‘Bob’ } COMMIT BEGIN SELECT count(*) FROM guards WHERE on-duty = y [result = 2] if > 1 { UPDATE guards SET on-duty = n WHERE guard = ‘Alice’ } COMMIT

n n

Tuesday, August 28, 2012

slide-20
SLIDE 20

guard

  • n-duty?

uty? Alice y Bob y

BEGIN SELECT count(*) FROM guard WHERE on-duty = y [result = 2] if > 1 { UPDATE guards SET on-duty = n WHERE guards = ‘Bob’ } COMMIT BEGIN SELECT count(*) FROM guards WHERE on-duty = y [result = 2] if > 1 { UPDATE guards SET on-duty = n WHERE guard = ‘Alice’ } COMMIT

n n

rw-conflict: T1 didn’t see T2’s UPDATE

Tuesday, August 28, 2012

slide-21
SLIDE 21

guard

  • n-duty?

uty? Alice y Bob y

BEGIN SELECT count(*) FROM guard WHERE on-duty = y [result = 2] if > 1 { UPDATE guards SET on-duty = n WHERE guards = ‘Bob’ } COMMIT BEGIN SELECT count(*) FROM guards WHERE on-duty = y [result = 2] if > 1 { UPDATE guards SET on-duty = n WHERE guard = ‘Alice’ } COMMIT

n n

rw-conflict: T1 didn’t see T2’s UPDATE rw-conflict: T2 didn’t see T1’s UPDATE

Tuesday, August 28, 2012

slide-22
SLIDE 22

SSI Approach

Detect these rw-conflicts and maintain a conflict graph Serializability theory: each anomaly involves two adjacent rw-conflict edges

  • if found, abort some involved transaction
  • note: can have false positives

Tuesday, August 28, 2012

slide-23
SLIDE 23

T2

rw-conflict: T1 didn’t see T2’s UPDATE

T1

rw-conflict: T2 didn’t see T1’s UPDATE

two adjacent edges: T1 -> T2 and T2 -> T1

Tuesday, August 28, 2012

slide-24
SLIDE 24

T2

rw-conflict: T1 didn’t see T2’s UPDATE

T1

rw-conflict: T2 didn’t see T1’s UPDATE

two adjacent edges: T1 -> T2 and T2 -> T1

X

Tuesday, August 28, 2012

slide-25
SLIDE 25

T2

rw-conflict: T1 didn’t see T2’s UPDATE

T1

rw-conflict: T2 didn’t see T1’s UPDATE

two adjacent edges: T1 -> T2 and T2 -> T1

X

ERROR: could not serialize access due to read/write dependencies among transactions HINT: The transaction might succeed if retried.

Tuesday, August 28, 2012

slide-26
SLIDE 26

Outline

  • Motivation
  • Review of snapshot isolation and SSI
  • Implementation challenges &
  • ptimizations
  • Performance
  • Conclusions

Tuesday, August 28, 2012

slide-27
SLIDE 27

SSI in PostgreSQL

Implementation challenges:

  • Detecting conflicts in a purely-snapshot DB
  • requires new lock manager
  • Reining in potentially-unbounded memory usage

Tuesday, August 28, 2012

slide-28
SLIDE 28

Detecting Conflicts

How to detect when an update conflicts with a previous read? Previous SSI implementations: reuse read locks from existing lock mgr But...

  • PostgreSQL didn’t have read locks!
  • ...let alone predicate locks

Tuesday, August 28, 2012

slide-29
SLIDE 29

SSI Lock Manager

Needed to build a new lock manager to track read dependencies

  • Uses multigranularity locks, index-range locks
  • Doesn’t block, just flags conflicts

=> no deadlocks

  • Locks need to persist past transaction commit

Tuesday, August 28, 2012

slide-30
SLIDE 30

Memory Usage

Need to keep track of transaction readsets + conflict graph

  • not just active transactions; also

committed ones that ran concurrently

  • one long-running transaction can cause

memory usage to grow without bound Could exhaust shared memory space (esp. in PostgreSQL)

Tuesday, August 28, 2012

slide-31
SLIDE 31

Read-Only Transactions

Many long-running transactions are read-only;

  • ptimize for these

Safe snapshots: cases where r/o transactions can never be a part of an anomaly

  • can then run using regular SI w/o SSI overhead
  • but: can only detect once all concurrent r/w

transactions complete

Deferrable transactions: delay execution to ensure safe snapshot

Tuesday, August 28, 2012

slide-32
SLIDE 32

Graceful Degradation

What if we still run out of memory? Don’t want to refuse to accept new transactions Instead: keep less information (tradeoff: more false positives)

  • keep less state about committed transactions
  • deduplicate readsets: “read by some committed

transaction”

Tuesday, August 28, 2012

slide-33
SLIDE 33

Outline

  • Motivation
  • Review of snapshot isolation and SSI
  • Implementation challenges & optimizations
  • Performance
  • Conclusions

Tuesday, August 28, 2012

slide-34
SLIDE 34

Performance

TPC-C-derived benchmark; modified to have SI anomalies Varied fraction of r/o and r/w transactions Compared PostgreSQL 9.1’s SSI against SI, and an implementation of S2PL

Tuesday, August 28, 2012

slide-35
SLIDE 35

Performance (in-memory)

0.4x 0.5x 0.6x 0.7x 0.8x 0.9x 1.0x 0% 20% 40% 60% 80% 100% SI SSI SSI (no r/o opt.) S2PL

25 warehouses (3 GB), tmpfs

  • trans. rate

(normalized) Fraction of read-only transactions

Tuesday, August 28, 2012

slide-36
SLIDE 36

Performance (disk)

150 warehouses (19 GB)

  • trans. rate

(normalized) Fraction of read-only transactions

0.4x 0.5x 0.6x 0.7x 0.8x 0.9x 1.0x 0% 20% 40% 60% 80% 100% SI SSI S2PL

Tuesday, August 28, 2012

slide-37
SLIDE 37

Conclusion

SSI available now in PostgreSQL 9.1

  • true serializability without blocking
  • new lock manager to track read dependencies
  • optimizations for read-only transactions

Performance close to that of SI

  • outperforms S2PL on read-heavy workloads
  • makes serializable mode a more practical
  • ption for some users

Tuesday, August 28, 2012