Synchronization Chapter 6 Part III Transactions. –Most of the lecture notes are based on slides by Prof. Jalal Y. Kawash at Univ. of Calgary –Some slides.

Slides:



Advertisements
Similar presentations
Optimistic Methods for Concurrency Control By : H.T. Kung & John T. Robinson Presenters: Munawer Saeed.
Advertisements

1 Concurrency Control Chapter Conflict Serializable Schedules  Two actions are in conflict if  they operate on the same DB item,  they belong.
Transaction Management: Concurrency Control CS634 Class 17, Apr 7, 2014 Slides based on “Database Management Systems” 3 rd ed, Ramakrishnan and Gehrke.
Concurrency Control II. General Overview Relational model - SQL  Formal & commercial query languages Functional Dependencies Normalization Physical Design.
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.
1 Chapter 3. Synchronization. STEMPusan National University STEM-PNU 2 Synchronization in Distributed Systems Synchronization in a single machine Same.
Database Systems, 8 th Edition Concurrency Control with Time Stamping Methods Assigns global unique time stamp to each transaction Produces explicit.
Concurrency Control and Recovery In real life: users access the database concurrently, and systems crash. Concurrent access to the database also improves.
©Silberschatz, Korth and Sudarshan16.1Database System Concepts 3 rd Edition Chapter 16: Concurrency Control Lock-Based Protocols Timestamp-Based Protocols.
Computer Science Lecture 12, page 1 CS677: Distributed OS Last Class Distributed Snapshots –Termination detection Election algorithms –Bully –Ring.
CS 582 / CMPE 481 Distributed Systems Concurrency Control.
CS 245Notes 101 CS 245: Database System Principles Notes 10: More TP Hector Garcia-Molina.
Database management concepts Database Management Systems (DBMS) An example of a database (relational) Database schema (e.g. relational) Data independence.
Synchronization Part 2 REK’s adaptation of Claypool’s adaptation ofTanenbaum’s Distributed Systems Chapter 5 and Silberschatz Chapter 17.
Distributed Systems1 Chapter 7: Distributed Transactions Transaction concepts Centralized/Distributed Transaction Architecture Schedule concepts Locking.
Transaction Management
EEC-681/781 Distributed Computing Systems Lecture 12 Wenbing Zhao Cleveland State University.
Synchronization Chapter 5. Clock Synchronization When each machine has its own clock, an event that occurred after another event may nevertheless be assigned.
Transaction. A transaction is an event which occurs on the database. Generally a transaction reads a value from the database or writes a value to the.
Synchronization.
CIS 720 Concurrency Control. Locking Atomic statement –Can be used to perform two or more updates atomically Th1: …. ;……. Th2:…………. ;…….
1 Transactions BUAD/American University Transactions.
08_Transactions_LECTURE2 DBMSs should guarantee ACID properties (Atomicity, Consistency, Isolation, Durability). This is typically done by guaranteeing.
Transaction Communications Yi Sun. Outline Transaction ACID Property Distributed transaction Two phase commit protocol Nested transaction.
CS 245Notes 101 CS 245: Database System Principles Notes 10: More TP Hector Garcia-Molina.
Database Systems/COMP4910/Spring05/Melikyan1 Transaction Management Overview Unit 2 Chapter 16.
Real-Time & MultiMedia Lab Synchronization Chapter 5.
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)
TRANSACTION MANAGEMENT R.SARAVANAKUAMR. S.NAVEEN..
1 Transactions Chapter Transactions A transaction is: a logical unit of work a sequence of steps to accomplish a single task Can have multiple.
Concurrency Control in Database Operating Systems.
Global State (1) a)A consistent cut b)An inconsistent cut.
Synchronization Chapter 5. Outline 1.Clock synchronization 2.Logical clocks 3.Global state 4.Election algorithms 5.Mutual exclusion 6.Distributed transactions.
Computer Science Lecture 13, page 1 CS677: Distributed OS Last Class: Canonical Problems Distributed synchronization and mutual exclusion Distributed Transactions.
II.I Selected Database Issues: 2 - Transaction ManagementSlide 1/20 1 II. Selected Database Issues Part 2: Transaction Management Lecture 4 Lecturer: Chris.
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.
Synchronization Chapter 5. Table of Contents Clock Synchronization Logical Clocks Global State Election Algorithms Mutual Exclusion.
Page 1 Concurrency Control Paul Krzyzanowski Distributed Systems Except as otherwise noted, the content of this presentation.
Transactions. Transaction: Informal Definition A transaction is a piece of code that accesses a shared database such that each transaction accesses shared.
Concurrency Control Introduction Lock-Based Protocols
1 DC8: Transactions Chapter 12 Transactions and Concurrency Control.
Transaction Management Transparencies. ©Pearson Education 2009 Chapter 14 - Objectives Function and importance of transactions. Properties of transactions.
Clock Synchronization When each machine has its own clock, an event that occurred after another event may nevertheless be assigned an earlier time.
1 CSE232A: Database System Principles More Concurrency Control and Transaction Processing.
Timestamp-based Concurrency Control
NOEA/IT - FEN: Databases/Transactions1 Transactions ACID Concurrency Control.
Synchronization. Clock Synchronization In a centralized system time is unambiguous. In a distributed system agreement on time is not obvious. When each.
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
3 Database Systems: Design, Implementation, and Management CHAPTER 9 Transaction Management and Concurrency Control.
Synchronization CSCI 4900/6900. Transactions Protects data and allows processes to access and modify multiple data items as a single atomic transaction.
Synchronization Chapter 5. Clock Synchronization When each machine has its own clock, an event that occurred after another event may nevertheless be assigned.
Lecture on Synchronization Submitted by
Transactions Chapter 12 Transactions and Concurrency Control.
Computer Science Lecture 13, page 1 CS677: Distributed OS Last Class: Canonical Problems Election algorithms –Bully algorithm –Ring algorithm Distributed.
Atomic Tranactions. Sunmeet Sethi. Index  Meaning of Atomic transaction.  Transaction model Types of storage. Transaction primitives. Properties of.
Transaction Management
Last Class: Canonical Problems
Transaction Management Overview
Synchronization Chapter 5C
CIS 720 Concurrency Control.
Chapter 10 Transaction Management and Concurrency Control
Database Transactions
Chapter 7: Distributed Transactions
Transaction management
Transaction Management Overview
Transactions, Properties of Transactions
Presentation transcript:

Synchronization Chapter 6 Part III Transactions

–Most of the lecture notes are based on slides by Prof. Jalal Y. Kawash at Univ. of Calgary –Some slides are from Prof. Steve Goddard at University Nebraska, Lincoln, Prof. Harandi, Prof. Hou, Prof. Gupta and Prof. Vaidya from University of Illinois, Prof. Kulkarni from Princeton University –I have modified them and added new slides Giving credit where credit is due: CSCE455/855 Distributed Operating Systems

Transactions Example Transaction: Transfer amount X from A to B debit(Account A; Amount X): A = A – X; credit(Account B; Amount X): B = B + X; Either do the whole thing or nothing

ACID Properties – AC Atomicity: No intermediate results are observable –To an external observer, T jumps from the initial state to the final state, or never leaves the initial state Consistency: T produces consistent results only, otherwise it aborts –T fulfills the consistency constraints of the application, no violation of system invariants

ACID Properties – ID Isolation: T looks like it is the only program running –Notice the looks like! Durability: T produces unforgettable by the system results –T’s results become part of reality

Some Transaction Primitives Examples of primitives for transactions. 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, etc. WRITEWrite data to a file, a table, etc.

Transaction Types Flat Transactions Flat Transactions with Savepoints Chained Transactions Nested Transactions Distributed Transactions Multi-level Transactions Open Nested Transactions Long-lived Transactions

Flat Transactions – All or Nothing Simplest Type Basic building block for organizing an application into atomic actions Encloses a program with brackets: –BEGIN_TRANSACTION –END_TRANSACTION All that is between the brackets is performed or nothing at all Strictly satisfies ACID

Flat Transactions – Limitations All-or-nothing is not always appropriate It is beneficial to commit partial results (violate atomicity) Trip Planning: commit part of a transaction Bulk Updates: can be expensive to undo all updates

Trip Planning a)Transaction to reserve three flights commits b)Transaction aborts when third flight is unavailable BEGIN_TRANSACTION reserve LNK -> MSP; reserve MSP -> SEA; reserve SEA -> YVR; END_TRANSACTION (a) BEGIN_TRANSACTION reserve LNK -> MSP; reserve MSP -> SEA; reserve SEA -> YVR full => ABORT_TRANSACTION (b)

Flat Transactions with SavePoints T: BEGIN_TRANSACTION S 1 … S m SAVEPOINT S m+1 … END_TRANSACTION Failure here ROLLBACK Flat T w/o SavePoint W SavePoint

Nested Transactions – No D They organize T actions into a hierarchy 1.A nested T is a tree of T’s; sub-trees are flat or nested 2.Leaf T’s are flat 3.Root T = top-level T; all other are subTs 4.SubT can commit or roll back. Its commit will not take effect unless the root commits 5.When a subT rolls back, all its children are rolled back Satisfy ACI, not the D (except for top level)

Nested Transactions – Trip Planning BEGIN_TRANSACTION BEGIN_SUB reserve LNK -> MSP; END_SUB BEGIN_SUB reserve MSP -> SEA; END_SUB BEGIN_SUB reserve SEA -> YVR; END_SUB END_TRANSACTION Failure here Can Commit

Distributed Transactions A flat transaction that runs in a distributed environment: –Visit several nodes in the system Distributed T: structure is determined by the distribution of data in the DS Nested T: structure is determined by the functional decomposition of the application

Nested versus Distributed Ts a)A nested transaction b)A distributed transaction

How to Implement Transactions?

Achieving Atomicity (I) Private Workspace: –Change a copy of data, keeping original intact –COMMIT: copy changed data to original –ROLLBACK: discard copy

Private Workspace a)The file index and disk blocks for a three-block file b)The situation after a transaction has modified block 0 and appended block 3 c)After committing

Achieving Atomicity (II) Writeahead Log: –Change original data, logging every change before making it –COMMIT: leave changes –ROLLBACK: restore from log

Writeahead Log a) A transaction b) – d) The log before each statement is executed x = 0; y = 0; BEGIN_TRANSACTION; x = x + 1; y = y + 2 x = y * y; END_TRANSACTION; (a) Log [x = 0 / 1] (b) Log [x = 0 / 1] [y = 0 / 2] (c) Log [x = 0 / 1] [y = 0 / 2] [x = 1 / 4] (d)

Achieving Consistency & Isolation Concurrency Control: controlling the execution of concurrent Ts operating on shared data Consistency & Isolation: All Ts must appear as if they executed in some sequential order, one after another (Serializability)

Serializability d) Possible schedules BEGIN_TRANSACTION x = 0; x = x + 1; END_TRANSACTION (a) BEGIN_TRANSACTION x = 0; x = x + 2; END_TRANSACTION (b) BEGIN_TRANSACTION x = 0; x = x + 3; END_TRANSACTION (c) Schedule 1x = 0; x = x + 1; x = 0; x = x + 2; x = 0; x = x + 3Legal Schedule 2x = 0; x = 0; x = x + 1; x = x + 2; x = 0; x = x + 3;Legal Schedule 3x = 0; x = 0; x = x + 1; x = 0; x = x + 2; x = x + 3;Illegal (d) a) – c) Three transactions

Ts as Sequences of Reads and Writes Transaction = sequence of read and write operations –Read of x returning 1 by T: r T (x)1 –Write to x a value 2 by T: w T (x)2 T a BEGIN_TRANSACTION x = 0; x = x + 1; END_TRANSACTION BT w a (x)0 r a (x) 0 w a (x)1 ET 

Conflicting Operations Two operations o 1 and o 2 conflict if: –Both o 1 and o 2 are on the same data item, and –At least one of o 1 and o 2 is a write w a (x)0 r a (x) 0 w a (x)1 w b (x)0 r b (x) 0 w b (x)2 w c (x)0 r c (x) 0 w c (x)3 X

Concurrency Control Algorithms (CCA) CCA: order read and write operations –By using locks (critical sections) –By using timestamps Pessimistic CCA: Act conservatively so that nothing can go wrong Optimistic CCA: Act aggressively, if something goes wrong, abort

Using Locks For T to access (read or write) a data item x: –T requests a lock on x from the scheduler When T finishes accessing x: –T releases the lock Scheduler grants acquisitions & releases on locks so that serializability is guaranteed Locks: –Shared: can only read x –Exclusive: can read and write x

Example T a x = 0 x = x + 1 T b x = 0 x = x + 2 Serializability x = 1 or 2 only Acquire x.lock w(x)0 Release x.lock Acquire x.lock w(x)0 Release x.lock Acquire x.lock r(x)0 Release x.lock Acquire x.lock w(x)1 Release x.lock Acquire x.lock r(x)1 Release x.lock Acquire x.lock w(x)3 Release x.lock x = 3

Two-Phase Locking – Pessimistic A transaction executes in two phases

2PL – Scheduler Rules 1.When sched receives operation o T (x)v: a.If ((exists o’ holding a lock on x) & (o’ and o are conflicting)) Delay o b.Else grant a lock to o and pass o to the data manager 2.Sched never releases a lock for x granted for operation o, until data manager acks the completion of o 3.Once sched releases a lock for T, T cannot be granted another lock. If T tries to, abort it

2PL – Analysis 2PL guarantees serializability BUT not every serializable schedule can be generated by 2PL 2PL can cause a deadlock, concurrency is reduced BEGIN_TRANSACTION x = 0; x = x + 1; x = 6 END_TRANSACTION (a) BEGIN_TRANSACTION x = 0; x = x + 2; x = 8 END_TRANSACTION (b) BEGIN_TRANSACTION x = 0; x = x + 3; x = 10; END_TRANSACTION (c)

Strict 2PL Do not release locks until a T is finished

2PL – Discussion Strict 2PL can also lead to a deadlock –Use timeouts to preempt locks Strict 2PL advantages: –Acquisitions and releases can be done more easily, without T’s knowledge –T always reads committed data  avoid cascaded aborts

2PL – Discussion Strict 2PL can also lead to a deadlock –Use timeouts to preempt locks Strict 2PL advantages: –Acquisitions and releases can be done more easily, without T’s knowledge –T always reads committed data  avoid cascaded aborts Every 2PL (both versions) schedule is serializable BUT not every serializable schedule can be generated by 2PL (both versions)

Pessimistic Timestamp Ordering (PTO) Each T has a timestamp, denoted T.ts Each operation in T has same timestamp (T.ts) Using Lamport’s or vector timestamps, all Ts have unique timestamp values If T.ts < T’.ts then T must appear before T’ in the schedule With each data item x, associate: –x.wts : largest ts of any T that executed w T (x)v –x.rts : largest ts of any T that executed r T (x)v Update x.wts (resp. x.rts) whenever w T (x)v (resp. r T (x)v) occurs

PTO General Concept If T.ts < T’.ts then T must appear before T’ in the schedule Process transactions in a serial order Can use the same file, but must do it in order Therefore isolation is preserved

PTO – read operation When Sched receives r T (x)v operation: –if T.ts < x.wts \\T tries to read the past reject r T (x)v roll T back (assign T a new ts and restart) –if T.ts  x.wts –(Do we need to compare T.ts with x.rts?) execute r T (x)v x.rts = max(x.rts, T.ts)

PTO – write operation When Sched receives w T (x)v operation: –if (T.ts < x.rts) or (T.ts < x.wts) \\T tries to write in the past reject w T (x)v roll T back (assign T a new ts and restart) –else execute w T (x)v x.wts = T.ts

PTO – Analysis Will PTO cause deadlock? –PTO is deadlock-free Each PTO schedule is serializable Not every serializable schedule is possible in PTO 2PL can produce schedules not possible under PTO, and vice versa All serializable Schedules All PTO Schedules All 2PL Schedules

Optimistic Timestamp Ordering (OTO) Each T does its changes to data (in its private workspace) When done either commit or restart Each data item x has x.wts and x.rts, updated as before When T needs to commit, Check x’s ts If there is a conflict then restart else commit

OTO (cont.) Parallelism is maximized –No waiting on locks –Inefficient when an abort is needed Pessimistic vs. Optimistic CCA –For instance, PTO vs. OTO ??

TO: Cascaded Aborts Problem For example the following run with transactions T1 and T2: –W 1 (x) R 2 (x) W 2 (y) R 1 (z), when can we commit T1 and T2? –W 1 (x) R 2 (x) W 2 (y) C 2 R 1 (z) C 1 –This could be produced by a TO scheduler T2 commits even though having read (i.e., R 2 (x)) from an uncomitted transaction –Answer: a scheduler can keep a list of other transactions each transaction has read from, and not let a transaction commit before this list consists of only committed transactions Cascaded aborts still possible! –Answer: To avoid cascaded aborts, the scheduler can tag data written by uncommitted transactions as dirty, and never let a read operation start on such a data item before it was untagged

Appendix

Concurrency Control General organization of managers for handling transactions. Concurrency Control

Concurrency Control for Distributed Ts General organization of managers for handling distributed transactions.