Transaction Models of DDBMS Zsolt Németh Topics covered: –Transactions –Characterization of transactions –Formalization of transactions –Serializability.

Slides:



Advertisements
Similar presentations
Distributed DBMS© M. T. Özsu & P. Valduriez Ch.10/1 Outline Introduction Background Distributed Database Design Database Integration Semantic Data Control.
Advertisements

More About Transaction Management Chapter 10. Contents Transactions that Read Uncommitted Data View Serializability Resolving Deadlocks Distributed Databases.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 16.
Introduction to Database Systems1 Concurrency Control CC.Lecture 1.
1 Integrity Ioan Despi Transactions: transaction concept, transaction state implementation of atomicity and durability concurrent executions serializability,
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.
CSC271 Database Systems Lecture # 32.
Transactions (Chapter ). What is it? Transaction - a logical unit of database processing Motivation - want consistent change of state in data Transactions.
(c) Oded Shmueli Transactions Lecture 1: Introduction (Chapter 1, BHG) Modeling DB Systems.
Lecture 11 Recoverability. 2 Serializability identifies schedules that maintain database consistency, assuming no transaction fails. Could also examine.
Transaction Processing Lecture ACID 2 phase commit.
Concurrency Control and Recovery In real life: users access the database concurrently, and systems crash. Concurrent access to the database also improves.
Distributed DBMSPage © 1998 M. Tamer Özsu & Patrick Valduriez Outline Introduction Background Distributed DBMS Architecture Distributed Database.
Distributed DBMSPage © 1998 M. Tamer Özsu & Patrick Valduriez Outline Introduction Background Distributed DBMS Architecture Distributed Database.
10 1 Chapter 10 Transaction Management and Concurrency Control Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
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.
What is a Transaction? Logical unit of work
Chapter 8 : Transaction Management. u Function and importance of transactions. u Properties of transactions. u Concurrency Control – Meaning of serializability.
Transaction Management
1 Transaction Management Database recovery Concurrency control.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
Transaction Management WXES 2103 Database. Content What is transaction Transaction properties Transaction management with SQL Transaction log DBMS Transaction.
Distributed DBMSPage © 1998 M. Tamer Özsu & Patrick Valduriez Outline Introduction Background Distributed DBMS Architecture Distributed Database.
Transaction Management and Concurrency Control
TRANSACTIONS AND CONCURRENCY CONTROL Sadhna Kumari.
Multi-user Database Processing Architectures Architectures Transactions Transactions Security Security Administration Administration.
Transaction Processing Concepts
Transactions Sylvia Huang CS 157B. Transaction A transaction is a unit of program execution that accesses and possibly updates various data items. A transaction.
Distributed DBMSSlide 1Lectured by, Jesmin Akhter, Assistant Professor, IIT, JU PMIT-6102 Advanced Database Systems By- Jesmin Akhter Assistant Professor,
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 10 Transaction Management.
Introduction to Transaction Management
Transaction Communications Yi Sun. Outline Transaction ACID Property Distributed transaction Two phase commit protocol Nested transaction.
DB Transactions CS143 Notes TRANSACTION: A sequence of SQL statements that are executed "together" as one unit:
Database Management Systems, 2 nd Edition. R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Lecture 21 Ramakrishnan - Chapter 18.
PMIT-6102 Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University.
Distributed DBMSPage © 1998 M. Tamer Özsu & Patrick Valduriez Outline Introduction Background Distributed DBMS Architecture Distributed Database.
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.
1 IT420: Database Management and Organization Session Control Managing Multi-user Databases 24 March 2006 Adina Crăiniceanu
Concurrency Control in Database Operating Systems.
PMIT-6102 Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 136 Database Systems I SQL Modifications and Transactions.
Databases Illuminated
Transactions. What is it? Transaction - a logical unit of database processing Motivation - want consistent change of state in data Transactions developed.
II.I Selected Database Issues: 2 - Transaction ManagementSlide 1/20 1 II. Selected Database Issues Part 2: Transaction Management Lecture 4 Lecturer: Chris.
Transactions and Concurrency Control. Concurrent Accesses to an Object Multiple threads Atomic operations Thread communication Fairness.
Jennifer Widom Transactions Properties. Jennifer Widom Transactions Solution for both concurrency and failures A transaction is a sequence of one or more.
Transaction Management Transparencies. ©Pearson Education 2009 Chapter 14 - Objectives Function and importance of transactions. Properties of transactions.
Multidatabase Transaction Management COP5711. Multidatabase Transaction Management Outline Review - Transaction Processing Multidatabase Transaction Management.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
10 Transaction Management and Concurrency Control MIS 304 Winter 2005.
18 September 2008CIS 340 # 1 Last Covered (almost)(almost) Variety of middleware mechanisms Gain? Enable n-tier architectures while not necessarily using.
H.Lu/HKUST L06: Concurrency Control & Locking. L06: Concurrency Control & Locking - 2 H.Lu/HKUST Transactions  Concurrent execution of user programs.
Chapter 13 Managing Transactions and Concurrency Database Principles: Fundamentals of Design, Implementation, and Management Tenth Edition.
1 Concurrency Control. 2 Why Have Concurrent Processes? v Better transaction throughput, response time v Done via better utilization of resources: –While.
Transaction Management and Concurrency Control
Transaction Properties
Chapter 10 Transaction Management and Concurrency Control
Outline Introduction Background Distributed DBMS Architecture
Introduction of Week 13 Return assignment 11-1 and 3-1-5
Transaction management
Distributed Database Management Systems
Distributed Database Management Systems
UNIT -IV Transaction.
Presentation transcript:

Transaction Models of DDBMS Zsolt Németh Topics covered: –Transactions –Characterization of transactions –Formalization of transactions –Serializability theory –Concurrency control models –Locks

Transactions The concept of transaction is a unit of consistent and reliable computation Transaction management: keeping the DB in consistent state even when concurrent accesses and failures occur Begin transactionEnd transactionExecution of transaction Database in a consistent state Database may be temporarily in an inconsistent state

Definition of a transaction A transaction makes transformations of system states preserving consistency A transaction is a sequence of read and write operations together with computation steps, assuming that –the transaction may be executed concurrently with others: concurrency transparency must be provided –failures may occur during execution: failure transparency must be provided

Example of a transaction Example DB: FLIGHT(FNO, DATE, SRC, DEST, STSOLD, CAP) CUST(CNAME, ADDR, BAL) FC(FNO, DATE, CNAME, SPECIAL) Transaction BEGIN_TRANSACTION RESERVATION BEGIN INPUT(flight_no, date, customer_name); EXEC SQL UPDATE FLIGHT SET STSOLD = STSOLD + 1 WHERE FNO = flight_no AND DATE = date; EXEC SQL INSERT INTO FC(FNO, DATE, CNAME, SPECIAL) VALUES(flight_no, date, customer_name, null); END

Properties of transactions A tomicity –all or nothing C onsistency –maps one consistent DB state to another –the ´correctness´of a transaction I solation –each transaction sees a consistent DB D urability –the results of a transaction must survive system failures Remember ACIDity

Atomicity Treated as a unit of operation Either all the actions of a transaction are completed or none of them –upon failure the DBMS can decide whether to terminate by completing the pending actions or terminate by undoing the actions that have been executed Maintainig atomicity requires recovery from failures –transaction failures: data errors, deadlocks, etc.  Transaction recovery –system failures: media, processor failures, communication breakages, etc.  Crash recovery

Classification of consistency (by Gray et al.) Dirty data: data values that have been written by a transaction prior to its commitment Degree 0 (Transaction T sees degree 0 consistency if) –T does not overwrite dirty data of other transactions Degree 1: Degree 0 plus –T does not commit any writes before end of transaction Degree 2: Degree 1 plus –T does not read dirty data from other transactions Degree 3: Degree 2 plus –Other transactions do not dirty any data read by T before T completes

Isolation (example) Possible execution schemes of T1 and T2T1: Read(x)T1: x = x + 1 T1: Write(x)T2: Read(x) T1: CommitT1: Write(x) T2: Read(x)T1: CommitT2: x = x + 1T2: Write(x)T2: Commit Lost update: incomplete results can be seen by other transactions Cascading aborts: if T1 decides to abort, all transactions that have seen T1´s incomplete results must be aborted Reads 50 when x is 51

Isolation An executing transaction cannot reveal it results to other concurrent transactions before its commitment Isolation is related to serializability: if several transactions are executed concurrently, the results must be the same as if they were executed serially in some order There is a strong relationship between isolation and degrees of consistency: –degree 0: low level of isolation, yet solves the problem of lost updates –degree 2: solves both lost updates and cascading aborts –degree 3: full isolation

Durability Once a transaction commits, its results are permanent and cannot be erased even if system failure occurs Database recovery

Termination of transactions A transaction always terminates –if the task is successful: commits –if the task is incomplete (for some reasons): aborts either due to system failure or unsatisfied conditions rollback: undone the actions and return the DB to its state before execution Commit –the point of no return –if a transaction is committed its results are permanently stored in the DB  durability its results can be made visible to other transactions  consistency, isolation

Example of termination BEGIN_TRANSACTION RESERVATION BEGIN INPUT(flight_no, date, customer_name) EXEC SQL SELECT STSOLD, CAP INTO temp1, temp2 FROM FLIGHT WHERE FNO = flight_no AND DATE = date; IF temp1 = temp2 THEN BEGIN OUTPUT(„no free seats“); ABORT END ELSE BEGIN EXEC SQL UPDATE FLIGHT SET STSOLD = STSOLD + 1 WHERE FNO = flight_no AND DATE = date; EXEC SQL INSERT INTO FC(FNO, DATE, CNAME, SPECIAL) VALUES(flight_no, date, customer_name, null); COMMIT; OUTPUT(„reservation completed“); END

Formalization of the transaction concept Characterization –Data items that a given transaction reads: Read Set (RS) writes: Write Set (WS) they are not necessarily mutually exclusive Base Set (BS): BS = RS  WS Insertion and deletion are omitted, the discussion is restricted to static databases

Formalization of the transaction concept O ij (x): some atomic operation O j of transaction T i that operates on DB entity x O j  {read, write} OS i =  j O ij, i.e. all operations in T i N i  {abort, commit}, the termination condition for T i Transaction T i is a partial ordering over its operations and the termination condition

Formalization of the transaction concept Partial order P = { ,  } where –  is the domain –  is an irreflexive and transitive relation Transition T i is a partial order {  i,  i } where –  i = OS i  N i –For any two operations O ij, O ik  OS i, if O ij =R(x) and O ik =W(x) for any data item x then either O ij  i O ik or O ik  i O ij, i.e. ´there must be an order between conflicting operations´ –  O ij  OS i, O ij  i N i, i.e. áll operations must precede the termination´ The ordering relation  i is application dependent

Formalization of the transaction concept Example Read(x) Read(y) x = x + y Write(x) Commit –  = {R(x), R(y), W(x), C} –  = {(R(x), W(x)), (R(y), W(x)), (W(x), C), (R(x), C), (R(y), C)} where (O i, O j ) means O i  O j Partial order: the ordering is not specified for every pair of operations R(x) R(y) W(x)C

Characterization of transactions According to application type –regular or distributed –compensating –heterogeneous According to duration –on-line (short life) or batch (long life) According to structure –flat, nested or workflow According to the order of read and write operations –general –two-step: all read ops before any write ops –restricted: a data item must be read before written –restricted two-step –action: restricted where each read-write pair is atomic

Structural types of transactions Flat –a sequence of primitive operations between begin and end markers Nested –a transaction may include other transactions with their own commit points more concurrency introduced recovery is possible independently for each subtransaction –a subtransaction can be a nested one too –nesting open –subtransactions begin after their parents and finish before them –commitment is conditional upon the commitment of the parent closed –subtransactions can execute and commit independently –compensation may be necessary

Architecture revisited User Interface Handler Semantic Data Controller Global Query Optimizer Global Execution Monitor External Schema Global Conceptual Schema GD/D User processor User Scheduler (SC) Transaction Manager (TM) Global Execution Monitor (Distributed Execution Monitor) Begin_transaction, Read, Write, Commit, Abort Results To data processors With other TMs With other SCs With other data processors

Serializability theory Schedule (history) S: specifies an interleaved execution order over a set of transactions T={T 1, T 2,... T n } Complete schedule S T c : is a partial order S T c ={  T,  T } over a set of transactions T={T 1, T 2,... T n } that defines the execution order of all operations in its domain – – for any two conflicting operations O ij, O kl   T, either O ij  T O kl or O kl  T O ij

Serializability theory Schedule (example): a possible complete schedule –T1:T2:Read(x)x = x + 1Write(x)Commit –  1 = {R 1 (x), W 1 (x), C 1 },  2 = {R 2 (x), W 2 (x), C 2 } –  T =  1   2 = {R 1 (x), W 1 (x), C 1, R 2 (x), W 2 (x), C 2 } –  T = {(R 1, R 2 ), (R 1, W 1 ), (R 1, C 1 ), (R 1, W 2 ), (R 1, C 2 ), (R 2, W 1 ), (R 2, C 1 ), (R 2, W 2 ), (R 2, C 2 ), (W 1, C 1 ), (W 1, W 2 ), (W 1, C 2 ), (C 1, W 2 ), (C 1, C 2 ), (W 2, C 2 )} R1R1 R2R2 W1W1 W2W2 C1C1 C2C2

Serializability theory Prefix: P´ = {  ´,  ´} is a prefix of partial order P = { ,  } if –  ´   –  e i   ´, e 1  ´e 2 iff e 1  e 2 –  e i   ´, if  e j   and e j  e i, then e j   ´ Only the conflicting operations are relevant at scheduling - redefine schedule: Schedule (incomplete) S: is a prefix of complete schedule S T c

Serializability theory Incomplete schedule (example) –T1:T2:T3: Read(x)Write(x)Read(x) Write(x)Write(y)Read(y) CommitRead(z)Read(z)Commit Complete schedulePartial schedule –the partial schedule is a prefix of complete schedule and equivalent to it R1(x) W2(x)R3(x) W1(x) W2(y)R3(y) C1R2(z)R3(z) C2C3 R1(x) W2(x)R3(x) W2(y)R3(y) R2(z)R3(z)

Serializability theory Serial schedule (serial history): if in a schedule S the operations of various transactions are not interleaved, the schedule is serial –S = {W 2 (x), W 2 (y), R 2 (z), C 2, W 1 (x), R 1 (x), C 1, R 3 (x), R 3 (y), R 3 (z), C 3 } –T 2  S T 1  S T 3 Two schedules S 1 and S 2 are equivalent if for each pair of conflicting operations O ij, O kl (i  k) whenever O ij  1 O kl then O ij  2 O kl. (conflict equivalence) Schedule S is serializable if it is conflict equivalent to a serial schedule (conflict-based serializability)

Serializability theory Transactions execute concurrently but the overall effect of the resulted history upon the database is equivalent to some serial scheduling Primary goal of concurrency control: generate a serializable schedule for the pending transactions Two histories must be taken into account: –local schedule (at each site) –global schedule

Serializability theory When the DB is partitioned, if each local schedule is serializable then the global schedule is serializable When the DB is replicated, the global schedule is serializable (one-copy serializable) if –local schedules are serializable –two conflicting operations are in the same relative order in each local schedule where they appear

Replica control protocol Consistency in presence of replication: one-copy serializability must be provided –concurrency control plus –replica control Assume data item x (logical data) is replicated as x 1, x 2,... x n (physical data items) –each read(x) is mapped to one of the physical items –each write(x) is mapped to a subset of the physical data copies If read(x) is mapped to one and write(x) is mapped to all physical copies, it is a read-once/write-all (ROWA) protocol

Concurrency control models Pessimistic –2-Phase Locking based (2PL) Centralized Primary copy Distributed –Timestamp Ordering (TO) Basic Multiversion Conservative –Hybrid Optimistic –Locking –Timestamp ordering

Locks Locks ensure that data shared by conflicting operations are accessed by one operation at a time - a simple way of serialization The lock is –set by a transaction before the lock unit is accessed –reset at the end of the operation –if the lock is set already, the lock unit cannot be accessed Lock modes –read lock (shared lock) –write lock (exclusive lock) Locks are controlled by the Lock Manager (LM) which is a part of the Scheduler (see architecture revisited)

Locks Two-phase locking (2PL): no transaction should request a lock after it releases one of its locks Transactions have –growing phase –lock point –shrinking phase Theorem: any schedule that obeys 2PL rule is serializable (Eswaran et al.) Difficult to implement Transaction Manager (among others due to cascading aborts) Lock point BeginEnd Obtain lock Release lock

Locks Strict two-phase locking (S2PL): locks are released if the operation is a commit or an abort BeginEnd Obtain lock Release locks Data in use

Locks in distributed DBSs: Centralized 2PL There is only one 2PL scheduler (lock manager) in the distributed system All lock requests are addressed to it Important: TM must implement the replica control protocol Data processorsCoordinating TMCentralized LM 1 Lock request 2 Lock Granted 3 Operation 4 End of Operation 5 Release Lock

Locks in distributed DBSs: Primary copy 2PL The centralized 2PL scheduler may form a bottleneck In PC2PL lock managers are implemented at a number of sites –they are responsible for a given set of lock units –TMs send lock and unlock requests to the scheduler that is responsible for the given lock unit –one copy of the data item is treated as a primary copy –the location of the primary copy must be determined prior to sending lock and unlock requests - a directory design issue

Locks in distributed DBSs: Distributed 2PL LMs are available at each site in D2PL –if the DB is not replicated, it is the same as PC2PL –if replicated, it implements the ROWA protocol –operations are passed via LMs - there is no lock granted message Participating DPsCoordinating TMParticipating LMs 1 Lock request 2 Operation 3 End of Operation 4 Release Lock