Concurrency Control II (OCC, MVCC)

Slides:



Advertisements
Similar presentations
CM20145 Concurrency Control
Advertisements

Concurrency Control III. General Overview Relational model - SQL Formal & commercial query languages Functional Dependencies Normalization Physical Design.
Optimistic Methods for Concurrency Control By : H.T. Kung & John T. Robinson Presenters: Munawer Saeed.
Database Systems (資料庫系統)
1 Concurrency Control Chapter Conflict Serializable Schedules  Two actions are in conflict if  they operate on the same DB item,  they belong.
Concurrency Control II
Topic 6.3: Transactions and Concurrency Control Hari Uday.
CSIS 7102 Spring 2004 Lecture 5 : Non-locking based concurrency control (and some more lock-based ones, too) Dr. King-Ip Lin.
Concurrency Control II. General Overview Relational model - SQL  Formal & commercial query languages Functional Dependencies Normalization Physical Design.
1 ICS 214B: Transaction Processing and Distributed Data Management Lecture 5: Tree-based Concurrency Control and Validation Currency Control Professor.
1 CS 194: Elections, Exclusion and Transactions Scott Shenker and Ion Stoica Computer Science Division Department of Electrical Engineering and Computer.
Lecture 11 Recoverability. 2 Serializability identifies schedules that maintain database consistency, assuming no transaction fails. Could also examine.
Sekolah Tinggi Ilmu Statistik (STIS) 1 Dr. Said Mirza Pahlevi, M.Eng.
Concurrent Transactions Even when there is no “failure,” several transactions can interact to turn a consistent state into an inconsistent state.
CS 582 / CMPE 481 Distributed Systems Concurrency Control.
Concurrency III (Timestamps). Schedulers A scheduler takes requests from transactions for reads and writes, and decides if it is “OK” to allow them to.
Transaction Management
Alternative Concurrency Control Methods R&G - Chapter 17.
Concurrency Control In Dynamic Database Systems Laurel Jones.
TRANSACTIONS AND CONCURRENCY CONTROL Sadhna Kumari.
Concurrency Control in Distributed Databases. By :- Rishikesh Mandvikar rmandvik[at]engr.smu.edu May 1, 2004.
Optimistic Concurrency Control Lecture Phase Locking Recap Phases – Growth – acquire all locks – Shrinking – release locks as done Strict 2PL –
Concurrency Control Lectured by, Jesmin Akhter, Assistant professor, IIT, JU.
Concurrency Server accesses data on behalf of client – series of operations is a transaction – transactions are atomic Several clients may invoke transactions.
Concurrency Control in Database Operating Systems.
1 Concurrency Control Chapter Conflict Serializable Schedules  Two schedules are conflict equivalent if:  Involve the same actions of the same.
Computer Science Lecture 13, page 1 CS677: Distributed OS Last Class: Canonical Problems Distributed synchronization and mutual exclusion Distributed Transactions.
Computer Science Lecture 13, page 1 CS677: Distributed OS Last Class: Canonical Problems Election algorithms –Bully algorithm –Ring algorithm Distributed.
Transactions and Concurrency Control. Concurrent Accesses to an Object Multiple threads Atomic operations Thread communication Fairness.
7c.1 Silberschatz, Galvin and Gagne ©2003 Operating System Concepts with Java Module 7c: Atomicity Atomic Transactions Log-based Recovery Checkpoints Concurrent.
Page 1 Concurrency Control Paul Krzyzanowski Distributed Systems Except as otherwise noted, the content of this presentation.
Concurrency Control Introduction Lock-Based Protocols
1 Concurrency control lock-base protocols timestamp-based protocols validation-based protocols Ioan Despi.
1 CSE232A: Database System Principles More Concurrency Control and Transaction Processing.
6.830 Lecture 14 Two-phase Locking Recap Optimistic Concurrency Control 10/28/2015.
Timestamp-based Concurrency Control
NOEA/IT - FEN: Databases/Transactions1 Transactions ACID Concurrency Control.
Lecture 9- Concurrency Control (continued) Advanced Databases Masood Niazi Torshiz Islamic Azad University- Mashhad Branch
Database Isolation Levels. Reading Database Isolation Levels, lecture notes by Dr. A. Fekete, resentation/AustralianComputer.
Chap 21 – Concurrency Control. Database Concurrency Control 1 Purpose of Concurrency Control To enforce Isolation (through mutual exclusion) among conflicting.
Computer Science Lecture 13, page 1 CS677: Distributed OS Last Class: Canonical Problems Election algorithms –Bully algorithm –Ring algorithm Distributed.
Transactions Examples
Transaction Management
Last Class: Canonical Problems
Concurrency Control Techniques
Spanner Storage insights
Lecture#23: Concurrency Control – Part 2
Multiple Granularity Granularity is the size of data item  allowed to lock. Multiple Granularity is the hierarchically breaking up the database into portions.
COS 418: Advanced Computer Systems Lecture 5 Michael Freedman
Concurrency Control via Validation
MVCC and Distributed Txns (Spanner)
Concurrency Control II (OCC, MVCC) and Distributed Transactions
Database Concurrency Control
4. Concurrency control techniques
Concurrency Control via Timestamps
CONCURRENCY CONTROL (CHAPTER 16)
Chapter 10 Transaction Management and Concurrency Control
Section 18.8 : Concurrency Control – Timestamps -CS 257, Rahul Dalal - SJSUID: Edited by: Sri Alluri (313)
Concurrency Control Techniques
Database Transactions
Basic Two Phase Locking Protocol
6.830 Lecture 14 Two-phase Locking Recap Optimistic Concurrency Control 10/28/2015.
Distributed Database Management Systems
Atomic Commit and Concurrency Control
Concurrency Control II and Distributed Transactions
Concurrency Control Techniques
Database Management System
Submitted to Dr. Badie Sartawi Submitted by Nizar Handal Course
Concurrency control (OCC and MVCC)
Transactions, Properties of Transactions
Presentation transcript:

Concurrency Control II (OCC, MVCC) COS 418: Distributed Systems Lecture 18 Michael Freedman

Serializability  Execution of a set of transactions over multiple items is equivalent to some serial execution of txns

Lock-based concurrency control Big Global Lock: Results in a serial transaction schedule at the cost of performance Two-phase locking with finer-grain locks: Growing phase when txn acquires locks Shrinking phase when txn releases locks (typically commit) Allows txn to execute concurrently, improvoing performance So that motivates the 2PL algorithm.

Q: What if access patterns rarely, if ever, conflict?

Be optimistic! Goal: Low overhead for non-conflicting txns Assume success! Process transaction as if would succeed Check for serializability only at commit time If fails, abort transaction Optimistic Concurrency Control (OCC) Higher performance when few conflicts vs. locking Lower performance when many conflicts vs. locking

2PL vs OCC From ”Rococo” paper in OSDI 2014. Focus on 2PL vs. OCC. Observe OCC better when write rate lower (fewer conflicts), worse than 2PL with write rate higher (more conflicts)

OCC: Three-phase approach Begin: Record timestamp marking the transaction’s beginning Modify phase: Txn can read values of committed data items Updates only to local copies (versions) of items (in db cache) Validate phase Commit phase If validates, transaction’s updates applied to DB Otherwise, transaction restarted Care must be taken to avoid “TOCTTOU” issues Time to check t Time to use

OCC: Why validation is necessary New txn creates shadow copies of P and Q P and Q’s copies at inconsistent state txn coord O txn coord P When commits txn updates, create new versions at some timestamp t Q

OCC: Validate Phase Transaction is about to commit. System must ensure: Initial consistency: Versions of accessed objects at start consistent No conflicting concurrency: No other txn has committed an operation at object that conflicts with one of this txn’s invocations Consider transaction 1. For all other txns N either committed or in validation phase, one of the following holds: N completes commit before 1 starts modify 1 starts commit after N completes commit, and ReadSet 1 and WriteSet N are disjoint Both ReadSet 1 and WriteSet 1 are disjoint from WriteSet N, and N completes modify phase. When validating 1, first check (A), then (B), then (C). If all fail, validation fails and 1 aborted.

OCC: Validate Phase 1 N N completes commit before 1 starts modify Q P N N completes commit before 1 starts modify Remember that modify includes both read & write. So this just says N finishes before 1 actually starts any read/write  no conflict 1 starts commit after N completes commit, and ReadSet 1 and WriteSet N are disjoint Nothing 1 has recently read depends on what N has written, and 1’s writes will all be serialized after N’s (even though may overwrite N’s values) Both ReadSet 1 and WriteSet 1 are disjoint from WriteSet N, and N completes modify phase. If N has already finished reads (during modify), so it’s reads won’t depend on WriteSet 1, and similarly, 1’s reads don’t depend on N’s writes.

2PL & OCC = strict serialization Provides semantics as if only one transaction was running on DB at time, in serial order + Real-time guarantees 2PL: Pessimistically get all the locks first OCC: Optimistically create copies, but then recheck all read + written items before commit

Multi-version concurrency control Generalize use of multiple versions of objects

Multi-version concurrency control Maintain multiple versions of objects, each with own timestamp. Allocate correct version to reads. Prior example of MVCC:

Multi-version concurrency control Maintain multiple versions of objects, each with own timestamp. Allocate correct version to reads. Unlike 2PL/OCC, reads never rejected Occasionally run garbage collection to clean up

MVCC Intuition Split transaction into read set and write set All reads execute as if one “snapshot” All writes execute as if one later “snapshot” Yields snapshot isolation < serializability

Serializability vs. Snapshot isolation Intuition: Bag of marbles: ½ white, ½ black Transactions: T1: Change all white marbles to black marbles T2: Change all black marbles to white marbles Serializability (2PL, OCC) T1 → T2 or T2 → T1 In either case, bag is either ALL white or ALL black Snapshot isolation (MVCC) T1 → T2 or T2 → T1 or T1 || T2 Bag is ALL white, ALL black, or ½ white ½ black

Timestamps in MVCC Transactions are assigned timestamps, which may get assigned to objects those txns read/write Every object version OV has both read and write TS ReadTS: Largest timestamp of txn that reads OV WriteTS: Timestamp of txn that wrote OV

Executing transaction T in MVCC Find version of object O to read: # Determine the last version written before read snapshot time Find OV s.t. max { WriteTS(OV) | WriteTS(OV) <= TS(T) } ReadTS(OV) = max(TS(T), ReadTS(OV)) Return OV to T Perform write of object O or abort if conflicting: Find OV s.t. max { WriteTS(OV) | WriteTS(OV) <= TS(T) } # Abort if another T’ exists and has read O after T If ReadTS(OV) > TS(T) Abort and roll-back T Else Create new version OW Set ReadTS(OW) = WriteTS(OW) = TS(T)

Digging deeper Notation W(1) = 3: Write creates version 1 with WriteTS = 3 R(1) = 3: Read of version 1 returns timestamp 3 TS = 3 txn txn TS = 4 txn TS = 5 write(O) by TS=3 O

Digging deeper Notation W(1) = 3: Write creates version 1 with WriteTS = 3 R(1) = 3: Read of version 1 returns timestamp 3 TS = 3 txn txn TS = 4 txn TS = 5 W(1) = 3 R(1) = 3 write(O) by TS=5 O

Digging deeper Write O by txn T, find serializable write or abort: Notation W(1) = 3: Write creates version 1 with WriteTS = 3 R(1) = 3: Read of version 1 returns timestamp 3 TS = 3 txn txn TS = 4 txn TS = 5 Write O by txn T, find serializable write or abort: Find OV s.t. max { WriteTS(OV) | WriteTS(OV) <= TS(T) } If ReadTS(OV) > TS(T) Abort and roll-back T Else Create new version OW ReadTS(Ow) = WriteTS(Ow) = TS(T) W(1) = 3 R(1) = 3 W(2) = 5 R(2) = 5 O Find v such that max WriteTS(v) <= (TS = 4) v = 1 has (WriteTS = 3) <= 4 If ReadTS(1) > 4, abort 3 > 4: false Otherwise, write object write(O) by TS = 4

Digging deeper Notation W(1) = 3: Write creates version 1 with WriteTS = 3 R(1) = 3: Read of version 1 returns timestamp 3 TS = 3 txn txn TS = 4 txn TS = 5 W(1) = 3 R(1) = 3 W(3) = 4 R(3) = 4 W(2) = 5 R(2) = 5 O Find v such that max WriteTS(v) <= (TS = 4) v = 1 has (WriteTS = 3) <= 4 If ReadTS(1) > 4, abort 3 > 4: false Otherwise, write object

Digging deeper Read O by txn T, find version to read (never rejected): Notation W(1) = 3: Write creates version 1 with WriteTS = 3 R(1) = 3: Read of version 1 returns timestamp 3 TS = 3 txn txn TS = 4 txn TS = 5 Read O by txn T, find version to read (never rejected): Find OV s.t. max { WriteTS(OV) | WriteTS(OV) <= TS(T) } ReadTS(OV) = max(TS(T), ReadTS(OV)) Return OV to T W(1) = 3 R(1) = 3 R(1) = 5 O BEGIN Transaction tmp = READ(O) WRITE (O, tmp + 1) END Transaction Find v such that max WriteTS(v) <= (TS = 5) v = 1 has (WriteTS = 3) <= 5 Set R(1) = max(5, R(1)) = 5

Digging deeper Read O by txn T, find version to read (never rejected): Notation W(1) = 3: Write creates version 1 with WriteTS = 3 R(1) = 3: Read of version 1 returns timestamp 3 TS = 3 txn txn TS = 4 txn TS = 5 Read O by txn T, find version to read (never rejected): Find OV s.t. max { WriteTS(OV) | WriteTS(OV) <= TS(T) } ReadTS(OV) = max(TS(T), ReadTS(OV)) Return OV to T W(1) = 3 R(1) = 3 W(2) = 5 R(2) = 5 R(1) = 5 O Find v such that max WriteTS(v) <= (TS = 5) v = 1 has (WriteTS = 3) <= 5 If ReadTS(1) > 5, abort 5 > 5: false Otherwise, write object BEGIN Transaction tmp = READ(O) WRITE (O, tmp + 1) END Transaction

Digging deeper Read O by txn T, find version to read (never rejected): Notation W(1) = 3: Write creates version 1 with WriteTS = 3 R(1) = 3: Read of version 1 returns timestamp 3 TS = 3 txn txn TS = 4 txn TS = 5 Read O by txn T, find version to read (never rejected): Find OV s.t. max { WriteTS(OV) | WriteTS(OV) <= TS(T) } ReadTS(OV) = max(TS(T), ReadTS(OV)) Return OV to T W(1) = 3 R(1) = 3 W(2) = 5 R(2) = 5 R(1) = 5 O Find v such that max WriteTS(v) <= (TS = 4) v = 1 has (WriteTS = 3) <= 4 If ReadTS(1) > 4, abort 5 > 4: true write(O) by TS = 4

Digging deeper Read O by txn T, find version to read (never rejected): Notation W(1) = 3: Write creates version 1 with WriteTS = 3 R(1) = 3: Read of version 1 returns timestamp 3 TS = 3 txn txn TS = 4 txn TS = 5 Read O by txn T, find version to read (never rejected): Find OV s.t. max { WriteTS(OV) | WriteTS(OV) <= TS(T) } ReadTS(OV) = max(TS(T), ReadTS(OV)) Return OV to T W(1) = 3 R(1) = 3 W(2) = 5 R(2) = 5 R(1) = 5 R(1) = 5 O Find v such that max WriteTS(v) <= (TS = 4) v = 1 has (WriteTS = 3) <= 4 Set R(1) = max(4, R(1)) = 5 BEGIN Transaction tmp = READ(O) WRITE (P, tmp + 1) END Transaction Then write on P succeeds as well

Distributed Transactions No class Wednesday! 🦃 Monday lecture Distributed Transactions + Google Spanner