Transactions and concurrency control

Slides:



Advertisements
Similar presentations
CM20145 Concurrency Control
Advertisements

Lecture plan Transaction processing Concurrency control
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.
TRANSACTION PROCESSING SYSTEM ROHIT KHOKHER. TRANSACTION RECOVERY TRANSACTION RECOVERY TRANSACTION STATES SERIALIZABILITY CONFLICT SERIALIZABILITY VIEW.
Concurrency Control II
Concurrency Control Amol Deshpande CMSC424. Approach, Assumptions etc.. Approach  Guarantee conflict-serializability by allowing certain types of concurrency.
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.
CMPT 401 Summer 2007 Dr. Alexandra Fedorova Lecture X: Transactions.
Exercises for Chapter 17: Distributed Transactions
1 TRANSACTION & CONCURRENCY CONTROL Huỳnh Văn Quốc Phương Thái Thị Thu Thủy
Transactions and concurrency control
CMPT Dr. Alexandra Fedorova Lecture X: Transactions.
Distributed Systems 2006 Styles of Client/Server Computing.
Distributed Systems Fall 2010 Transactions and concurrency control.
Transaction Management and Concurrency Control
14/06/2015Distribuerede Systemer1 Concurrency Control Thomas Hildebrandt.
CS 582 / CMPE 481 Distributed Systems Concurrency Control.
Transaction Management and Concurrency Control
Transaction Management and Concurrency Control
Persistent State Service 1 Distributed Object Transactions  Transaction principles  Concurrency control  The two-phase commit protocol  Services for.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
Transaction Management
Concurrency Control John Ortiz.
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.
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.
Distributed Deadlocks and Transaction Recovery.
Exercises for Chapter 16: Transactions and Concurrency Control
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 10 Transaction Management.
Transaction Communications Yi Sun. Outline Transaction ACID Property Distributed transaction Two phase commit protocol Nested transaction.
Chapterb19 Transaction Management Transaction: An action, or series of actions, carried out by a single user or application program, which reads or updates.
Distributed Transactions
Databases Illuminated
Chapter 11 Concurrency Control. Lock-Based Protocols  A lock is a mechanism to control concurrent access to a data item  Data items can be locked in.
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.
TRANSACTION MANAGEMENT R.SARAVANAKUAMR. S.NAVEEN..
Transactions and Concurrency Control Distribuerade Informationssystem, 1DT060, HT 2013 Adapted from, Copyright, Frederik Hermans.
II.I Selected Database Issues: 2 - Transaction ManagementSlide 1/20 1 II. Selected Database Issues Part 2: Transaction Management Lecture 4 Lecturer: Chris.
Distributed Transactions Chapter – Vidya Satyanarayanan.
Distributed Processing Systems ( Concurrency Control ) 오 상 규 서강대학교 정보통신 대학원
Transactions and Concurrency Control. Concurrent Accesses to an Object Multiple threads Atomic operations Thread communication Fairness.
Page 1 Concurrency Control Paul Krzyzanowski Distributed Systems Except as otherwise noted, the content of this presentation.
CSC 240 (Blum)1 Database Transactions. CSC 240 (Blum)2 Transaction  A transaction is an interaction between a user (or application) and a database. A.
Transaction Management Overview. Transactions Concurrent execution of user programs is essential for good DBMS performance. – Because disk accesses are.
IM NTU Distributed Information Systems 2004 Distributed Transactions -- 1 Distributed Transactions Yih-Kuen Tsay Dept. of Information Management National.
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.
NOEA/IT - FEN: Databases/Transactions1 Transactions ACID Concurrency Control.
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.
3 Database Systems: Design, Implementation, and Management CHAPTER 9 Transaction Management and Concurrency Control.
Distributed Transactions What is a transaction? (A sequence of server operations that must be carried out atomically ) ACID properties - what are these.
Chapter 13 Managing Transactions and Concurrency Database Principles: Fundamentals of Design, Implementation, and Management Tenth Edition.
Transaction Management
Concurrency Control Techniques
Transaction Management and Concurrency Control
Concurrency Control.
Part- A Transaction Management
Chapter 10 Transaction Management and Concurrency Control
Chapter 15 : Concurrency Control
Introduction of Week 13 Return assignment 11-1 and 3-1-5
Distributed Transactions
Transaction management
Exercises for Chapter 14: Distributed Transactions
Transaction Management
UNIVERSITAS GUNADARMA
Presentation transcript:

Transactions and concurrency control This power point presentation has been adapted from: http://www.cdk5.net/wp/preface http://www.it.uu.se/edu/course/hom epage/datsyst2/p2ht06/lecture5.pdf

Contents Introduction Transactions Concurrency Control Nested transactions Locks Concurrency Control Optimistic concurrency control Timestamp ordering Comparison of methods for concurrency control

Contents Introduction Transactions Concurrency Control Nested transactions Locks Concurrency Control Optimistic concurrency control Timestamp ordering Comparison of methods for concurrency control

Introduction The goal of transactions To ensure all objects managed by a server remain in a consistent state when they are accessed by multiple transactions in the presence of server crashed Transactions deal with crash failures of processes omission failures in communication A transaction is specified by a client as a set of operations on objects to be performed as an indivisible unit by the servers managing those objects

Introduction Recoverable Objects Objects that can be recovered after their server crashes. How servers make objects recoverable? Objects may be stored in volatile memory (for example, RAM) or persistent memory (for example, a hard disk) When objects are stored in volatile memory, the server may use persistent memory to store sufficient information for the state of the objects to be recovered if the server process crashes

Introduction Failure model for transactions Lampson [1981] proposed a fault model for distributed transactions that accounts for failures of disks. The model states the following: Writes to permanent storage may fail, either by writing nothing or by writing a wrong value Servers may crash occasionally. Crashes can occur at any time; in particular, they may occur during recovery. There may be an arbitrary delay before a message arrives. A message may be lost, duplicated or corrupted. The model was used to design a stable system whose components can survive any single fault

Contents Introduction Transactions Concurrency Control Nested transactions Locks Concurrency Control Optimistic concurrency control Timestamp ordering Comparison of methods for concurrency control

Transactions Example of Transactions An example of a simple client transaction specifying a series of related actions involving the bank accounts A, B and C. The first two actions transfer $100 from A to B and the second two transfer $200 from C to B. A client achieves a transfer operation by doing a withdrawal followed by a deposit.

Transactions Introduction Transactions originate from database management systems an execution of a program that accesses a database. From the client’s point of view a transaction is a sequence of operations that forms a single step, transforming the server data from one consistent state to another. Transactions can be provided as a part of middleware: CORBA - Object Transaction Service

Transactions Property of Transactions Atomicity: Isolation Consistency All or nothing- transaction either completes successfully, or has no effect at all Isolation Each transaction must be performed without interference from other transactions Consistency a transaction takes the system from one consistent state to another consistent state Durability After a transaction has completed successfully, all its effects are saved in permanent storage

Transactions Coordinator interface For recoverable objects, transaction is created and managed by a coordinator It implements the Coordinator interface as follows:

Transactions Concurrent Transactions Some well-known problems of concurrent transactions: The lost update problem Inconsistent retrievals

Transactions Transactions Life Histories

Transactions The Lost Update Problem Occurs when two transactions read the old value of a variable and then use it to calculate the new value.

Transactions Inconsistent Retrievals Occurs when a retrieval transaction runs concurrently with an update transaction

Transactions Solutions- Serial Equivalence Serial equivalence An interleaving of the transactions in which the combined effect is the same as if the transactions had been performed one at a time in some order prevents the occurrence of lost updates and inconsistent retrievals

Transactions Serial Equivalence Serial equivalence to solve the lost update problem

Transactions Serial Equivalence Serial equivalence to solve the inconsistent retrievals problem

Transactions Conflicting Operations All pairs of conflicting operations of two transactions should be executed in the same order to ensure serializability. Two operations conflict if their combined effect depends on the order in which they are executed.

Transactions Recoverability From Aborts Servers must record all the effects of committed transactions and none of the effects of aborted transactions Problems in relation to aborting transactions: Dirty reads Premature writes

Transactions Dirty Reads Caused by the interaction between a read operation in one transaction and an earlier write operation in another transaction on the same object

Transactions Premature Writes Premature writes is a problem related to the interaction between write operations on the same object belonging to different transactions. The executions of transactions are called strict if the service delays both read and write operations on an object until all transactions that previously wrote that object have either committed or aborted.

Transactions Nested Transactions Extend the transaction model by allowing transactions to be composed of other transactions several transactions may be started from within a transaction, allowing transactions to be regarded as modules that can be composed as required.

Transactions Nested Transactions Advantages: Subtransactions at one level (and their descendants) may run concurrently with other subtransactions at the same level in the hierarchy Subtransactions can commit or abort independently

Transactions Locks Basic idea: A transaction must be scheduled so that their effect on shared data is serially equivalent. A server can achieve serial equivalence of transactions by serializing access to the objects. Simple example Only one object can read or write at a time.

Transactions Locks Exclusive Locks

Transactions Locks Lock Compatibility Lock is implemented to avoid the inconsistent retrievals and lost updates caused by conflicts between read operations in one transaction and write operations in another as

Transactions Locks Strict Two Phase Locking Transaction is not allowed to have any new locks after it has released a lock. Two phases growing phase all locks are acquired shrinking phase locks are given back

Transactions Locks Lock implementation Lock is implemented by a lock manager a separate object in the server that holds a set of locks, e.g.in a hash table Each lock is an instance of the class Lock and is associated with a particular object Each instance of Lock maintains the following information in its instance variables: the identifier of the locked object the transaction identifiers of the transactions that currently hold the lock (shared locks can have several holders) a lock type

Transactions Locks Deadlocks a state in which each member of a group of transactions is waiting for some other member to release a lock two transactions are waiting, and each is dependent on the other to release a lock so it can resume

Transactions Locks Deadlocks

Transactions Locks Deadlocks: A wait-for graph can be used to represent the waiting relationships between current transactions

Transactions Locks Deadlocks:

Transactions Locks Deadlock prevention: lock all of the objects used by a transaction when it starts

Transactions Locks Deadlock detection: may be detected by finding cycles in the wait-for graph. a transaction must be selected for abortion to break the cycle

Transaction Locks Lock timeouts A method for resolution of deadlocks Each lock is given a limited period in which it is invulnerable. After this time, a lock becomes vulnerable If there is no other transaction is competing for the object that is locked, an object with a vulnerable lock remains locked. If any other transaction is waiting to access the object protected by a vulnerable lock, the lock is broken (that is, the object is unlocked) and the waiting transaction resumes. The transaction whose lock has been broken is normally aborted.

Transaction Locks Lock timeouts

Contents Introduction Transactions Concurrency Control Nested transactions Locks Concurrency Control Optimistic concurrency control Timestamp ordering Comparison of methods for concurrency control

Concurrency control Optimistic Concurrency Control Locking is not efficient. The drawbacks of locking: Lock maintenance represents an overhead The use of locks can result in deadlock Reduce the potential for concurrency as locks cannot be released until the end of the transaction The alternative approach to locking is optimistic concurrency control proposed by Kung and Robinson based on the observation in most applications, the likelihood of two clients’ transactions accessing the same object is low

Concurrency control The key idea The operation involved 3 phases: Optimistic Concurrency Control The key idea Transactions are allowed to proceed until the client completes its task and issues a closeTransaction request. When a conflict arises, some transaction will be aborted and will need to be restarted by the client. The operation involved 3 phases: Working phase Validation phase Update phase

Concurrency control Working phase Optimistic Concurrency Control Working phase each transaction has a tentative version of each of the objects that it updates allows the transaction to abort (with no effect on the objects), either during the working phase or if it fails validation due to other conflicting transactions Several different tentative values of the same object may coexist when there are several concurrent transactions Two records are kept for the objects a read set (objects read by the transaction) a write set (objects written by the transaction)

Concurrency control Validation phase Optimistic Concurrency Control The transaction is validated when the closeTransaction request is received to identify conflict with other operations on the same objects. If the validation is successful, then the transaction can commit. If the validation fails, then some form of conflict resolution must be used (e.g. transaction is aborted)

Concurrency control Update phase Optimistic Concurrency Control Update phase If a transaction is validated, all of the changes recorded in its tentative versions are made permanent. Read-only transactions can commit immediately after passing validation. Write transactions are ready to commit once the tentative versions of the objects have been recorded in permanent storage.

Concurrency control Validation of transactions: Optimistic Concurrency Control Validation of transactions: Validation uses the read-write conflict rules to ensure that the scheduling of a particular transaction is serially equivalent Each transaction is assigned a transaction number when it enters the validation phase (when the client issues a closeTransaction) If the transaction is validated and completes successfully, it retains this number if it fails and is aborted, or if the transaction is read only, the number is released for reassignment

Concurrency control Validation of transactions: Optimistic Concurrency Control Validation of transactions: A transaction with the number Ti always precedes a transaction with the number Tj if i < j. Rules to achieve serial equivalent for transaction Tv and Ti:

Concurrency control Validation of transactions: Optimistic Concurrency Control Validation of transactions: TWO (2) forms of validation Backward checks the transaction undergoing validation with other preceding overlapping transactions – those that entered the validation phase before it. Forward checks the transaction undergoing validation with other later transactions, which are still active.

Concurrency control Backward validation: Optimistic Concurrency Control Backward validation:

Concurrency control Optimistic Concurrency Control Forward Validation:

Concurrency control Comparison of forward and backward validation Optimistic Concurrency Control Comparison of forward and backward validation Forward Backward Flexible in the resolution of conflicts Abort the transaction being validated Checks a small write set against the read sets of active transactions Compares a large read set against the old write sets Allow for new transactions to start during the validation process Has the overhead of storing old write sets until they are no longer needed

Concurrency control Starvation Optimistic Concurrency Control The prevention of a transaction ever being able to commit When a transaction is aborted, it will normally be restarted by the client program. But there is no guarantee that a particular transaction will ever pass the validation checks It may come into conflict with other transactions each time it is restarted. Occurrences of starvation are likely to be rare

Concurrency control Timestamp Ordering Each operation in a transaction is validated when it is carried out. If the operation cannot be validated the transaction is aborted immediately and then can be restarted by the client. Each transaction is assigned a unique timestamp value when it starts; The timestamp defines its position in the time sequence of transactions. Request from transactions can be ordered according to their timestamps.

Concurrency control Timestamp Ordering A simple time ordering rules; A transaction's request to write an object is valid only if that object was last read and written by earlier transactions. A transaction's request to read an object is valid only if that object was last written by an earlier transactions.

Concurrency control Timestamp Ordering Operations conflict for timestamp ordering

Concurrency control Timestamp Ordering Timestamp ordering write rule By combining rules 1 and 2 (the previous slide) the following rule for obtained It decide whether to accept a write operation requested by transaction Tc on object D

Concurrency control Timestamp Ordering Timestamp ordering write rule: The action of a write operation by transaction T3 in cases where T3 ≥ maximum read timestamp on the object

Concurrency control Timestamp Ordering Timestamp ordering write rule: Write operations and timestamp

Concurrency control Timestamp Ordering Timestamp ordering read rule: By using rule 3, the following rule is obtained It decides whether to accept immediately, to wait, or to reject a read operation requested by transaction Tc on object D.

Concurrency control Timestamp Ordering

Concurrency control Timestamp Ordering

Concurrency control Comparison of Methods for Concurrency Control Strict two-phase locking Optimistic methods Timestamp ordering Conflicts between transactions are detected as each object is accessed. Decides the serialization order dynamically – according to the order in which objects are accessed All transactions are allowed to proceed, but some are aborted when they attempt to commit, or in forward validation transactions are aborted earlier Decides the serialization order statically – when a transaction starts Used in file servers and common database systems Mostly used for document sharing over the Internets file servers and SDD-1 database system

Concurrency control Comparison of Methods for Concurrency Control Some examples of applications that used optimistic concurrency control: Dropbox Google Apps Wikipedia Dynamo

End of the Chapter…