Section 18.8 : Concurrency Control – Timestamps -CS 257, Rahul Dalal - SJSUID: 011445330 Edited by: Sri Alluri (313)

Slides:



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

Unit 9 Concurrency Control. 9-2 Wei-Pang Yang, Information Management, NDHU Content  9.1 Introduction  9.2 Locking Technique  9.3 Optimistic Concurrency.
1 Concurrency Control Chapter Conflict Serializable Schedules  Two actions are in conflict if  they operate on the same DB item,  they belong.
Concurrency Control Amol Deshpande CMSC424. Approach, Assumptions etc.. Approach  Guarantee conflict-serializability by allowing certain types of concurrency.
Concurrency Control II. General Overview Relational model - SQL  Formal & commercial query languages Functional Dependencies Normalization Physical Design.
CS6223: Distributed Systems
Lock-Based Concurrency Control
Lecture 11 Recoverability. 2 Serializability identifies schedules that maintain database consistency, assuming no transaction fails. Could also examine.
Concurrent Transactions Even when there is no “failure,” several transactions can interact to turn a consistent state into an inconsistent state.
SECTION 18.8 Timestamps. What is Timestamping? Scheduler assign each transaction T a unique number, it’s timestamp TS(T). Timestamps must be issued in.
CONCURRENCY CONTROL SECTION 18.7 THE TREE PROTOCOL By : Saloni Tamotia (215)
©Silberschatz, Korth and Sudarshan16.1Database System Concepts 3 rd Edition Chapter 16: Concurrency Control Lock-Based Protocols Timestamp-Based Protocols.
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.
Concurrency III (Timestamps). Serializability Via Timestamps (Continued) Every DB element X has two timestamps: 1. RT (X) = highest timestamp of a transaction.
©Silberschatz, Korth and Sudarshan16.1Database System Concepts 3 rd Edition Chapter 16: Concurrency Control Lock-Based Protocols Timestamp-Based Protocols.
Transaction Management
Concurrency. Correctness Principle A transaction is atomic -- all or none property. If it executes partly, an invalid state is likely to result. A transaction,
1 Lecture 19: Concurrency Control Friday, February 18, 2005.
18.8 Concurrency Control by Timestamps - Dongyi Jia - CS257 ID:116 - Spring 2008.
18.8 Concurrency Control by Timestamps CS257 Student Chak P. Li.
Concurrency control by Timestamps (Section18.8) Varun Gupta Department of Computer Science ID-216 CS 257.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
Alternative Concurrency Control Methods R&G - Chapter 17.
Prepared By: Ronak Shah Professor :Dr. T. Y Lin ID: 116.
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 10 Transaction Management.
Concurrency Control Techniques Chapter 18
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.
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
Transaction Management Transparencies. ©Pearson Education 2009 Chapter 14 - Objectives Function and importance of transactions. Properties of transactions.
CSE544: Transactions Concurrency Control Wednesday, 4/26/2006.
Timestamp-based Concurrency Control
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.
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.
CS411 Database Systems Kazuhiro Minami 16: Final Review Session.
Transactions Examples
Database recovery techniques
Concurrency control.
Database Recovery Techniques
Transaction Management
Concurrency Control Techniques
Transaction Management and Concurrency Control
Extra slide #3.
Multiple Granularity Granularity is the size of data item  allowed to lock. Multiple Granularity is the hierarchically breaking up the database into portions.
Transaction Management Transparencies
Synchronization Chapter 5C
Unit :- 1 Concurrency Control.
Database Concurrency Control
Concurrency Control via Timestamps
Concurrency Control II (OCC, MVCC)
CONCURRENCY CONTROL (CHAPTER 16)
Concurrency.
Chapter 10 Transaction Management and Concurrency Control
Database Transactions
Distributed Database Management Systems
Concurrency Control by Validation
Lecture 19: Concurrency Control
Transaction management
Concurrency Control Techniques
Submitted to Dr. Badie Sartawi Submitted by Nizar Handal Course
Introduction to Database Systems CSE 444 Lectures 17-18: Concurrency Control November 5-7, 2007.
Concurrency control (OCC and MVCC)
Transactions, Properties of Transactions
Presentation transcript:

Section 18.8 : Concurrency Control – Timestamps -CS 257, Rahul Dalal - SJSUID: 011445330 Edited by: Sri Alluri (313)

Agenda 18.8.1 Introduction 18.8.1 Basics 18.8.2 Physically Unrealizable Behavior 18.8.3 Problems – Dirty Data 13.8.4 Rules – Timestamp Scheduling 18.8.5 Multiversion Timestamps 18.8.6 Timestamp vs Locking

Introduction Assign a timestamp to each transaction Record the time stamps of the transaction/s that last read and write each database element Compare these values with the transactions timestamps to ensure the serial schedule is equivalent to the actual schedule

Basics Scheduler assigns each transaction T a timestamp – unique no. Ascending order Issued when a transaction notifies the scheduler its beginning How to generate timestamp ?? Property – A transaction that starts later has a higher timestamp than one that starts earlier System Clock Scheduler should not operate so fast that it could assign same timestamp to two transactions in one tick Scheduler maintains a counter Whenever a transaction starts, counter incremented by 1 Counter value is the timestamp Timestamp has nothing to do with actual ‘time’

Basics…. Maintain a table of currently active transactions and their timestamps Each database element ‘X’ is associated with RT(X) - Read time of database element X Highest timestamp of a transaction that has read X WT(X) - Write time of database element X Highest timestamp of a transaction that has written X C(X) - Commit bit for database element X True if and only if the most recent transaction to write X has already committed Why C(X) is required ? Transactions can abort in this system Imagine transaction T reads data written by another transaction U and U then aborts “Dirty read” problem - Uncommitted data can cause the database state to become inconsistent

Physically Unrealizable Behavior…. Scheduler assumes the timestamp order of trans­actions is also the serial order in which they must appear to execute ‘Whenever a read or write occurs, what happens in real time could have happened if each transaction had executed instantaneously at the moment of its timestamp’ If not the behavior is physically unrealizable Read too late Write too late

Read too late U writes X T reads X T U WT(X) = TS(U) time WT(X) = TS(U) Theoretically: TS(T) < WT(X) Actually: TS (T) > WT (X) Transaction T should have read X before X was written by U - contradiction T U Timestamps allocated by scheduler to T and U when they begin TS (T) < TS (U)

Read too late - Solution T should not be able to read the value written by U, because theoretically, U executed after T did T has no choice, because U’s value of X is the one that T now sees Solution - Abort T when the problem is encountered

Write too late U reads X T writes X T U RT(X) = TS(U) Theoretically: TS(T) < RT(X) Actually: TS (T) > RT (X) X has already been read by a transaction U that theoreti­cally executed later than T – contradiction T U Timestamps allocated by scheduler to T and U when they begin TS (T) < TS (U)

Dirty read class U writes X T reads X T start U start U aborts e.g. Division by 0 There is nothing physically unrealizable about T reading X It is better to delay T ’s read until U commits or aborts

Thomas Write Rule T should do nothing U writes X T writes X T starts U starts T should do nothing

Thomas Write Rule U with a later timestamp than T, has written X first T tries to write, the appropriate action is to do nothing No other transaction, V that should have read T ’s value of X got U’s value instead, because if V tried to read X it would have aborted because of a too-late read Future reads of X will want U’s value or a later value of X , not T ’s value

Thomas Write Rule - Problem U writes X T writes X Does nothing (no write) T start U start T commits U aborts

Thomas Write Rule - Problem If U aborts then Its value of X should be removed AND Previous value and write-time restored. Since T is committed, it would Value of X should be the one written by T for future reading Write by T was skipped and it is too late to repair the damage

Solution – Design Principle When a transaction T writes a database element X , the write is “tentative” and may be undone if T aborts. The commit bit C (X ) is set to false, and the scheduler makes a copy of the old value of X and its previous W T ( X )

Rules – Timestamp based scheduling Make sure that nothing physically unrealizable may occur The scheduler, in response to a read or write request from a transaction T has the choice of: Granting the request Aborting T (if T would violate physical reality) and restarting T with a new timestamp (abort followed by restart is often called rollback) OR Delaying T and later deciding whether to abort T or to grant the request (if the request is a read, and the read might be dirty)

Rule 1 Suppose the scheduler receives a request rT (X ) (a) If TS (T) > WT ( X ) , the read is physically realizable If c (X ) is true, grant the request. If TS (T) > RT ( X ) , set RT ( X ) := TS(T); otherwise do not change RT ( X ) If C(X) is false, delay T until C(X) becomes true, or the transaction that wrote X aborts (b) If TS (T) < WT ( X ) , the read is physically unrealizable. Rollback T ( Abort T and restart it with a new, larger timestamp)

Rule 2 Suppose the scheduler receives a request wT( X ) (a) If TS(T) > RT(X) and TS(T) > WT(X), the write is physically realizable and must be performed Write the new value for X Set WT(X) := TS(T), and Set C(X ) := false (b) If TS(T) > RT(X), but TS(T) < WT(X), then the write is physically realizable, but there is already a later value in X If C(X) is true, then the previous writer of X is committed, and we simply ignore the write by T; we allow T to proceed and make no change to the database if C (X ) is false, then we must delay T as in point l - ii. (c) If TS(T) < RT(X), then the write is physically unrealizable, and T must be rolled back.

Rules 3 & 4 Rule 3 - Suppose the scheduler receives a request to commit T. It must find (using a list the scheduler maintains) all the database elements X written by T, and set c (X ) := true . If any transactions are waiting for X to be committed (found from another scheduler-maintained list), these transactions are allowed to proceed Rule 4 - Suppose the scheduler receives a request to abort T or decides to rollback T as in 1 (b) or 2 (c), then any transaction that was waiting on an element X that T wrote must repeat its attempt to read or write, and see whether the action is now legal after T ’s writes are cancelled.

Example

Multiversion Timestamps Maintains old versions of database elements in addition to the current version that is stored in the database itself The purpose is to allow reads rT(X) that otherwise would cause transaction T to abort (because the current version of X was written in T ’s future) to proceed by reading the version of X that is appropriate for a transaction with T ’s timestamp The method is especially useful if database elements are disk blocks or pages

Multiversion Timestamps When a new write wT(X) occurs, if it is legal, then a new version of database element X is created. Its write time is TS(t), and we shall refer to it as Xt, where t = TS(T). When a read ru (X) occurs, the scheduler finds the version Xt of X such that t < TS(U), but there is no other version Xt’ with t < t' < TS(T) i.e. the version of X written immediately before T theoretically executed is the version that T reads. Write times are associated with versions of an element, and they never change Read times are also associated with versions. They are used to reject certain writes, namely one whose time is less than the read time of the previous version. When a version Xt has a write time t such that no active transaction has a timestamp less than t, then we may delete any version of X previous to Xt

Timestamps vs Locking Timestamping is optimistic - it assumes that no unserializable behavior will occur and only fix things up when a violation is apparent In contrast, all locking methods assume that things will go wrong unless transactions are prevented in advance from engaging in nonserializable behavior The optimistic approaches differ from locking in that the only remedy when something does go wrong is to abort and restart a transaction that tries to engage in unserializable behavior. In contrast, locking schedulers delay transactions, but do not abort them

Timestamps vs Locking Locking will frequently delay transactions as they wait for locks If concurrent transactions frequently read and write elements in common, then rollbacks will be frequent in a timestamp scheduler, introducing even more delay than a locking system Timestamping is superior in situations where either most transactions are read-only, or it is rare that concurrent transactions will try to read and write the same element In high-conflict situations, locking performs better

Beneficial compromise Several commercial systems a compromise of the two methods Scheduler divides the transactions into read-only transactions and read/write transactions. Read/write transactions are executed using two-phase locking, to keep all transactions from accessing the elements they lock Read-only transactions are executed using multiversion timestamping. As the read/write transactions create new versions of a database element, those versions are managed A read-only transaction is allowed to read whatever version of a database element is appropriate for its timestamp. A read-only transaction thus never has to abort, and will only rarely be delayed

Questions ???