SYNCHRONIZATION TECHNIQUES BASED ON TWO-PHASE LOCKING

Slides:



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

Database Systems (資料庫系統)
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.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Concurrency Control Chapter 17 Sections
Lock-Based Concurrency Control
Concurrency Control.
Lecture 11 Recoverability. 2 Serializability identifies schedules that maintain database consistency, assuming no transaction fails. Could also examine.
Database Systems, 8 th Edition Concurrency Control with Time Stamping Methods Assigns global unique time stamp to each transaction Produces explicit.
Exercises for Chapter 17: Distributed Transactions
Concurrency Control and Recovery In real life: users access the database concurrently, and systems crash. Concurrent access to the database also improves.
What we will cover…  Distributed Coordination 1-1.
©Silberschatz, Korth and Sudarshan16.1Database System Concepts 3 rd Edition Chapter 16: Concurrency Control Lock-Based Protocols Timestamp-Based Protocols.
Distributed DBMSPage © 1998 M. Tamer Özsu & Patrick Valduriez Outline Introduction Background Distributed DBMS Architecture Distributed Database.
Transaction Management and Concurrency Control
CS 582 / CMPE 481 Distributed Systems
Transaction Management and Concurrency Control
Manajemen Basis Data Pertemuan 10 Matakuliah: M0264/Manajemen Basis Data Tahun: 2008.
Transaction Management
ICS (072)Concurrency Control1 Transaction Processing and Concurrency Control Dr. Muhammad Shafique Chapter March 2008.
©Silberschatz, Korth and Sudarshan16.1Database System Concepts 3 rd Edition Chapter 16: Concurrency Control Lock-Based Protocols Timestamp-Based Protocols.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
CMPT Dr. Alexandra Fedorova Lecture XI: Distributed Transactions.
© 1997 UW CSE 11/13/97N-1 Concurrency Control Chapter 18.1, 18.2, 18.5, 18.7.
Deadlocks in Distributed Systems Deadlocks in distributed systems are similar to deadlocks in single processor systems, only worse. –They are harder to.
Concurrency Control.
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.
ICS (072)Concurrency Control Techniques1 Concurrency Control Techniques Chapter 18 Dr. Muhammad Shafique.
Concurrency Control Lectured by, Jesmin Akhter, Assistant professor, IIT, JU.
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.
Concurrency Control Techniques Chapter 18
Concurrency control. Lock-based protocols One way to ensure serializability is to require the data items be accessed in a mutually exclusive manner One.
Chapter 15 Concurrency Control Yonsei University 1 st Semester, 2015 Sanghyun Park.
Concurrency Control Concurrency Control By Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany) DIRECTOR ARUNAI ENGINEERING COLLEGE TIRUVANNAMALAI.
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.
Module Coordinator Tan Szu Tak School of Information and Communication Technology, Politeknik Brunei Semester
Chapter 18 Concurrency Control Techniques Copyright © 2004 Pearson Education, Inc.
1 Concurrency Control Chapter Conflict Serializable Schedules  Two schedules are conflict equivalent if:  Involve the same actions of the same.
II.I Selected Database Issues: 2 - Transaction ManagementSlide 1/20 1 II. Selected Database Issues Part 2: Transaction Management Lecture 4 Lecturer: Chris.
Distributed Transaction Management. Outline Introduction Concurrency Control Protocols  Locking  Timestamping Deadlock Handling Replication.
Chapter 20 Transaction Management Thomas Connolly, Carolyn Begg, Database System, A Practical Approach to Design Implementation and Management, 4 th Edition,
1 Concurrency Control Lecture 22 Ramakrishnan - Chapter 19.
Transaction Management Overview. Transactions Concurrent execution of user programs is essential for good DBMS performance. – Because disk accesses are.
Concurrency Control Introduction Lock-Based Protocols
1 Concurrency control lock-base protocols timestamp-based protocols validation-based protocols Ioan Despi.
1 Database Systems ( 資料庫系統 ) December 27, 2004 Chapter 17 By Hao-hua Chu ( 朱浩華 )
9 1 Chapter 9_B Concurrency Control Database Systems: Design, Implementation, and Management, Rob and Coronel.
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 Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
SHUJAZ IBRAHIM CHAYLASY GNOPHANXAY FIT, KMUTNB JANUARY 05, 2010 Distributed Database Systems | Dr.Nawaporn Wisitpongphan | KMUTNB Based on article by :
Chapter 13 Managing Transactions and Concurrency Database Principles: Fundamentals of Design, Implementation, and Management Tenth Edition.
Distributed Databases – Advanced Concepts Chapter 25 in Textbook.
Transaction Management
Concurrency Control Techniques
Concurrency Control.
Multiple Granularity Granularity is the size of data item  allowed to lock. Multiple Granularity is the hierarchically breaking up the database into portions.
Outline Announcements Fault Tolerance.
Chapter 10 Transaction Management and Concurrency Control
Chapter 15 : Concurrency Control
Distributed Database Management Systems
Introduction of Week 13 Return assignment 11-1 and 3-1-5
Exercises for Chapter 14: Distributed Transactions
Distributed Databases Recovery
CONCURRENCY Concurrency is the tendency for different tasks to happen at the same time in a system ( mostly interacting with each other ) .   Parallel.
Database Systems (資料庫系統)
Database Systems (資料庫系統)
Transactions, Properties of Transactions
Presentation transcript:

SYNCHRONIZATION TECHNIQUES BASED ON TWO-PHASE LOCKING Presented by Miss Napasakorn SukJay Miss Lumpapun Punchoojit

Agenda Background of Two-Phase locking Basic 2PL Implementation Primary Copy 2PL Voting 2PL Centralize 2 PL Deadlock Prevention and Detection Appendix 2

Background of Two-Phase locking Two-phase locking (2PL) synchronizes reads and writes by explicitly detecting and preventing conflicts between concurrent operations. Before reading data item x, a transaction must "own" a readlock on x. Before writing into x, it must "own" a writelock on x. The ownership of locks is governed by two rules: (1) different transactions cannot simultaneously own conflicting locks. (2) once a transaction surrenders ownership of a lock, it may never obtain additional locks.

Background of Two-Phase locking(cont.) The definition of conflicting lock depends on the type of synchronization being performed: - rw synchronization - ww synchronization There are 2 phase manner. - growing phase - shrinking phase

Basic 2PL Implementation The basic way to implement 2PL in a distributed database is to distribute the schedulers along with the database, placing the scheduler for data item x at the DM were x is stored. - readlocks may be implicitly requested by dm-reads - writelocks may be implicitly requested by prewrites. Writelocks are implicitly released by din-writes. This implementation "automatically" handles redundant data correctly.

Primary Copy 2PL Primary copy 2PL is a 2PL technique that pays attention to data redundancy. One copy of each logical data item is designated the primary copy. Before accessing any copy of the logical data item, the appropriate lock must be obtained on the primary copy. For readlocks this technique requires more communication than basic 2PL. For writelock, primary copy 2PL does not incur extra communication.

Voting 2PL Voting 2PL is derived from the majority consensus technique of Thomas and is only suitable for ww synchronization. Suppose transaction T wants to write into X. 1. TM sends prewrites to each DM holding a copy of X. 2. DM always responds immediately. 3.Counts the number of"lock~set" responses: 4. if the number constitutes a majority, then the TM behaves as if all locks were set. Otherwise, it waits for "lockset" operations from DMs that originally said "lock blocked." Deadlocks aside it will eventually receive enough "lockset" operations to proceed.

Centralized 2PL Instead of distributing the 2PL schedulers, one can centralize the scheduler at a single site. For Example to perform dm-read(x) where x is not stored at the central site, - The TM must first request a readlock on x from the central site. - Walt for the central site to acknowledge that the lock has been set. - then send dm-read(x) to the DM that holds x.

Deadlock Prevention and Detection The preceding implementations of 2PLforce transactions to wait for unavailable locks. If this waiting is uncontrolled, deadlocks can arise Deadlock situations can be characterized by waits-for graphs, directed graphs that indicate which transactions are waiting for which other transactions.

Deadlock Prevention Fig 6

Deadlock Prevention Deadlock prevention is a "cautious“ scheme in which a transaction is restarted when the system is "afraid" that deadlock might occur. Nonpreemptive: requesting transaction restart. Preemptive : transaction that currently owns the lock restart. assign priorities :A better approach to prevent deadlock Timestamps as priorities :each transaction be assigned a unique timestamp by its TM. Wait-Die is the nonpreemptive technique. Wound.Wait is the preemptive counterpart to Wait-Die. Preordering of resources. This technique requires predeclaration of locks. Data items are numbered and each transaction requests locks one at a time in numeric order.The priority of a transaction is the number of the highest numbered lock it owns.

Deadlock Detection Transactions wait for each other in an uncontrolled manner and are only aborted if a deadlock actually occurs.

Deadlock Detection(cont.) The centralized approach, one site is designated the deadlock detector for the distributed system. The hierarchical approach, the database sites are organized into a hierarchy , with a deadlock detector at each node of the hierarchy The periodic nature of theprocess introduces two problems. 1.A deadlock may exist for several minutes without being detected. 2.A transaction T may be restarted for reasons other than concurrency control.

Appendix 2 Thomas' Majority Consensus Algorithm One of the first published algorithms for distributed concurrency control Introduced several important synchronization techniques in that algorithm, including the Thomas Write Rule, majority voting, and certification The authors argued that the overall Thomas algorithm is not suitable for distributed databases.

Thomas' Majority Consensus Algorithm Thomas' algorithm assumes a fully redundant database, with every logical data item stored at every site. Each copy carries the timestamp of the last transaction that wrote into it.   Transactions execute in two phases.

First Phase In the first phase, each transaction executes locally at one site called the transaction's home site. The transaction is assigned a unique timestamp when it begins executing. During execution it keeps a record of the timestamp of each data item it reads and, when it executes a write on a data item, processes the write by recording the new value in an update list. This completes the first phase of execution.

Second Phase In the second phase the update list is sent to every site. Each site votes on the update list. A site votes yes on an update list if it can certify the transaction that produced it. After a site votes yes, the update list is said to be pending at that site.

Second Phase To cast the vote, the site sends a message to the transaction's home site, informs all sites of the outcome. If a majority voted yes, then all sites are required to commit the update. If a majority voted no, all sites are told to discard the update, and the transaction is restarted

Second Phase: Voting To vote on an update list U, a site compares the timestamp of each data item in the readset of U with the timestamp of that same data item in the site's local database. If any data item has a timestamp in the database different from that in U, the site votes no.   Otherwise, the site compares the readset and writeset of U with the readset and writeset of each pending update list at that site, and if there is no rw conflict between U and any of the pending update lists, it votes yes.

Second Phase: Voting If there is an rw conflict between U and one of those pending requests, the site votes pass (abstain) if U's timestamp is larger than that of all pending update lists with which it conflicts.   If there is an rw conflict but U's timestamp is smaller than that of the conflicting pending update list, then it sets U aside on a wait queue and tries again when the conflicting request has either been committed or aborted at that site.

Second Phase: Voting The second part of the voting rule, in which U is checked for rw conflicts against pending update lists conflicting requests are not certified concurrently. Suppose T1 reads X and Y, and writes Y, while T2 reads X and Y, and writes X. Suppose T1 and T2 execute at sites A and B, respectively, and X and Y have timestamps of 0 at both sites. Assume that T1 and T2 execute concurrently and produce update lists ready for voting at about the same time. Either T1 or T2 must be restarted, since neither read the other's output; if they were both committed, the result would be nonserializable.

Second Phase: Voting Thus it is not possible to certify conflicting transactions concurrently. This is yet another technical difficulty with the certification approach in a distributed environment

Correctness No simple proof of the serializability of Thomas' algorithm has ever been demonstrated.  

Partially Redundant Databases For the majority consensus algorithm to be useful in a distributed database environment, it must be generalized to operate correctly when the database is only partially redundant. Can be accomplished without either serious degradation of performance or a complete change in the set of techniques that are used?

Partially Redundant Databases Firstly, in a partially redundant database, each site would only be comparing the timestamps of the data items stored at that site. The majority consensus decision rule apparently must be dropped, since the voting algorithm depends on the fact that all sites perform exactly the same certification test. The significance of the majority vote would vanish.

Performance Even in the fully redundant case, the performance of the majority consensus algorithm is not very good. First, repeating the certification and conflict detection at each site is more than is needed to obtain serializability a centralized certifier would work just as well and would only require that certification be performed at one site.   Second, the algorithm is quite prone to restarts when there are run-time conflicts, since restarts are the only tactic available for synchronizing transactions. Finally, centralized 2PL outperforms the majority consensus algorithm.

Reliability Despite the performance problems of the majority consensus algorithm, the reliability of the algorithm is well-justified, as long as a majority of sites are correctly running. However, from current knowledge, this justification is not compelling for several reasons.

Reliability First, although there is no cost when a site fails, substantial effort may be required when a site recovers. A centralized algorithm using backup sites, lacks the symmetry of Thomas' algorithm, but may be more efficient due to the simplicity of site recovery.   In addition, the majority consensus algorithm does not consider the problem of atomic commitment and it is unclear how one would integrate two-phase commit into the algorithm.

Reliability Overall, the reliability threats that are handled by the majority consensus algorithm have not been explicitly listed, and alternative solutions have not been analyzed. While voting is certainly a possible technique for obtaining a measure of reliability, the circumstances under which it is cost-effective are unknown.

THANK YOU