UCDavis, ecs251 Spring 2007 04/17/2007Transactions1 Operating System Models ecs251 Spring 2007: Operating System Models #2: Transactions Dr. S. Felix.

Slides:



Advertisements
Similar presentations
Concurrency Control III. General Overview Relational model - SQL Formal & commercial query languages Functional Dependencies Normalization Physical Design.
Advertisements

Optimistic Methods for Concurrency Control By : H.T. Kung & John T. Robinson Presenters: Munawer Saeed.
1 Concurrency Control Chapter Conflict Serializable Schedules  Two actions are in conflict if  they operate on the same DB item,  they belong.
CS 542: Topics in Distributed Systems Transactions and Concurrency Control.
University of Tampere, CS Department Distributed Transaction Management Jyrki Nummenmaa
Transaction Management: Concurrency Control CS634 Class 17, Apr 7, 2014 Slides based on “Database Management Systems” 3 rd ed, Ramakrishnan and Gehrke.
Principles of Transaction Management. Outline Transaction concepts & protocols Performance impact of concurrency control Performance tuning.
Concurrency Control II
Topic 6.3: Transactions and Concurrency Control Hari Uday.
CS6223: Distributed Systems
Lock-Based Concurrency Control
1 Chapter 3. Synchronization. STEMPusan National University STEM-PNU 2 Synchronization in Distributed Systems Synchronization in a single machine Same.
1 TRANSACTION & CONCURRENCY CONTROL Huỳnh Văn Quốc Phương Thái Thị Thu Thủy
Transactions and concurrency control
Quick Review of Apr 29 material
CMPT Dr. Alexandra Fedorova Lecture X: Transactions.
Concurrency Control and Recovery In real life: users access the database concurrently, and systems crash. Concurrent access to the database also improves.
Distributed Systems 2006 Styles of Client/Server Computing.
Distributed Systems Fall 2010 Transactions and concurrency control.
Computer Science Lecture 12, page 1 CS677: Distributed OS Last Class Distributed Snapshots –Termination detection Election algorithms –Bully –Ring.
14/06/2015Distribuerede Systemer1 Concurrency Control Thomas Hildebrandt.
CS 582 / CMPE 481 Distributed Systems Concurrency Control.
Transaction Management and Concurrency Control
Transaction Management
Concurrency Control John Ortiz.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
System Catalogue v Stores data that describes each database v meta-data: – conceptual, logical, physical schema – mapping between schemata – info for query.
Concurrency Control In Dynamic Database Systems Laurel Jones.
Transactions and concurrency control
TRANSACTIONS AND CONCURRENCY CONTROL Sadhna Kumari.
Distributed Deadlocks and Transaction Recovery.
CIS 720 Concurrency Control. Locking Atomic statement –Can be used to perform two or more updates atomically Th1: …. ;……. Th2:…………. ;…….
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 10 Transaction Management.
Database Systems/COMP4910/Spring05/Melikyan1 Transaction Management Overview Unit 2 Chapter 16.
1 Transaction Management Overview Chapter Transactions  Concurrent execution of user programs is essential for good DBMS performance.  Because.
1 Mutual Exclusion: A Centralized Algorithm a)Process 1 asks the coordinator for permission to enter a critical region. Permission is granted b)Process.
Transactions CPSC 356 Database Ellen Walker Hiram College (Includes figures from Database Systems by Connolly & Begg, © Addison Wesley 2002)
Concurrency Server accesses data on behalf of client – series of operations is a transaction – transactions are atomic Several clients may invoke transactions.
Concurrency Control Concurrency Control By Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany) DIRECTOR ARUNAI ENGINEERING COLLEGE TIRUVANNAMALAI.
1 Transactions Chapter Transactions A transaction is: a logical unit of work a sequence of steps to accomplish a single task Can have multiple.
Computer Science Lecture 13, page 1 CS677: Distributed OS Last Class: Canonical Problems Election algorithms –Bully algorithm –Ring algorithm Distributed.
A Survey on Optimistic Concurrency Control CAI Yibo ZHENG Xin
Optimistic Methods for Concurrency Control By: H.T. Kung and John Robinson Presented by: Frederick Ramirez.
Distributed Processing Systems ( Concurrency Control ) 오 상 규 서강대학교 정보통신 대학원
Transactions and Concurrency Control. Concurrent Accesses to an Object Multiple threads Atomic operations Thread communication Fairness.
1 Concurrency control lock-base protocols timestamp-based protocols validation-based protocols Ioan Despi.
IM NTU Distributed Information Systems 2004 Distributed Transactions -- 1 Distributed Transactions Yih-Kuen Tsay Dept. of Information Management National.
Slides for Chapter 12: Transactions and Concurrency Control From Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edition 3,
6.830 Lecture 14 Two-phase Locking Recap Optimistic Concurrency Control 10/28/2015.
9 1 Chapter 9_B Concurrency Control Database Systems: Design, Implementation, and Management, Rob and Coronel.
NOEA/IT - FEN: Databases/Transactions1 Transactions ACID Concurrency Control.
Multidatabase Transaction Management COP5711. Multidatabase Transaction Management Outline Review - Transaction Processing Multidatabase Transaction Management.
Lecture 9- Concurrency Control (continued) Advanced Databases Masood Niazi Torshiz Islamic Azad University- Mashhad Branch
10 1 Chapter 10_B Concurrency Control Database Systems: Design, Implementation, and Management, Rob and Coronel.
Database Isolation Levels. Reading Database Isolation Levels, lecture notes by Dr. A. Fekete, resentation/AustralianComputer.
Computer Science Lecture 13, page 1 CS677: Distributed OS Last Class: Canonical Problems Election algorithms –Bully algorithm –Ring algorithm Distributed.
Distributed Transactions What is a transaction? (A sequence of server operations that must be carried out atomically ) ACID properties - what are these.
Concurrency Control Techniques
Transaction Management and Concurrency Control
Concurrency Control II (OCC, MVCC)
Chapter 10 Transaction Management and Concurrency Control
Section 18.8 : Concurrency Control – Timestamps -CS 257, Rahul Dalal - SJSUID: Edited by: Sri Alluri (313)
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
Introduction of Week 13 Return assignment 11-1 and 3-1-5
Distributed Transactions
Transaction Management
Concurrency control (OCC and MVCC)
Presentation transcript:

UCDavis, ecs251 Spring /17/2007Transactions1 Operating System Models ecs251 Spring 2007: Operating System Models #2: Transactions Dr. S. Felix Wu Computer Science Department University of California, Davis

UCDavis, ecs251 Spring /17/2007Transactions2 Transaction l A sequence/program of operations {read, write} on a set of “shared” variables

UCDavis, ecs251 Spring /17/2007Transactions3 A Transaction System l A set of transactions being executed and sharing a set variables. l A lot of uncontrollability: –Failures of everything and any time –Distributed nature –Unpredictable scheduling –Dynamics about transactions themselves l Program changes, Self aborting, Birth,…

UCDavis, ecs251 Spring /17/2007Transactions4 Applications of Transactions l Database/Information System l Distributed Mobile computing l Distributed File System l Fault Tolerant computing

UCDavis, ecs251 Spring /17/2007Transactions5 Transaction Properties: ACID l Atomicity (all or nothing) l Consistency (consistent state transition) l Isolation (intermediate results) l Durability (persistent)

UCDavis, ecs251 Spring /17/2007Transactions6 Transaction Properties: ACID l Atomicity (all or nothing) l Consistency (consistent state transition) l Isolation (intermediate results) l Durability (persistent) l Let’s not worry about the details for now…

UCDavis, ecs251 Spring /17/2007Transactions7 (a) R(X) W(X) R(Y) W(Y) (b) R(Z) R(Y) W(Y) R(X) W(X) (c) R(Y) R(Z) W(Y) W(Z) Three Transactions: a,b, and c Assuming we have only one copy of X, Y, & Z R t (O): Transaction t READ object O W t (O): Transaction t WRITE object O

UCDavis, ecs251 Spring /17/2007Transactions8 R(X) W(X) R(Y) W(Y) R(Z) R(Y) W(Y) R(X) W(X) R(Y) R(Z) W(Y) W(Z) Transaction Execution History time

UCDavis, ecs251 Spring /17/2007Transactions9 R(X) W(X) R(Y) W(Y) R(Z) R(Y) W(Y) R(X) W(X) R(Y) R(Z) W(Y) W(Z) Transaction Execution History time T b >> T c >> T a or “bca”

UCDavis, ecs251 Spring /17/2007Transactions10 R(X) W(X) R(Y) W(Y) R(Z) R(Y) W(Y) R(X) W(X) R(Y) R(Z) W(Y) W(Z) Transaction Execution History time

UCDavis, ecs251 Spring /17/2007Transactions11 R(X) W(X) R(Y) W(Y) R(Z) R(Y) W(Y) R(X) W(X) R(Y) R(Z) W(Y) W(Z) Does this schedule look OK? time

UCDavis, ecs251 Spring /17/2007Transactions12 R(X) W(X) R(Y) W(Y) R(Z) R(Y) W(Y) R(X) W(X) R(Y) R(Z) W(Y) W(Z) Y only: abc, acb, bac, bca, cab, cba ?? time abc Y Y Y

UCDavis, ecs251 Spring /17/2007Transactions13 R(X) W(X) R(Y) W(Y) R(Z) R(Y) W(Y) R(X) W(X) R(Y) R(Z) W(Y) W(Z) X only: abc, acb, bac, bca, cab, cba ?? time abc

UCDavis, ecs251 Spring /17/2007Transactions14 R(X) W(X) R(Y) W(Y) R(Z) R(Y) W(Y) R(X) W(X) R(Y) R(Z) W(Y) W(Z) Z only: abc, acb, bac, bca, cab, cba ?? time abc

UCDavis, ecs251 Spring /17/2007Transactions15 R(X) W(X) R(Y) W(Y) R(Z) R(Y) W(Y) R(X) W(X) R(Y) R(Z) W(Y) W(Z) Transaction Execution History time abc Y Y Y,Z X

UCDavis, ecs251 Spring /17/2007Transactions16 Operations in Coordinator interface BeginTransaction() -> trans; starts a new transaction and delivers a unique TID trans. This identifier will be used in the other operations in the transaction. EndTransaction(trans) -> (commit, abort); ends a transaction: a commit return value indicates that the transaction has committed; an abort return value indicates that it has aborted. AbortTransaction(trans); aborts the transaction.

UCDavis, ecs251 Spring /17/2007Transactions17 The Transaction Model PrimitiveDescription BEGIN_TRANSACTIONMake the start of a transaction END_TRANSACTIONTerminate the transaction and try to commit ABORT_TRANSACTIONKill the transaction and restore the old values READRead data from a file, a table, or otherwise WRITEWrite data to a file, a table, or otherwise

UCDavis, ecs251 Spring /17/2007Transactions18 Transaction Execution Histories SuccessfulAborted by clientAborted by server BeginTransaction operation server aborts transaction operation operation ERROR reported to client EndTransactionAbortTransaction

UCDavis, ecs251 Spring /17/2007Transactions19 Serial equivalence l if each one of a set of transactions has the correct effect when done on its own alone, then if they are done one at a time in some order the effect will be correct l a serially equivalent interleaving is one in which the combined effect is the same as if the transactions had been done one at a time in some order –abc, acb, bac, bca, cab, or cba l the same effect means –the read operations return the same values (to one order) –the instance variables of the objects have the same values at the end (of each transaction).

UCDavis, ecs251 Spring /17/2007Transactions20Serializability BEGIN_TRANSACTION read X; read Y; write Y END_TRANSACTION (a) BEGIN_TRANSACTION read X; read Z; write Z; END_TRANSACTION (b) BEGIN_TRANSACTION read Y; read Z; read X; END_TRANSACTION (c) Illegalr[X]a, r[X]b, r[Z]b, r[Y]a, r[Y]c, w[Z]b, w[Y]a, r[Z]c, r[X]cSchedule 3 Legalr[X]a, r[X]b, r[Z]b, r[Y]a, w[Z]b, w[Y]a, r[Y]c, r[Z]c, r[X]cSchedule 2 Legalr[X]a, r[Y]a, w[Y]a, r[X]b, r[Z]b, w[Z]b, r[Y]c, r[Z]c, r[X]cSchedule 1 r[X]a, r[X]b, r[Z]b, r[Y]a, r[Y]c, r[Z]c, w[Z]b, r[X]c, w[Y]a r[X]a, r[X]b, r[Z]b, r[Y]c, r[Y]a, w[Z]b, r[Z]c, r[X]c, w[Y]a

UCDavis, ecs251 Spring /17/2007Transactions21 operation conflict rules l Conflicting operations l a pair of operations conflicts if their combined effect depends on the order in which they were performed –e.g. read and write (whose effects are the result returned by read and the value set by write) Operations of different transactions ConflictReason read NoBecause the effect of a pair ofread operations does not depend on the order in which they are executed readwriteYesBecause the effect of aread and awrite operation depends on the order of their execution write YesBecause the effect of a pair ofwrite operations depends on the order of their execution

UCDavis, ecs251 Spring /17/2007Transactions22Serializability l Given a transaction execution history, check all the operation conflicts. –Check whether you can find a serializable schedule to satisfy all the conflicts, or –Check if the conflict dependency graph is acyclic or not.

UCDavis, ecs251 Spring /17/2007Transactions23 Concurrency Control l We might not be able to control the scheduler. l Let’s use some mechanisms (such as mutex, cond, or other) to stop certain threads to avoid “non-serializable” execution history. –locking –time-stamping –optimistic approach

UCDavis, ecs251 Spring /17/2007Transactions24 Lock-based CC l Two extra operations: –lock and unlock l The problem is where and when to put these new operations??

UCDavis, ecs251 Spring /17/2007Transactions25 (a) lock(X) R(X) W(X) unlock(X) lock(Y) R(Y) W(Y) unlock(Y) (b) lock(Z) R(Z) unlock(Z) lock(Y) R(Y) W(Y) unlock(Y) lock(X) R(X) W(X) unlock(X) (c) lock(Y) R(Y) lock(Z) R(Z) W(Y) unlock(Y) W(Z) unlock(Z)

UCDavis, ecs251 Spring /17/2007Transactions26 lock(X) R(X) W(X) unlock(X) lock(Y) R(Y) W(Y) unlock(Y) lock(Z) R(Z) unlock(Z) lock(Y) R(Y) W(Y) unlock(Y) lock(X) R(X) W(X) unlock(X) lock(Y) R(Y) lock(Z) R(Z) W(Y) unlock(Y) W(Z) unlock(Z)

UCDavis, ecs251 Spring /17/2007Transactions27 (a) lock(X) lock(Y) lock(Z) R(X) W(X) R(Y) W(Y) unlock(Z) unlock(Y) unlock(X) (b) lock(X) lock(Y) lock(Z) R(Z) R(Y) W(Y) R(X) W(X) unlock(Z) unlock(Y) unlock(X) (c) lock(X) lock(Y) lock(Z) R(Y) R(Z) W(Y) W(Z) unlock(Z) unlock(Y) unlock(X)

UCDavis, ecs251 Spring /17/2007Transactions28 (a) lock(Y) lock(X) R(X) W(X) R(Y) W(Y) unlock(X) unlock(Y) (b) lock(X) lock(Y) lock(Z) R(Z) R(Y) W(Y) R(X) W(X) unlock(Z) unlock(Y) unlock(X) (c) lock(Y) lock(Z) R(Y) R(Z) W(Y) W(Z) unlock(Z) unlock(Y)

UCDavis, ecs251 Spring /17/2007Transactions29 (a) lock(X) R(X) W(X) Lock(Y) Unlock(x) R(Y) W(Y) unlock(Y) (b) lock(X) lock(Y) lock(Z) R(Z) R(Y) W(Y) R(X) W(X) unlock(Z) unlock(Y) unlock(X) (c) lock(Y) R(Y) Lock(z) R(Z) W(Y) Unlock(Y) W(Z) unlock(Z)

UCDavis, ecs251 Spring /17/2007Transactions30 lock(X) lock(Y) R(X) W(X) R(Y) W(Y) unlock(Y) unlock(X) lock(X) lock(Y) lock(Z) R(Z) R(Y) W(Y) R(X) W(X) unlock(Z) unlock(Y) unlock(X) lock(Y) lock(Z) R(Y) R(Z) W(Y) W(Z) unlock(Z) unlock(Y) abc

UCDavis, ecs251 Spring /17/2007Transactions31 Two-Phase Locking l Two-phase locking.

UCDavis, ecs251 Spring /17/2007Transactions32 Strict Two-Phase Locking l Strict two-phase locking. Commit or Abort 1.prevent dirty read and immature write 2.we don’t really know where the lock point is!!

UCDavis, ecs251 Spring /17/2007Transactions33 Lock compatibility (read, write and commit locks) For one objectLock to be set readwritecommit Lock already setnoneOK readOK wait writeOKwait commitwait

UCDavis, ecs251 Spring /17/2007Transactions34 Time-Stamp Ordering l “Serial Equivalence”  One particular order, e.g., “abc”. l TSO sets the “order” from the beginning and enforce that the “execution history” must strictly follow that order. –If we decide “abc”, then we will not allow “bac”. l Problem: how to assign the order among transactions?

UCDavis, ecs251 Spring /17/2007Transactions35 Time Stamp Ordering l TS_start (T): each T will get a unique TS. –It should remain the same until abort/commit. –First Come First Serve. l For each object X: –TS_read (X): l The largest TS_start among T’s who had read X –TS_write(X): l The largest TS_start among T’s who had written X –The values only monotonically increase. l Write: TS_start(T) >= TS_read(X) –T’s future has not been read. –TS_start(T) < TS_write(X)  skip the write but continue. l Read: TS_start(T) >= TS_write(X) –T’s future has not been written.

UCDavis, ecs251 Spring /17/2007Transactions36 Operation conflicts for timestamp ordering Rule TcTc TiTi 1.writereadTcTc must notwrite an object that has beenread by anyTiTi where this requires thatTcTc ≥ the maximum read timestamp of the object. 2.write TcTc must notwrite an object that has beenwritten by anyTiTi where TiTi >TcTc this requires thatTcTc > write timestamp of the committedobject. 3.readwriteTcTc must notread an object that has beenwritten by anyTiTi where this requires thatTcTc > write timestamp of the committed object. TiTi >TcTc TiTi >TcTc

UCDavis, ecs251 Spring /17/2007Transactions37 (a) R(X) W(X) R(Y) W(Y) (b) R(Z) R(Y) W(Y) R(X) W(X) (c) R(Y) R(Z) W(Y) W(Z)

UCDavis, ecs251 Spring /17/2007Transactions38 TS start a = 1 R(X) = 1 W(X) = 1 TS start b = 2 R(Z) = 2 TS start c = 3 RW X Y Z RW X Y Z

UCDavis, ecs251 Spring /17/2007Transactions39 TS start a = 1 R(X) = 1 W(X) = 1 R(Y) = 3 (v1<3 == R(Y)) TS start b = 2 R(Z) = 2 R(Y) = 3 (v2<3) TS start c = 3 R(Y)= 3 R(Z)= 3 RW X Y Z (1 > 0 == W(Y)) RW X Y Z (2 > 0 == W(Y))

UCDavis, ecs251 Spring /17/2007Transactions40 TS start a = 1 R(X) = 1 W(X) = 1 R(Y) = 3 (1<3) W(Y) abort (1 < (R(Y) == 3)) TS start b = 2 R(Z) = 2 R(Y) = 3 (2<3) W(Y) abort (2 < (R(Y) == 3)) R(X) W(X) TS start c = 3 R(Y)= 3 R(Z)= 3 W(Y)= 3 W(Z)= 3 RW X Y Z

UCDavis, ecs251 Spring /17/2007Transactions41 TS start a = 1 R(X) = 1 W(X) = 1 R(Y) = 2 W(Y) = 3 TS start b = 2 R(Z) = 2 R(Y) = 2 W(Y) = 2 R(X) = 2 W(X) = 2 TS start c = 3 R(Y)= 3 R(Z)= 3 W(Y)= 3 W(Z)= 3 Which one(s) will commit?

UCDavis, ecs251 Spring /17/2007Transactions42 TS start a = 1 R(X) = 1 W(X) = 1 R(Y) = 2 W(Y) = 3 TS start b = 2 R(Z) = 2 R(Y) = 2 W(Y) = 2 R(X) = 2 W(X) = 2 TS start c = 3 R(Y)= 3 R(Z)= 3 W(Y)= 3 W(Z)= 3

UCDavis, ecs251 Spring /17/2007Transactions43 TS start a = 1 R(X) = 1 W(X) = 1 R(Y) = 2 W(Y) = 3 TS start b = 2 R(Z) = 2 R(Y) = 2 W(Y) = 2 R(X) = 2 W(X) = 2 TS start c = 3 R(Y)= 3 R(Z)= 3 W(Y)= 3 W(Z)= 3

UCDavis, ecs251 Spring /17/2007Transactions44 TS start a = 1 R(X) = 1 W(X) = 1 R(Y) = 2 W(Y) = 3 TS start b = 2 R(Z) = 2 R(Y) = 2 W(Y) = 2 R(X) = 2 W(X) = 2 TS start c = 3 R(Y)= 3 R(Z)= 3 W(Y)= 3 W(Z)= 3

UCDavis, ecs251 Spring /17/2007Transactions45 TS start a = 1 R(X) = 1 W(X) = 1 R(Y) = 2 W(Y) = 3 TS start b = 2 R(Z) = 2 R(Y) = 2 W(Y) = 2 R(X) = 2 W(X) = 2 TS start c = 3 R(Y)= 3 R(Z)= 3 W(Y)= 3 W(Z)= 3

UCDavis, ecs251 Spring /17/2007Transactions46 TS start a = 1 R(X) = 1 W(X) = 1 R(Y) = 2 W(Y) = 3 TS start b = 2 R(Z) = 2 R(Y) = 2 W(Y) = 2 R(X) = 2 W(X) = 2 TS start c = 3 R(Y)= 3 R(Z)= 3 W(Y)= 3 W(Z)= 3

UCDavis, ecs251 Spring /17/2007Transactions47 T1: begin transaction query cs.ucdavis.edu query x123.google.com query mail.yahoo.com end transaction T2: begin transaction query cs.ucdavis.edu update cs.ucdavis.edu query x123.google.com update x123.google.com end transaction T3: begin transaction query mail.yahoo.com update mail.yahoo.com query x123.google.com update x123.google.com end transaction DNS Transactions Consistent Name-IPAddr Mappings e.g., web site upgrading

UCDavis, ecs251 Spring /17/2007Transactions48 HW#2 Programming Part l Transaction Execution History –Operation {R, W} –Object Identifier (an integer) –Transaction Identifier (an integer) l Answer: –Serializable or not –Can this input execution history be produced by 2PL, TSO, or OCC? l Due Date: May 31, 2007 (1~2 students per team) l I will provide the test cases. l We will do “interactive grading”!

UCDavis, ecs251 Spring /17/2007Transactions49 HW#2 Writing Part l I will post a few questions (like HW#1) regarding distributed file systems (NFS, AFS, GFS, and Coda). l During the interactive grading session, I will ask questions as well.

UCDavis, ecs251 Spring /17/2007Transactions50 OCC: Optimistic Concurrency Control Execute the Transaction Validation logging Commit or abort??

UCDavis, ecs251 Spring /17/2007Transactions51 Three Phases in OCC Working phase –the transaction uses a tentative version of the objects it accesses (dirty reads can’t occur as we read from a committed version or a copy of it) –the coordinator records the readset and writeset of each transaction Validation phase –at closeTransaction the coordinator validates the transaction (looks for conflicts) –if the validation is successful the transaction can commit. –if it fails, either the current transaction, or one it conflicts with is aborted Update phase –If validated, the changes in its tentative versions are made permanent. –read-only transactions can commit immediately after passing validation.

UCDavis, ecs251 Spring /17/2007Transactions52 OCC Data Structure l Object l Transaction –ReadSet: objects read by T –WriteSet: objects written by T –Shadow Copies: copies of objects written by T but not yet committed (temporary copies) Real R W R W

UCDavis, ecs251 Spring /17/2007Transactions53 OCC Operations l T.read (Object Obj) –add Obj to T.ReadSet –if Obj in T.WriteSet, return T.Copies(Obj) –otherwise return Real(Obj); l T.write (Object Obj, Value V) –add Obj to T.WriteSet –if Obj in T.WriteSet, update T.Copies(Obj) –otherwise, create T.Copies(Obj), and update it.

UCDavis, ecs251 Spring /17/2007Transactions54 How to Validate?? Execute the Transaction Validation logging

UCDavis, ecs251 Spring /17/2007Transactions55 How to Validate?? l Assign the Transaction number –similar to the TSO, but until the beginning of the validation phase.

UCDavis, ecs251 Spring /17/2007Transactions56 How to Validate?? l Assign the Transaction number –similar to the TSO, but until the beginning of the validation phase. l According to the “Order”, try to detect conflicts for a particular transaction, T current –Have T current read anything that have been updated since then? –Validate against all the transactions committed earlier, but finished their update phase after the starting time of the transaction. l “Backward Validation”  “Forward” l “Serial Validation”  “Parallel”

UCDavis, ecs251 Spring /17/2007Transactions57 Three Phases in OCC WorkingValidationUpdate Starting Time of the Transaction Commit

UCDavis, ecs251 Spring /17/2007Transactions58 OCC transactions Earlier committed transactions WorkingValidationUpdate T 1 T current Transaction being validated T 2 T 3 Later active transactions active 1 2

UCDavis, ecs251 Spring /17/2007Transactions59 Which ones should we consider? Earlier committed transactions WorkingValidationUpdate T 1 T current Transaction being validated T 2 T 3 Later active transactions active 1 2

UCDavis, ecs251 Spring /17/2007Transactions60 OCC Conflict Detection l Transactions entering the commit queue. l Conflicts: –if T reads something that has been updated by “earlier” committed transactions. T R-set W-set T R-set W-set T R-set W-set T R-set W-set T R-set W-set committedcurrentcommitted

UCDavis, ecs251 Spring /17/2007Transactions61 Why not Write-Write conflicts? l WW conflicts: –In OCC, all the writes are performed in one shot (atomically)!!

UCDavis, ecs251 Spring /17/2007Transactions62 (a) W(X) W(Z) (b) W(Y) W(X) (c) W(Y) W(Z)

UCDavis, ecs251 Spring /17/2007Transactions63 (a) W(X) W(Z) (b) W(Y) W(X) (c) W(Y) W(Z)

UCDavis, ecs251 Spring /17/2007Transactions64 (a) validation W(X) W(Z) (b) validation W(Y) W(X) (c) validation W(Y) W(Z)

UCDavis, ecs251 Spring /17/2007Transactions65 Validation of Transactions Backward validation of transaction T v boolean valid = true; for (int T i = startTn+1; T i <= finishTn; T i ++){ if (read set of T v intersects write set of T i ) valid = false; } Forward validation of transaction T v boolean valid = true; for (int T id = active1; T id <= activeN; T id ++){ if (write set of T v intersects read set of T id ) valid = false; }

UCDavis, ecs251 Spring /17/2007Transactions66 An Optimization T 102 R-set W-set T 101 R-set W-set T 97 R-set W-set T 92 R-set W-set T 103 R-set W-set committedcurrentcommitted conflict Problem: ReadSet (T 103 ) intersects with WriteSet (T 101 ) Assume that WriteSet (T 103 ) does NOT intersect with ReadSet (T 101 ) Do we have any hope NOT to abort T 103 ?

UCDavis, ecs251 Spring /17/2007Transactions67 Forward Validation l Try to detect conflicts for other transactions against T current –Have T current updated anything that have been read EVER? –Validate against all the transactions not yet committed. l Every Object should have a “ReadSet” (which transactions have read this object).

UCDavis, ecs251 Spring /17/2007Transactions68 OCC - Serial Validation committedcommittingworking/in progress transaction number being assigned Latest Committed transaction

UCDavis, ecs251 Spring /17/2007Transactions69 Parallel Validation l Can I validate multiple transactions at the same time?

UCDavis, ecs251 Spring /17/2007Transactions70 How to Validate in Parallel?? l Assign the Transaction number –similar to the TSO, but when?? l According to the “Order”, try to detect conflicts for a particular transaction, T current –Have T current read anything that have been updated since then? How about other “committing” transactions? –Validate against all the transactions committed or committing earlier, but finished their update phase after the starting time of the transaction.

UCDavis, ecs251 Spring /17/2007Transactions71 OCC - Parallel Validation committedcommittingworking/in progress transaction number being assigned Latest Committed transaction ….. difference: against themselves as well abc acb bac bca cab cba committing ab ba

UCDavis, ecs251 Spring /17/2007Transactions72 OCC - PV committedcommittingworking/in progress transaction number being assigned Latest Committed transaction …..

UCDavis, ecs251 Spring /17/2007Transactions73OCC l the scheme is called optimistic because the likelihood of two transactions conflicting is low l a transaction proceeds without restriction until the closeTransaction (no waiting, therefore no deadlock) l it is then checked to see whether it has come into conflict with other transactions l when a conflict arises, a transaction is aborted l each transaction has three phases

UCDavis, ecs251 Spring /17/2007Transactions74 Validation of transactions l We use the read-write conflict rules –to ensure a particular transaction is serially equivalent with respect to all other overlapping transactions l each transaction is given a transaction number when it starts validation (the number is kept if it commits) l the rules ensure serializability of transaction T v (transaction being validated) with respect to transaction T i TvTv TiTi Rule writeread1.TiTi must not read objects written byTvTv readwrite2.TvTv must not read objects written byTiTi write 3.TiTi must not write objects written byTvTv and TvTv mustnot write objects written byTiTi forward backward

UCDavis, ecs251 Spring /17/2007Transactions75 OCC: Optimistic Concurrency Control Execute the Transaction Validation logging Concurrency?? Security?? Semantic Conflict detection Intrusion detection Abort  conflict resolution

UCDavis, ecs251 Spring /17/2007Transactions76 AFS l State-ful clients and servers. l Caching the files to clients. –File close ==> check-in the changes. l How to maintain consistency? –Using “Callback” in v2/3 open read applications invalidate and re-cache

UCDavis, ecs251 Spring /17/2007Transactions77 Other Applications?? l In what situations, the optimistic approach might be better than the traditional locking approach?

UCDavis, ecs251 Spring /17/2007Transactions78 Special Cases l Long-life transactions –??? l Read-only transactions –Maybe a very common case –Die versus Kill

UCDavis, ecs251 Spring /17/2007Transactions79 Multi-Versions l Data update history for every object. l Every version has a logical timestamp

UCDavis, ecs251 Spring /17/2007Transactions80 Multi-Versions X Y time

UCDavis, ecs251 Spring /17/2007Transactions81 Multi-Versions X Y Real Time Initial Value

UCDavis, ecs251 Spring /17/2007Transactions82 Multi-Versions X Y Real Time Initial Value

UCDavis, ecs251 Spring /17/2007Transactions83 MV -- Global VTS X Y Virtual Time Initial Value

UCDavis, ecs251 Spring /17/2007Transactions84 Real-Only Transaction l How to make sure that ROT will never be aborted?

UCDavis, ecs251 Spring /17/2007Transactions85 MV -- Global VTS X Y Virtual Time Initial Value

UCDavis, ecs251 Spring /17/2007Transactions86 C MV -- Global VTS X Y Virtual Time Initial Value

UCDavis, ecs251 Spring /17/2007Transactions87 Deciding the right “GTS”

UCDavis, ecs251 Spring /17/2007Transactions88 Deciding the right “GTS” l Get the latest committed version # from “every object” (we have to know the Read Set in advance or maybe we will be aborted at most ONCE) l Choose the “smallest” # as the GTS for this read-only transaction?

UCDavis, ecs251 Spring /17/2007Transactions89 Inactive Object

UCDavis, ecs251 Spring /17/2007Transactions90 Distributed OCC l Distributed Files systems

UCDavis, ecs251 Spring /17/2007Transactions91 local OCC on 1 server: Optimistic Concurrency Control Execute the Transaction Validation logging Abort  conflict resolution T R-set W-set T R-set W-set T R-set W-set T R-set W-set T R-set W-set committedcurrentcommitted 2PC

UCDavis, ecs251 Spring /17/2007Transactions92DOCC [tID 22] R-set W-set [tID 05] R-set W-set [tID 17] R-set W-set [tID 67] R-set W-set [tID 34] R-set W-set committedcurrentcommitted Transaction-ID: tID Validation-Order-ID:vID Server X: Server Y: What is the issue here? [tID 05] R-set W-set [tID 34] R-set W-set [tID 17] R-set W-set [tID 67] R-set W-set [tID 22] R-set W-set committedcurrentcommitted [vID 03][vID 05][vID 06] [vID 11][vID 12][vID 16]

UCDavis, ecs251 Spring /17/2007Transactions93DOCC [tID 22] R-set W-set [tID 05] R-set W-set [tID 17] R-set W-set [tID 67] R-set W-set [tID 34] R-set W-set committedcurrentcommitted Transaction-ID: tID Validation-Order-ID:vID Server X: Server Y: Local serializable, but not global serializable!! [tID 05] R-set W-set [tID 34] R-set W-set [tID 17] R-set W-set [tID 67] R-set W-set [tID 22] R-set W-set committedcurrentcommitted [vID 03][vID 05][vID 06] [vID 11][vID 12][vID 16]

UCDavis, ecs251 Spring /17/2007Transactions94 Distribited OCC l How to extend OCC to a distributed system? –distributed 3 phases: working, validation, and writing –how to coordinate?

UCDavis, ecs251 Spring /17/2007Transactions95 Distributed OCC Coordinator Server ….. How to assign “consistent” transaction # to the same global transaction? OCC What is the problem? Coordinator

UCDavis, ecs251 Spring /17/2007Transactions96 Maximum Validation ID Coordinator Server ….. Coordinator mvID:the largest validation-ID being assigned on a local server!! [mvID]

UCDavis, ecs251 Spring /17/2007Transactions97 Getting the vID Right!! l C  S –What is the current value of [mvID]? l S  C –Answer l C  S –C chooses a value (max{mvID i } + delta) l S  C –success or not l C  S –validation start if all succeed.

UCDavis, ecs251 Spring /17/2007Transactions98 Readings l OCC (Kung-Robinson) l DMV-OCC