1 Term 2, 2004, Lecture 6, TransactionsMarian Ursu, Department of Computing, Goldsmiths College Transactions 3.

Slides:



Advertisements
Similar presentations
Database System Concepts 5 th Ed. © Silberschatz, Korth and Sudarshan, 2005 See for conditions on re-usewww.db-book.com Chapter 16 : Concurrency.
Advertisements

1 Concurrency: Deadlock and Starvation Chapter 6.
Copyright © 2003 Pearson Education, Inc. Slide 1 Computer Systems Organization & Architecture Chapters 8-12 John D. Carpinelli.
Author: Julia Richards and R. Scott Hawley
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Transactions generalities 1 Transactions - generalities.
1 Term 2, 2004, Lecture 3, NormalisationMarian Ursu, Department of Computing, Goldsmiths College Normalisation 5.
Data recovery 1. 2 Recovery - introduction recovery restoring a system, after an error or failure, to a state that was previously known as correct have.
Concurrency control 1. 2 Introduction concurrency more than one transaction have access to data simultaneously part of transaction processing.
1 Term 2, 2004, Lecture 5, Physical DesignMarian Ursu, Department of Computing, Goldsmiths College Physical Design 3.
1 Term 2, 2004, Lecture 6, Views and SecurityMarian Ursu, Department of Computing, Goldsmiths College Views and Security 3.
1 Term 2, 2004, Lecture 9, Distributed DatabasesMarian Ursu, Department of Computing, Goldsmiths College Distributed databases 3.
Transaction Management Reading: CB, Ch. 22. Dept of Computing Science, University of Aberdeen2 In this lecture you will learn the problems of concurrency.
Concurrency Control Alexandra Cristea and Steve Russ 1.
REVIEW: Arthropod ID. 1. Name the subphylum. 2. Name the subphylum. 3. Name the order.
Concurrency Control Techniques
VOORBLAD.
Factor P 16 8(8-5ab) 4(d² + 4) 3rs(2r – s) 15cd(1 + 2cd) 8(4a² + 3b²)
Basel-ICU-Journal Challenge18/20/ Basel-ICU-Journal Challenge8/20/2014.
1..
Lecture plan Transaction processing Concurrency control
© 2012 National Heart Foundation of Australia. Slide 2.
Understanding Generalist Practice, 5e, Kirst-Ashman/Hull
Indra Budi Transaction Indra Budi
25 seconds left…...
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
Chapters 15-17: Transaction Management
Intracellular Compartments and Transport
PSSA Preparation.
Essential Cell Biology
Concurrency Control WXES 2103 Database. Content Concurrency Problems Concurrency Control Concurrency Control Approaches.
Chapter 16 Concurrency. Topics in this Chapter Three Concurrency Problems Locking Deadlock Serializability Isolation Levels Intent Locking Dropping ACID.
1 Lecture 11: Transactions: Concurrency. 2 Overview Transactions Concurrency Control Locking Transactions in SQL.
TRANSACTION PROCESSING SYSTEM ROHIT KHOKHER. TRANSACTION RECOVERY TRANSACTION RECOVERY TRANSACTION STATES SERIALIZABILITY CONFLICT SERIALIZABILITY VIEW.
Lecture 11 Recoverability. 2 Serializability identifies schedules that maintain database consistency, assuming no transaction fails. Could also examine.
Transaction Management and Concurrency Control
Transaction Management and Concurrency Control
Transaction Management and Concurrency Control
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
Transaction Management
1 Transaction Management Database recovery Concurrency control.
9 Chapter 9 Transaction Management and Concurrency Control Hachim Haddouti.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
Academic Year 2014 Spring Academic Year 2014 Spring.
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 10 Transaction Management.
Transactions CPSC 356 Database Ellen Walker Hiram College (Includes figures from Database Systems by Connolly & Begg, © Addison Wesley 2002)
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 136 Database Systems I SQL Modifications and Transactions.
II.I Selected Database Issues: 2 - Transaction ManagementSlide 1/20 1 II. Selected Database Issues Part 2: Transaction Management Lecture 4 Lecturer: Chris.
The Relational Model1 Transaction Processing Units of Work.
Chapter 16 Concurrency. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.16-2 Topics in this Chapter Three Concurrency Problems Locking Deadlock.
Concurrency Chapter 6.2 V3.1 Napier University Dr Gordon Russell.
Transaction Management Transparencies. ©Pearson Education 2009 Chapter 14 - Objectives Function and importance of transactions. Properties of transactions.
9 1 Chapter 9_B Concurrency Control Database Systems: Design, Implementation, and Management, Rob and Coronel.
Switch off your Mobiles Phones or Change Profile to Silent Mode.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
©Bob Godfrey, 2002, 2005 Lecture 17: Transaction Integrity and Concurrency BSA206 Database Management Systems.
18 September 2008CIS 340 # 1 Last Covered (almost)(almost) Variety of middleware mechanisms Gain? Enable n-tier architectures while not necessarily using.
Chapter 13 Managing Transactions and Concurrency Database Principles: Fundamentals of Design, Implementation, and Management Tenth Edition.
SYSTEMS IMPLEMENTATION TECHNIQUES TRANSACTION PROCESSING DATABASE RECOVERY DATABASE SECURITY CONCURRENCY CONTROL.
Transaction Management and Concurrency Control
Transaction Management and Concurrency Control
Transaction Properties
Concurrency.
Chapter 10 Transaction Management and Concurrency Control
Concurrency Control WXES 2103 Database.
Concurrency Unit 4.2 Dr Gordon Russell, Napier University
Introduction of Week 13 Return assignment 11-1 and 3-1-5
STRUCTURE OF PRESENTATION :
Concurrency Unit 4.2 Dr Gordon Russell, Napier University
Presentation transcript:

1 Term 2, 2004, Lecture 6, TransactionsMarian Ursu, Department of Computing, Goldsmiths College Transactions 3

2 Term 2, 2004, Lecture 6, TransactionsMarian Ursu, Department of Computing, Goldsmiths College Outline transactions - generalities concurrency control concurrency problems locking

3 Term 2, 2004, Lecture 6, TransactionsMarian Ursu, Department of Computing, Goldsmiths College 1

4 Transactions – example Parts (P_id, P_name, Colour, Weight, Total_qty) Contracted (S_id, P_id, Qty) add a new contract for S4 for 200 pieces of P1

5 Term 2, 2004, Lecture 6, TransactionsMarian Ursu, Department of Computing, Goldsmiths College Transaction logical unit of work sequence of database operations transforms a consistent state of a db into another consistent state between operations the db can be inconsistent

6 Term 2, 2004, Lecture 6, TransactionsMarian Ursu, Department of Computing, Goldsmiths College Transaction Processing do not allow for one operation to be performed and the other ones not principle of transaction processing support if some operations are executed and then a failure occurs (before the planned termination) then those operations will be undone

7 Term 2, 2004, Lecture 6, TransactionsMarian Ursu, Department of Computing, Goldsmiths College Transaction Manager COMMIT TRANSACTION a logical unit of work was successfully completed all the updates can be made permanent ROLLBACK TRANSACTION unsuccessful end of transaction all the attempted updates must be rolled back they are issued from applications

8 Term 2, 2004, Lecture 6, TransactionsMarian Ursu, Department of Computing, Goldsmiths College Example execute(BEGIN TRANSACTION); execute(INSERT (S4, P1, 200) INTO Contracted); if(/*any error occurred*/) then go to undo; execute( UPDATE Parts WHERE P_id =P1 SET Total_qty = Total_qty + 200); if(/*any error occurred*/) then go to undo; execute(COMMIT TRANSACTION); go to finish; undo : execute(ROLLBACK TRANSACTION); finish : return;

9 Term 2, 2004, Lecture 6, TransactionsMarian Ursu, Department of Computing, Goldsmiths College SQL Support COMMIT and ROLLBACK No BEGIN TRANSACTION (in SQL2 and Oracle) all data definition and data manipulation statements are transaction initiating PostgreSQL provides BEGIN [TRANSACTION]

10 Term 2, 2004, Lecture 6, TransactionsMarian Ursu, Department of Computing, Goldsmiths College At the COMMIT point all updates, since the previous commit, are made permanent (will not be undone) all database positioning and all tuple locks are lost

11 Term 2, 2004, Lecture 6, TransactionsMarian Ursu, Department of Computing, Goldsmiths College ACID Properties of Transactions Atomicity all or nothing Consistency preserve database consistency Isolation transactions are isolated from one another Durability committed transaction updates are performed

12 Term 2, 2004, Lecture 6, TransactionsMarian Ursu, Department of Computing, Goldsmiths College 2

13 Term 2, 2004, Lecture 6, TransactionsMarian Ursu, Department of Computing, Goldsmiths College Concurrency more than one transaction have access to data simultaneously

14 Term 2, 2004, Lecture 6, TransactionsMarian Ursu, Department of Computing, Goldsmiths College Three concurrency problems the lost update the uncommitted dependency the inconsistent analysis

15 Term 2, 2004, Lecture 6, TransactionsMarian Ursu, Department of Computing, Goldsmiths College The lost update problem Transaction Atime Transaction B RETRIEVE (t)t1 t2 RETRIEVE (t) UPDATE (t) TO (t 1 )t3 t4 UPDATE (t) TO (t 2 )

16 Term 2, 2004, Lecture 6, TransactionsMarian Ursu, Department of Computing, Goldsmiths College The uncommitted dependency problem Transaction Atime Transaction B t1 UPDATE (t) RETRIEVE (t)t2 t3 ROLLBACK

17 Term 2, 2004, Lecture 6, TransactionsMarian Ursu, Department of Computing, Goldsmiths College The uncommitted dependency problem Transaction Atime Transaction B t1 UPDATE p UPDATE pt2 t3 ROLLBACK

18 Term 2, 2004, Lecture 6, TransactionsMarian Ursu, Department of Computing, Goldsmiths College The inconsistent analysis problem

19 Term 2, 2004, Lecture 6, TransactionsMarian Ursu, Department of Computing, Goldsmiths College Issue all these problems may lead to an inconsistent (incorrect) database is there a criterion based on which to decide weather a certain set of transaction, if executed concurrently, leads to an incorrect database or not?

20 Term 2, 2004, Lecture 6, TransactionsMarian Ursu, Department of Computing, Goldsmiths College Serialisability criterion for correctness for concurrent execution of transactions: the interleaved execution of a set of transactions is guaranteed to be correct if it is serialisable correct the DB is not in an inconsistent state serialisability: an interleaved execution has the same result as some serial execution

21 Term 2, 2004, Lecture 6, TransactionsMarian Ursu, Department of Computing, Goldsmiths College Serialisable schedule

22 Term 2, 2004, Lecture 6, TransactionsMarian Ursu, Department of Computing, Goldsmiths College Notes the schedules described in the concurrency problems examples were not serialisable neither A-then-B nor B-then-A two different interleaved transactions might produce different results, yet both can be considered correct

23 Term 2, 2004, Lecture 6, TransactionsMarian Ursu, Department of Computing, Goldsmiths College 3

24 Term 2, 2004, Lecture 6, TransactionsMarian Ursu, Department of Computing, Goldsmiths College Two-phase locking theorem if all transactions obey the two phase locking protocol then all possible interleaved schedules are serialisable i.e., they can be executed concurrently, because they will leave the database in a consistent state

25 Term 2, 2004, Lecture 6, TransactionsMarian Ursu, Department of Computing, Goldsmiths College Two-phase locking protocol 1.before operating on an object a transaction must acquire a lock on that object 2.after releasing a lock a transaction must not go on to acquire any more locks phase1 (growing): acquire locks (not simultaneously) phase2 (shrinking): release locks (no further acquisitions allowed) usually locks are released by the COMMIT or ROLLBACK operation in practice trade-off between release lock early and acquire more locks and the two phase locking protocol

26 Term 2, 2004, Lecture 6, TransactionsMarian Ursu, Department of Computing, Goldsmiths College Locking usually, applicable to tuples types X, exclusive - write S, shared - read rules compatibility matrix

27 Term 2, 2004, Lecture 6, TransactionsMarian Ursu, Department of Computing, Goldsmiths College Compatibility matrix

28 Term 2, 2004, Lecture 6, TransactionsMarian Ursu, Department of Computing, Goldsmiths College Data access protocol retrieve tuple acquire S lock (on that tuple) update tuple acquire X lock (on that tuple), or promote the S lock it holds (if it holds one) implicit request if request for lock is denied transaction goes in wait state until the lock is released livelock - first come first served X locks are held until end of transaction (COMMIT or ROLLBACK) (two phase locking protocol)

29 Term 2, 2004, Lecture 6, TransactionsMarian Ursu, Department of Computing, Goldsmiths College The uncommitted dependency problem: OK Transaction AtimeTransaction B t1UPDATE (t) (X lock on t) RETRIEVE (t)t2 (request X lock on t) waitt3COMMIT / ROLL.. wait(release X lock on t) resume RETRIEVE (t)t4 (acquire S lock on t)

30 Term 2, 2004, Lecture 6, TransactionsMarian Ursu, Department of Computing, Goldsmiths College The lost update problem : dead-lock Transaction A time Transaction B RETRIEVE p t1 (acquire S lock on p) t2 RETRIEVE p (acquire S lock on p) UPDATE p t3 (request X lock on p denied) t4 UPDATE p wait (request X lock on p wait denied) wait wait

31 Term 2, 2004, Lecture 6, TransactionsMarian Ursu, Department of Computing, Goldsmiths College Locking solves the three basic problems of concurrency theorem if all the transactions of a set S of transactions comply with the two phase locking protocol, then all their possible interleaved executions (schedules) are serialisable however, not all schedules produce the same result –think of examples introduces another problem: deadlock

32 Term 2, 2004, Lecture 6, TransactionsMarian Ursu, Department of Computing, Goldsmiths College Deadlock two or more transaction are waiting for the other to release a lock in practice: usually two transactions detect a deadlock cycle in the wait-for graph, or timing mechanism break a deadlock rollback a victim transaction what happens to the victim?

33 Term 2, 2004, Lecture 6, TransactionsMarian Ursu, Department of Computing, Goldsmiths College Further topics two phase locking protocol - not feasible in practice (not efficient) levels of isolation degree of interference intent locking locking granularity SQL support no explicit locking facilities it supports different isolation levels (with locking behind the scenes)

34 Term 2, 2004, Lecture 6, TransactionsMarian Ursu, Department of Computing, Goldsmiths College –

35 Term 2, 2004, Lecture 6, TransactionsMarian Ursu, Department of Computing, Goldsmiths College Conclusions transactions concurrency concurrency problems locking