Serializable Snapshot Isolation
Making ISOLATION LEVEL SERIALIZABLE Provide Serializable Isolation
Dan Ports MIT Kevin Grittner Wisconsin Court System
1 Saturday, May 21, 2011
Serializable Snapshot Isolation Making ISOLATION LEVEL SERIALIZABLE - - PowerPoint PPT Presentation
Serializable Snapshot Isolation Making ISOLATION LEVEL SERIALIZABLE Provide Serializable Isolation Dan Ports Kevin Grittner MIT Wisconsin Court System Saturday, May 21, 2011 1 Overview Serializable isolation makes it easier to reason
Dan Ports MIT Kevin Grittner Wisconsin Court System
1 Saturday, May 21, 2011
Serializable isolation makes it easier to reason about concurrent transactions In 9.0 and before, SERIALIZABLE was really snapshot isolation – allows anomalies in 9.1: Serializable Snapshot Isolation (SSI)
(first implementation in a production DBMS!)
2 Saturday, May 21, 2011
3 Saturday, May 21, 2011
Transactions group related operations:
shouldnʼt see one operation without the others
concurrently (isolation)
4 Saturday, May 21, 2011
Serializable isolation: each transaction is guaranteed to behave as though itʼs the only one running
transactionʼs behavior in isolation Weaker isolation levels:
cause anomalous behavior
5 Saturday, May 21, 2011
SQL Standard SERIALIZABLE REPEATABLE READ READ COMMITTED READ UNCOMMITTED t ment s
6 Saturday, May 21, 2011
SQL Standard SERIALIZABLE REPEATABLE READ READ COMMITTED READ UNCOMMITTED t ment s 9.0 snapshot isolation per-statement snapshots
6 Saturday, May 21, 2011
SQL Standard SERIALIZABLE REPEATABLE READ READ COMMITTED READ UNCOMMITTED t ment s 9.0 snapshot isolation per-statement snapshots 9.1 SSI snapshot isolation per-statement snapshots
6 Saturday, May 21, 2011
Each transaction sees a “snapshot” of DB taken at its first query
concurrent modifications Still a weaker isolation level than true serializability!
7 Saturday, May 21, 2011
8 Saturday, May 21, 2011
guard
uty? Alice y Bob y
9 Saturday, May 21, 2011
BEGIN SELECT count(*) FROM guards WHERE on-duty = y if > 1 { UPDATE guards SET on-duty = n WHERE guard = x } COMMIT
guard
uty? Alice y Bob y
9 Saturday, May 21, 2011
guard
uty? Alice y Bob y
10 Saturday, May 21, 2011
guard
uty? Alice y Bob y
BEGIN SELECT count(*) FROM guards WHERE on-duty = y [result = 2]
10 Saturday, May 21, 2011
guard
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]
10 Saturday, May 21, 2011
guard
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
10 Saturday, May 21, 2011
guard
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
10 Saturday, May 21, 2011
guard
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
10 Saturday, May 21, 2011
guard
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
10 Saturday, May 21, 2011
Serializable means: results equivalent to some serial ordering of the transactions Serialization history graph shows dependencies between transactions
if B sees a change made by A
if B overwrites a change by A
if B doesnʼt see a change made by A
Serializable if no cycle in graph
11 Saturday, May 21, 2011
guard
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
12 Saturday, May 21, 2011
guard
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
12 Saturday, May 21, 2011
guard
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
12 Saturday, May 21, 2011
rw-conflict: T1 didnʼt see T2ʼs UPDATE
rw-conflict: T2 didnʼt see T1ʼs UPDATE
cycle means no serial order exists! T1 before T2 before T1...
13 Saturday, May 21, 2011
Three transactions:
Invariant: after we read yesterdayʼs report, no new receipts for yesterday should appear
14 Saturday, May 21, 2011
T1 T2
SELECT batch FROM control [result = 5/19] UPDATE control SET batch = 5/20 COMMIT INSERT receipt (5/19, …) COMMIT
rw-conflict: T1 didnʼt see T2ʼs UPDATE
15 Saturday, May 21, 2011
[incr-batch]
[add-receipt]
rw-conflict: T1 didnʼt see T2ʼs UPDATE
Apparent order of execution: T1 before T2 ...but T2 committed before T1. Thatʼs OK!
16 Saturday, May 21, 2011
T1 T2
SELECT batch FROM control [result = 5/19] UPDATE control SET batch = 5/20 COMMIT INSERT receipt (5/19, …) COMMIT
T3
17 Saturday, May 21, 2011
T1 T2
SELECT batch FROM control [result = 5/19] UPDATE control SET batch = 5/20 COMMIT INSERT receipt (5/19, …) COMMIT SELECT batch... [result = 5/20] SELECT 5/19 receipts [...]
T3
17 Saturday, May 21, 2011
T1 T2
SELECT batch FROM control [result = 5/19] UPDATE control SET batch = 5/20 COMMIT INSERT receipt (5/19, …) COMMIT SELECT batch... [result = 5/20] SELECT 5/19 receipts [...]
T3
rw-conflict
17 Saturday, May 21, 2011
T1 T2
SELECT batch FROM control [result = 5/19] UPDATE control SET batch = 5/20 COMMIT INSERT receipt (5/19, …) COMMIT SELECT batch... [result = 5/20] SELECT 5/19 receipts [...]
T3
rw-conflict wr-dependency
17 Saturday, May 21, 2011
T1 T2
SELECT batch FROM control [result = 5/19] UPDATE control SET batch = 5/20 COMMIT INSERT receipt (5/19, …) COMMIT SELECT batch... [result = 5/20] SELECT 5/19 receipts [...]
T3
rw-conflict wr-dependency rw-conflict
17 Saturday, May 21, 2011
[incr-batch]
[add-receipt]
rw-conflict: T1 didnʼt see T2ʼs UPDATE
Adding the read-only transaction creates a cycle.
[report]
wr-dependency: T3 did see T2ʼs UPDATE rw-conflict: T3 didnʼt see T1ʼs INSERT
18 Saturday, May 21, 2011
19 Saturday, May 21, 2011
20 Saturday, May 21, 2011
T1 T2
SELECT batch FROM control [result = 5/19]
21 Saturday, May 21, 2011
T1 T2
SELECT batch FROM control [result = 5/19]
21 Saturday, May 21, 2011
T1 T2
SELECT batch FROM control [result = 5/19] UPDATE control SET batch = 5/20 [blocked!]
21 Saturday, May 21, 2011
T1 T2
SELECT batch FROM control [result = 5/19] UPDATE control SET batch = 5/20 [blocked!] INSERT receipt (5/19, …) COMMIT
21 Saturday, May 21, 2011
T2 T1
22 Saturday, May 21, 2011
T2 T1
22 Saturday, May 21, 2011
T2 T1 T3
22 Saturday, May 21, 2011
T2 T1 T3
22 Saturday, May 21, 2011
T2 T1 T3
22 Saturday, May 21, 2011
T2 T1 T3
22 Saturday, May 21, 2011
Serializability theory tells us:
rw-conflict edges (where A didnʼt see Bʼs update) So we can just look for those
[Cahill et al. Serializable Isolation For Snapshot Databases, SIGMOD ʼ08]
23 Saturday, May 21, 2011
24 Saturday, May 21, 2011
Need to keep some extra transaction state
until all concurrent transactions commit
But how do we identify a rw-conflict?
25 Saturday, May 21, 2011
Recall: T1 —> T2 if T2 makes a change, and T1ʼs read doesnʼt see its effects
T1 will see tupleʼs MVCC data and ignore it
use a “lock” to know that T2ʼs write conflicts
xmin xmax data T2 …
26 Saturday, May 21, 2011
Recall: T1 —> T2 if T2 makes a change, and T1ʼs read doesnʼt see its effects
T1 will see tupleʼs MVCC data and ignore it
use a “lock” to know that T2ʼs write conflicts
xmin xmax data T2 …
T2 not in T1ʼs snapshot => conflict w/ T1
26 Saturday, May 21, 2011
Acquire a “SIREAD lock” on anything read Check for SIREAD locks on write, flag conflict New lock manager — unlike current locks:
27 Saturday, May 21, 2011
Not enough just to lock returned tuples: Really want predicate locking:
“lock everything where x=42” (but not feasible)
Instead: lock corresponding index page
SELECT FROM... WHERE x=42 [3 results] INSERT INTO… VALUES (x=42) [should conflict; wonʼt]
28 Saturday, May 21, 2011
Deferrable read-only transactions
without lock overhead or risk of abort
Dealing with shared memory exhaustion
and push to disk if necessary (SLRU)
29 Saturday, May 21, 2011
30 Saturday, May 21, 2011
Conflicts may cause transactions to abort
Performance tips
31 Saturday, May 21, 2011
32 Saturday, May 21, 2011
Two main sources of slowdown
SIREAD lock manager add?
because of conflicts?
33 Saturday, May 21, 2011
DBT-2 benchmark (OLTP, like TPC-C)
serialization failure Configuration:
34 Saturday, May 21, 2011
Approach: use highest scale factor that gives 90% request latency < 5 seconds
REPEATABLE READ (snapshot isolation):
SERIALIZABLE (SSI):
35 Saturday, May 21, 2011
True serializable transactions are here!
can simplify applications
mechanisms
36 Saturday, May 21, 2011