Transactions: Definition. Transactional properties of DBS. Transactions: Management in DBS. Transactions: Read/Write Model



Similar documents
Transactional properties of DBS

Lecture 7: Concurrency control. Rasmus Pagh

Course Content. Transactions and Concurrency Control. Objectives of Lecture 4 Transactions and Concurrency Control

Database Tuning and Physical Design: Execution of Transactions

Concurrency Control. Module 6, Lectures 1 and 2

Concurrency Control. Chapter 17. Comp 521 Files and Databases Fall

Concurrency control. Concurrency problems. Database Management System

Roadmap DB Sys. Design & Impl. Detailed Roadmap. Paper. Transactions - dfn. Reminders: Locking and Consistency

Concurrency Control: Locking, Optimistic, Degrees of Consistency

Goals. Managing Multi-User Databases. Database Administration. DBA Tasks. (Kroenke, Chapter 9) Database Administration. Concurrency Control

Comp 5311 Database Management Systems. 16. Review 2 (Physical Level)

Transactions and Concurrency Control. Goals. Database Administration. (Manga Guide to DB, Chapter 5, pg , ) Database Administration

(Pessimistic) Timestamp Ordering. Rules for read and write Operations. Pessimistic Timestamp Ordering. Write Operations and Timestamps

CMSC724: Concurrency

CAP Theorem and Distributed Database Consistency. Syed Akbar Mehdi Lara Schmidt

Textbook and References

Transaction Management Overview

Transactions. SET08104 Database Systems. Napier University

Module 3 (14 hrs) Transactions : Transaction Processing Systems(TPS): Properties (or ACID properties) of Transactions Atomicity Consistency

Database Concurrency Control and Recovery. Simple database model

Introduction to Database Management Systems

In This Lecture. More Concurrency. Deadlocks. Precedence/Wait-For Graphs. Example. Example

CHAPTER 6: DISTRIBUTED FILE SYSTEMS

Transactions and Recovery. Database Systems Lecture 15 Natasha Alechina

High-Performance Concurrency Control Mechanisms for Main-Memory Databases

CS 245 Final Exam Winter 2013

Distributed Databases

Distributed Transactions

Chapter 6 The database Language SQL as a tutorial

Chapter 10. Backup and Recovery

Homework 8. Revision : 2015/04/14 08:13

PostgreSQL Concurrency Issues

Simulations of the implementation of primary copy two-phase locking in distributed database systems

Database Management System Prof. D. Janakiram Department of Computer Science & Engineering Indian Institute of Technology, Madras Lecture No.

Ph.D. Thesis Proposal Database Replication in Wide Area Networks

Unit 12 Database Recovery

Transactions and the Internet

Brewer s Conjecture and the Feasibility of Consistent, Available, Partition-Tolerant Web Services

Datenbanksysteme II: Implementation of Database Systems Recovery Undo / Redo

Recovery Theory. Storage Types. Failure Types. Theory of Recovery. Volatile storage main memory, which does not survive crashes.

Chapter 7: Deadlocks!

Information Systems. Computer Science Department ETH Zurich Spring 2012

A Proposal for a Multi-Master Synchronous Replication System

Transaction Processing Monitors

COS 318: Operating Systems

Serializability, not Serial: Concurrency Control and Availability in Multi Datacenter Datastores

Database Replication with Oracle 11g and MS SQL Server 2008

Transactional Support for SDN Control Planes "

Redo Recovery after System Crashes

OPERATING SYSTEMS DEADLOCKS

Data Management in the Cloud

Cloud DBMS: An Overview. Shan-Hung Wu, NetDB CS, NTHU Spring, 2015

Generalized Isolation Level Definitions

READPAST & Furious: Transactions, Locking and Isolation

! Volatile storage: ! Nonvolatile storage:

The first time through running an Ad Hoc query or Stored Procedure, SQL Server will go through each of the following steps.

Review: The ACID properties

The CAP theorem and the design of large scale distributed systems: Part I

Outline. Failure Types

The ConTract Model. Helmut Wächter, Andreas Reuter. November 9, 1999

Elena Baralis, Silvia Chiusano Politecnico di Torino. Pag. 1. Active database systems. Triggers. Triggers. Active database systems.

INTRODUCTION TO DATABASE SYSTEMS

Scalable Transaction Management on Cloud Data Management Systems

TRANSACÇÕES. PARTE I (Extraído de SQL Server Books Online )

Database Replication with MySQL and PostgreSQL

Chapter 14: Recovery System

VALLIAMMAI ENGNIEERING COLLEGE SRM Nagar, Kattankulathur

Optimizing Concurrent Processing of Write-then-Read Transactions

1.264 Lecture 15. SQL transactions, security, indexes

b. Examine the following histories. Draw their serialization graph and identify which of them is serializable given reasons.

Hagit Attiya and Eshcar Hillel. Computer Science Department Technion

Serializable Isolation for Snapshot Databases

Chapter 16: Recovery System

System model. Section 7.1. Operating Systems: Deadlock p. 1/15

Lecture 18: Reliable Storage

Introduction to Distributed Systems

F1: A Distributed SQL Database That Scales. Presentation by: Alex Degtiar (adegtiar@cmu.edu) /21/2013

Postgres-R(SI): Combining Replica Control with Concurrency Control based on Snapshot Isolation

SanDisk ION Accelerator High Availability

Recovery: An Intro to ARIES Based on SKS 17. Instructor: Randal Burns Lecture for April 1, 2002 Computer Science Johns Hopkins University

Applying Attribute Level Locking to Decrease the Deadlock on Distributed Database

Chapter 15: Recovery System

Sequential lmove Games. Using Backward Induction (Rollback) to Find Equilibrium

Java DB Performance. Olav Sandstå Sun Microsystems, Trondheim, Norway Submission ID: 860

Factorization in Polynomial Rings

Entangled Transactions. Nitin Gupta, Milos Nikolic, Sudip Roy, Gabriel Bender, Lucja Kot, Johannes Gehrke, Christoph Koch

Topics. Distributed Databases. Desirable Properties. Introduction. Distributed DBMS Architectures. Types of Distributed Databases

W I S E. SQL Server 2008/2008 R2 Advanced DBA Performance & WISE LTD.

How To Recover From Failure In A Relational Database System

Data Structures Fibonacci Heaps, Amortized Analysis

Transcription:

Transactions: Definition Transactional properties of DBS Transaction Concepts Concurrency control Recovery Important concept Transaction (TA) Unit of work consisting of a sequence of operations Transaction principles (ACID): Atomicity: the sequence of operations is executed completely or has no effect on the database Consistency: if the database was in a consistent state before transaction execution it will be after Isolation: concurrently executed transactions do not interfere Durability: (persistency) all effects of a TA are permanent 12.2 Transactions: Read/Write Model Transactions: Management in DBS Atomic DBoperations READ[x] TA reads object x WRITE[y] TA writes object x Transaction: sequence of reads and writes Transaction control Begin of transaction (BOT) often implicitly Commit: successful end of transaction Abort: unsuccessful end of transaction Insert a new tape for the movie Psycho (Hitchcock) Read movieid, read and write sequence, insert tapetuple TA i = r i [m], r i [s], w i [s], w i [t], c i 12.3 Concurrency Situation: Multiuser access to database Challenge: Find a correct execution sequence of the atomic operations of multiple transactions Ensures isolation Recovery Situation: Failing transactions Challenge: Recover a consistent database state Ensures atomicity Ensures persistency 12.4 Concurrent transactions: Problems Concurrent transactions: Schedule Potential problems during interleaved execution Lost update: same object concurrently updated by two transactions, one update lost r 1 [x], r 2 [x], w 1 [x], w 2 [x], c 2, c 1 Dirty read: reading of object value changed by (later) aborted transaction r 1 [x], w 1 [x], r 2 [x], w 2 [x], c 2, a 1 Nonrepeatable read: different result when reading the same object more than once in a transaction r 1 [x], w 1 [x], r 2 [x], w 1 [x], r 2 [x], w 2 [x], c 2, c 1 Phantoms: nonrepeatable read caused by insertions or deletions 12.5 Schedule (History) Informally: interleaved sequence of atomic actions of two or more transactions A schedule S of a (finite) set of transactions T is a sequence of atomic actions a i with partial ordering < S if: Each atomic action of each TA T occurs exactly once in S No other action occurs in S If a i < S a j in some TA, then a i < S a j in S 12.6 1

Concurrent transactions: Schedule TA 1 = r1[x], r1[y], w1[y], r1[z], w1[x], c1 TA 2 = r2[y], r2[z], w2[y], r2[x], w2[x], r2[s], c2 Schedule: r1[x], r2[y], r2[z], w2[y], r2[x], r1[y], w2[x], w1[y], r1[z], r2[s], c2, w1[x], c1 No schedule: r1[x], r2[y], r1[y], w2[y], w1[y], r1[z], r2[z], r2[x], w2[x], c2, w1[x], c1 12.7 Serial schedule The execution of the TAs one after the other, in an arbitrary order, is called a serial execution TA 1 = r1[x], r1[y], w1[y], r1[z], w1[x], c1 TA 2 = r2[y], r2[z], w2[y], r2[x], w2[x], r2[s], c2 T1 then T2: r1[x], r1[y], w1[y], r1[z], w1[x], c1, r2[y], r2[z], w2[y],r2[x], w2[x], r2[s], c2 T2 then T1 : r2[y], r2[z], w2[y], r2[x], w2[x], r2[s], c2, r1[x], r1[y], w1[y], r1[z], w1[x], c1 12.8 Correctness criterion for schedules: Serializability A schedule S of a transaction set T is called serializable, if it is equivalent to a serial execution of T Serializable schedules are defined as correct Equivalence of schedules 1. Resultequivalence: Equivalent if same result on database not really useful, used in some books 2. Conflictequivalence: Equivalent if same same order of conflict operations typically applied 12.9 Conflicts: Lost update, dirty read, nonrepeatable read, phantoms Only if different transactions operate on the same object and at least one is a write operation Possible conflicts between two TAs No conflict: r1[x], r2[x] Possible: r1[x], w2[x] Possible: w1[x], r2[x] Possible: w1[x], w2[x] Conflict pairs: Pairs of conflicting operations in different TAs on the same data object Example: r1[x], r2[y], w1[x], w1[y], w2[y], c1, c2 12.10 Conflicting operations op i [x] and op j [y] are in conflict, if x = y i!= j op = w or op = w Conflict relation Ordered conflict relation C of a schedule S: C(S) = {(op, op ) op and op conflicting operations, op < S op in S} Example: C(S) = {(r2[y], w1[y]), (w1[y], w2[y])} 12.11 Conflictserializable schedules Same conflict pairs as some serial schedule Same order of conflict pairs as in some serial schedule A Schedule S of a transaction set T is conflictserializable if it has the same conflict relation as some serial execution SER of T: C(S) = C(SER) S: r1[x], r2[x], r1[y], r2[z], w2[y], w2[x], c2, c1 C(S): {(r1[x], w2[x]), (r1[y], w2[y])} SER: r1[x], r1[y], c1, r2[x], r2[z], w2[y], w2[x], c2, 12.12 2

Example S: r 1 [x], r 2 [x], r 1 [y], r 2 [z], w 2 [y], w 2 [x], w 1 [y], r 1 [z], c 2, w 1 [x], c 1 C(S) = { (r1[x], w2[x]), (r2[x], w1[x]), (r1[y], w2[y] ), (w2[y], w1[y]), (w2[x], w1[x]) } Not conflictserializable Requires T1 before T2 in a serial schedule Requires T2 before T1 in a serial schedule 12.13 Conflict Graph (Precedence or dependency graph) Directed graph Shows conflicts between transactions Nodes: transactions of S Arc TA i TA j : conflicting pair (op i [x], op j [x] ) C(S) = { (r1[x], w2[x]), (r2[x], w1[x]), (r1[y], w2[y] ), (w2[y], w1[y]), (w2[x], w1[x]) } T1 x,y x,y T2 12.14 Concurrent transactions: Serializability Theorem Serializability Theorem: A schedule S is conflict serializable, if and only if its conflict graph does not contain a cycle S: r1[y], r3[u], r2[u], w1[y], w2[x], w1[x], w2[z], w3[x], c1, c2, c3 C(S): {(w2[x], w1[x]), (w2[x], w3[x]), (w1[x], w3[x])} SER: r2[u], w2[x], w2[z], c2, r1[y], w1[y], w1[x], c1, r3[u], w3[x], c3 T1 T3 Serializable T2 12.15 Intuitive correctness idea: Determine "conflictequivalent serial schedule from graph Exchange operations in S without switching conflict pairs Proof: " " The nodes of a connected directed graph without cycles can be sorted topologically: a < S b iff there is a path from a to b in the graph. Results in a serial schedule if nonconflicting TAs are added arbitrarily. " " Suppose there is a cycle TA i TA j in the graph. Then there are conflicting pairs (p i,q j ) and (q j ',p i '), No serial schedule will contain both (p i,q j ) and (q j ',p i '). Induction over length of cycle proves the "only if". 12.16 Concurrent transactions: Scheduling Conflict serializability sometimes too restrictive S: w1[y], w2[x], r2[y], w2[y], w1[x], w3[x], c1, c2, c3 C(S1) = {(w1[y],r2[y]), (w1[y],w2[y]), (w2[x], w1[x]), (w2[x],w3[x]), (w1[x], w3[x])} But effect of S is the same as from the serial Schedule: T1, T2, T3! T1 T3 T2 12.17 Serializability Theoretical model which defines correctness of executions Often not implemented No realtime scheduling control Goal: effective realtime scheduling of operations with guaranteed serializability of resulting execution sequence TA 1 TA n Transaction manager Controls transactions Scheduler Controls execution of DB calls 12.18 3

Concurrent transactions: Scheduling Concurrency control: Locking Concurrency control in DBS methods which schedule the operations of different TAs in a way which guarantees serializability Principle concurrency control methods Locking (most important) Optimistic concurrency control Time stamps Transactions not known in advance 12.19 Locking: Access on data only if TA has lock on data Transactions request and release locks Scheduler allows or defers operations based on lock table Implicit locking by scheduler Explicit locking in application programs error prone additionally allowed for in most DBS Not considered here: transaction independent locking, e.g. page lock while writing 12.20 Concurrency control: Locking Concurrency control: Lock Protocols Locking is pessimistic: Assumption: during operation op[x] of a (potentially) conflicting operation op'[x] of will access object x Avoid by locking x before accessing x Lock protocols Simplistic Preclaiming Two Phase Locking (2PL) Strict 2PL 12.21 Simplistic Lock each object before writing Unlock afterwards schedule will not be serializable T1: r1[x], w1[x], c1 T2: r2[x], w2[x], c2 lock1(x), r1[x], unlock1(x), lock2(x), r2[x], unlock2(x), lock1(x), w1[x], unlock1(x), lock2(x), w2[x], unlock2(x) 12.22 Concurrency control: Lock Protocols Concurrency control: Lock Protocols 2PL Preclaiming Acquire all locks TA needs before performing an operation Release locks if TAs does not get all try again Execute transaction Release locks Lock acquisition phase # locks Begin TA End TA Problems: Racing situation Objects to access may not be known in advance Not used in DBS Work phase time 12.23 Two phase locking (2PL) 1. Lock each object accessed by TA before usage 2. Respect existing locks of other TAs 3. No TA requests lock which it already holds: if T holds a read lock for x, it will not request a write lock for x 4. No lock after unlock: No lock is requested by a TA, after a lock has been released by same TA 5. Locks are released at least at commit time # locks Begin TA Lock acquisition phase Release phase time End TA Important method 12.24 4

Concurrency control: Lock Protocols 2PL Concurrency control: Lock Protocols 2PL Locked objects accessible in lock acquisition phase Rule 3 is essential (see "select... for update") Example: Example: rlock1(x), r1[x], x=x*10, rlock2(x), r2[x], x:=x1, wlock1(x), w1[x], unlock1(x), wlock2(x), w2[x], unlock2(x) Lock after unlock may result in a lost update Rule 4 is essential lock1(x), r1[x], x=x*10, unlock1(x), lock2(x), r2[x], x:=x1, w2[x], unlock2(x), lock1(x), w1(x), unlock1(x) 12.25 2Phase locking theorem If all transactions follow the 2phase locking protocol, the resulting schedule is serializable Proof sketch: Suppose a resulting schedule is not serializable after 2PL conflict graph contains a cycle TA 1 and TA 2 with conflict pairs (p 1,q 2 ) and (q 2 ', p 1 ') p 1,q 2 access the same object x, and q 2 ', p 2 ' an object y (assuming a cycle of length 1, induction for the general case) Let e.g. (p 1,q 2 ) = (r1[x], w2[x]), (q 1 ', p 2 ') = (w2[y], w1[y]) Analyze all possible sequences of execution 12.26 Concurrency control: Lock Protocols 2PL Concurrency control: Lock Protocols 2PL Proof sketch (continued) Analyze <p 1, q 2, q 2 ', p 1 > Analyze <p 1, q 2 ', q 2, p 1 > Analyze <q 2 ', p 1, p 1 ', q 2 > Analyze <q 2 ', p 1 ', p 1, q 2 > Analyze <q 2 ', p 1, q 2, p 1 > T2: Lock y, T1: Lock x, T2: Lock x, T1: Lock y T1 must have released lock on x and acquired one on y (or T2 must have acquired after release) Hurts 2phase rule! Contradiction to assumption. Similar argumentation for the other possible sequences Theorem 12.27 Serializability does not imply 2PL serializable schedule not resulting from a 2PL scheduler Cascading abort: Possible access of to object x which was unlocked by in release phase if aborts, used wrong state of x to be aborted by the system # locks Begin TA Release phase abort time May happen recursively: cascading abort 12.28 Concurrency control: Lock Protocols S2PL Concurrency control: Lock Protocol S2PL Strict 2phase locking Prevents cascading abort Release all locks at commit point # locks Begin TA Lock acquisition phase Release all locks at commit End TA time 12.29 S: r1[x], r2[y], w1[x], w1[y], w2[y], c1, c2 Lock(x) Lock(y)? Lock(y) w[y] c1 Unlock(x) Unlock(y) Lock(y) w[y] c2 Unlock(y) 12.30 5

Concurrency control: Lock Protocol Concurrency control: Lock Modes Deadlock situation Transactions each ing for locks the other one holds S: w1[x], r2[y], r1[y], r2[x], c1, c2 Lock(x) Lock(y)? Lock(y) Lock(x)? Inherent to lockbased scheduling 12.31 Shared and exclusive locks For each object x either one exclusive lock or many shared locks Read lock: shared lock holder Write lock: exclusive lock S X requester Read locks allow for read locks Exclusive lock prevents additional locks S X 12.32 Concurrency control: Lock Modes Concurrency control: Lock Modes S: w1[x], r2[y], r1[y], r2[x], c1, c2 Shared and exclusive locks may prevent deadlocks XLock(x) SLock(y) c1 Unlock(x) Unlock(y) SLock(y) SLock(x)? SLock(x) c2 Unlock(y) Unlock(x) 12.33 Upgradeable locks Often first read of object then write Upgrade not allowed: abort transaction If upgrade allowed: deadlock S: r1[x], r2[x], w1[x], w2[x], c1, c2 SLock(x) XLock(x)? SLock(x) XLock(x)? 12.34 Concurrency control: Lock Modes Concurrency control: Lock Modes Update locks Update lock: shared lock for reading, allows for upgrading Read lock: shared lock holder Write lock: exclusive lock S U X Read locks allow for read or update lock Update lock or exclusive lock prevent additional locks Asymmetric: Update lock acts as shared lock when requested, as exclusive lock when used Update lock is promoted to exclusive lock as soon as no other shared locks exist on the page or row 12.35 requester S U X S: r1[x], r2[x], w1[x], w2[x], c1, c2 Update locks may prevent abort or deadlock Operations not always known in advance ULock(x) XLock(x) c1 Unlock(x) ULock(x)? ULock(x) XLock(x) c2 Unlock(x) 12.36 6

Concurrency control: Lock Modes Concurrency control: Locking granularity Increment locks Useful for TAs incrementing or decrementing stored values Examples: Money transfer, ticket selling, Commutative increment actions Noncommutative to read or write Equivalent schedules: S: r1[x], r2[x], inc2[y], inc1[y], c1, c2 S: r1[x], inc1[y], r2[x], inc2[y], c1, c2 S: r1[x], r2[x], inc1[y], inc2[y], c1, c2 requester S X I holder S X I 12.37 Single lock granularity insufficient Overhead: many record locks vs. one table lock Phantoms: not prevented by record locks Granularities: Tuple, page, block, relation, At least two lock granularities in most DBS Problem: TA requests lock on table R Some rows of R locked by different TAs Lock conflict: TA ing for release of all record locks Danger of starvation of TA 12.38 Concurrency control: Hierarchical locking Concurrency control: Hierarchical locking Object hierarchy: Record Block B1 Record Relation R1 Intention locks Intention to request lock For each lock mode: e.g., IS and IX Block B2... Locking: Start at root of hierarchy Before right element place intention locks At the right element in hierarchy request lock 12.39 Lock situation: IS, IX signal locks deeper in hierarchy Element locks lock all subordinate elements in hierarchy Goal: Lock on block B1 Warning on upper elements (Intention lock on relation R) Locks on block and records in B1 lock Record lock lock Block B1 Record! Relation R1 Block B2... 12.40 Concurrency control: Hierarchical locking Concurrency control: Deadlocks Advantage: one lookup to check if lock on higher level can be granted Compatibility of locks: Exclusive lock not compatible Intended exclusive only compatible to intention locks requester holder IS IX IS IX S X Lock escalation Convert many locks on level i into one lock on level i1 Only for locks by single TA Efficiency reasons (large locktables) S X 12.41 Lock conflict TA s for lock held by other TA Conflict solved when TA finished and lock released Deadlocks inherent to 2PL Deadlock: at least two pairing conflicts Releasing lock would break Rule 4 Keeping lock would lead to deadlock Resolving deadlocks Cycle check in Waitsforgraph Timeout 12.42 7

Concurrency control: Deadlocks Concurrency control: Deadlocks Waitsforgraph TAi Directed graph Shows TAs ing for locks held by other TAs Nodes: transactions of S Arc TA i TA j : TA i s for lock held by TA j Cycles indicate deadlocks Deadlock prevention: Refuse actions that cause cycles Rollback of the requesting TA Expensive method (maintain graph at all times ) TAj 12.43 S: w1[x], r2[y], r1[y], r2[x], c1, c2 Lock(x) Lock(y)? continues Lock(y) Lock(x)? abort Waitsforgraph: Lock(y)? Lock(x)? 12.44 Concurrency control: Deadlock resolving Concurrency control: Deadlock resolving Deadlock resolving with sforgraph Less expensive One of the ing transactions rolled back TA selection for rollback Minimize costs: rollback of youngest TA, rollback TA with minimal #locks Maximize free resources: rollback TA with maximal #locks Avoid starvation: avoid rollback of same TA more than x times (employ counter) Minimize cycles: rollback TA involved in maximal #cycles 12.45 Deadlock resolving with timeout TAs have initial timestamps TA s for lock Abort TA after ing longer than time limit t Simple and efficient technique May roll back TAs without deadlock TA selection for rollback Wait/Die method Wound/Wait method Initial timestamp ts() for each TA 12.46 Concurrency control: Deadlock resolving Concurrency control: Deadlock resolving Wait/Die method requests lock held by If older than [ ts() < ts() ] s If younger than [ ts() > ts() ] dies ( aborted) abort 12.47 Wound/Wait method requests lock held by If older than [ ts() < ts() ] wounds T2 ( aborted) If younger than [ ts() > ts() ] s abort 12.48 8

Concurrency control: Optimistic Concurrency control: Optimistic Optimistic concurrency control Locks are expensive, Conflict solving hopefully is cheaper Several types (backward, forward, ) Backward oriented concurrency control (BOCC) Idea: TAs work on copies, check for conflicts at the end, commit (or abort) BOT Read phase: Copy data to private workspace Execute operations on copy Validation phase: resolve conflicts EOT Commit phase: write data into DB 12.49 BOCC Implementation ReadSet R(TA) = data set read by TA in read phase WriteSet W(TA) = data set changed during read phase Assumption: W(T) R(T) TA3 w[z] Commit or rollback of T2? EOT w[y] EOT x,y R(T2) z W(T1) x,y W(T3) 12.50 Concurrency control: Optimistic Concurrency control: Optimistic BOCC Validation for TA: for all transactions (TA') which committed after BOT(T) : if R(TA) W(TA') = then T.commit else T.abort TA3 w[z] EOT w[y] EOT R(T2) W(T3) abort x,y R(T2) z W(T1) x,y W(T3) 12.51 Could result in unnecessary aborts Fast and atomic commit processing Fast validation Only one TA can validate at a time Useful in situation with few expected conflicts 12.52 Concurrency control: Timestamps Concurrency control: Timestamps Optimistic concurrency control based on timestamps Each TA timestamp assigned Idea: record timestamps of TA last access on element, compare order of timestamps with transaction schedule For each database element x RT(x): timestamp of youngest TA that read x WT(x): timestamp of youngest TA that wrote x C(x): commit bit, true if lastwriting TA has committed Goal: synchronize TAs such that resulting schedule is equivalent to serial schedule according to timestamp order 12.53 Scheduler actions Grant request Abort TA, restart TA with new timestamp Delay TA Scheduling TA for reading: If ts(ta) < WT(x): abort TA If ts(ta) >= WT(x): read and RT(x):= max(ts(ta), RT(x)) Scheduling TA for writing: If ts(ta) < RT(x): abort TA If ts(ta) < WT(x): abort TA Else: write and WT(x):= ts(ta) and RT(x):= ts(ta) 12.54 9

Concurrency control: Timestamps Concurrency control: Multiversion timestamps Access on object x delayed until TA committed Timestamp method: resulting schedule equivalent serial schedule in timestamp order Older TAs aborted and restarted Younger TAs succeed 2PL: resulting schedule equivalent serial schedule in commit order Requesting TAs have to until commit of other TAs 12.55 Allows reads that would otherwise cause aborts Hold multiple versions of an object The latest consistent version (in DB) The updated, but not committed version (as copy) TA3 access would have to abort since ts() < WT(x)=ts(TA3) Multiversion: give access to copy of older state 12.56 Concurrency control: Deadlock resolving Transactions and Concurrency: Short summary Oracle: Variant of Multiversioning Table and row level locks Deadlock detection: sforgraph in central systems Deadlock detection: Timeout in distributed environment (cycles hard to detect) User influence: lock modes MySQL: Multiversioning and twophase locking Table and row level locks Deadlock detection: sfor graph Spaceefficient lock table: lock escalation not needed User influence: set priority of statement types 12.57 ACID properties of transactions Schedules: Serial, (conflict) serializable Correctness of schedules: Serializability theorem Locking: Preclaiming, 2PL, strict 2PL, lock modes Optimistic concurrency control Timestampmethods Serializability Cascading rollback Deadlocks Detection (Waitsforgraph) Avoidance (Waitsforgraph, Wait/Die, Wound/Wait) 12.58 10